[diffoscope] 03/04: presenters: Add a Presenter.start method to simplify logic.

Chris Lamb chris at chris-lamb.co.uk
Tue Feb 7 11:10:14 CET 2017


This is an automated email from the git hooks/post-receive script.

lamby pushed a commit to branch master
in repository diffoscope.

commit 2003d09076f589ab4a8149c8bd6d0961feac3b30
Author: Chris Lamb <lamby at debian.org>
Date:   Tue Feb 7 23:07:15 2017 +1300

    presenters: Add a Presenter.start method to simplify logic.
    
    Signed-off-by: Chris Lamb <lamby at debian.org>
---
 diffoscope/presenters/formats.py | 4 ++--
 diffoscope/presenters/json.py    | 7 +++----
 diffoscope/presenters/utils.py   | 3 +++
 3 files changed, 8 insertions(+), 6 deletions(-)

diff --git a/diffoscope/presenters/formats.py b/diffoscope/presenters/formats.py
index f5fa396..92f81fd 100644
--- a/diffoscope/presenters/formats.py
+++ b/diffoscope/presenters/formats.py
@@ -83,7 +83,7 @@ def output_all(difference, parsed_args, has_differences):
                 continue
 
             with make_printer(data['target']) as fn:
-                data['klass'](fn).visit(difference)
+                data['klass'](fn).start(difference)
 
 def text(difference, parsed_args, has_differences):
     # As a special case, write an empty file instead of an empty diff.
@@ -101,7 +101,7 @@ def text(difference, parsed_args, has_differences):
         presenter = TextPresenter(fn, color)
 
         try:
-            presenter.visit(difference)
+            presenter.start(difference)
         except UnicodeEncodeError:
             logger.critical("Console is unable to print Unicode characters. "
                 "Set e.g. PYTHONIOENCODING=utf-8")
diff --git a/diffoscope/presenters/json.py b/diffoscope/presenters/json.py
index 4953ac8..bf4d39e 100644
--- a/diffoscope/presenters/json.py
+++ b/diffoscope/presenters/json.py
@@ -30,11 +30,10 @@ class JSONPresenter(Presenter):
 
         super().__init__()
 
-    def visit(self, difference):
-        super().visit(difference)
+    def start(self, difference):
+        super().start(difference)
 
-        if self.depth == 0:
-            self.print_func(json.dumps(self.root[0], indent=2, sort_keys=True))
+        self.print_func(json.dumps(self.root[0], indent=2, sort_keys=True))
 
     def visit_difference(self, difference):
         self.current.append({
diff --git a/diffoscope/presenters/utils.py b/diffoscope/presenters/utils.py
index bc3e480..18b784d 100644
--- a/diffoscope/presenters/utils.py
+++ b/diffoscope/presenters/utils.py
@@ -26,6 +26,9 @@ class Presenter(object):
     def __init__(self):
         self.depth = 0
 
+    def start(self, difference):
+        self.visit(difference)
+
     def visit(self, difference):
         self.visit_difference(difference)
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reproducible/diffoscope.git


More information about the diffoscope mailing list