[diffoscope] 02/05: Split output and configuration of presenters.

Chris Lamb chris at chris-lamb.co.uk
Sun Apr 30 11:02:23 CEST 2017


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

lamby pushed a commit to branch experimental
in repository diffoscope.

commit 3e8c0c9d4dec343cb0a559c42e8660685e6b6f13
Author: Chris Lamb <lamby at debian.org>
Date:   Sun Apr 30 09:15:18 2017 +0100

    Split output and configuration of presenters.
    
    Signed-off-by: Chris Lamb <lamby at debian.org>
---
 diffoscope/main.py               |  5 +++--
 diffoscope/presenters/formats.py | 25 +++++++++++++------------
 2 files changed, 16 insertions(+), 14 deletions(-)

diff --git a/diffoscope/main.py b/diffoscope/main.py
index 9a89db1..f7c060d 100644
--- a/diffoscope/main.py
+++ b/diffoscope/main.py
@@ -40,7 +40,7 @@ from .difference import Difference
 from .comparators import ComparatorManager
 from .external_tools import EXTERNAL_TOOLS
 from .presenters.html import JQUERY_SYSTEM_LOCATIONS
-from .presenters.formats import output_all
+from .presenters.formats import configure_presenters, output_all
 from .comparators.utils.compare import compare_root_paths
 
 logger = logging.getLogger(__name__)
@@ -285,6 +285,7 @@ def run_diffoscope(parsed_args):
     Config().fuzzy_threshold = parsed_args.fuzzy_threshold
     Config().new_file = parsed_args.new_file
     Config().excludes = parsed_args.excludes
+    presenter_config = configure_presenters(parsed_args)
     # Don't waste time computing visual differences if we won't use them.
     Config().compute_visual_diffs = any((
         parsed_args.html_output,
@@ -304,7 +305,7 @@ def run_diffoscope(parsed_args):
     if difference is None and parsed_args.output_empty:
         difference = Difference(None, parsed_args.path1, parsed_args.path2)
     with profile('main', 'outputs'):
-        output_all(difference, parsed_args, has_differences)
+        output_all(presenter_config, difference, parsed_args, has_differences)
     return 1 if has_differences else 0
 
 
diff --git a/diffoscope/presenters/formats.py b/diffoscope/presenters/formats.py
index 963d8d0..e30ac8e 100644
--- a/diffoscope/presenters/formats.py
+++ b/diffoscope/presenters/formats.py
@@ -31,14 +31,7 @@ from .restructuredtext import RestructuredTextPresenter
 logger = logging.getLogger(__name__)
 
 
-def output_all(difference, parsed_args, has_differences):
-    """
-    Generate all known output formats.
-    """
-
-    if difference is None:
-        return
-
+def configure_presenters(parsed_args):
     FORMATS = {
         'text': {
             'klass': TextPresenter,
@@ -66,14 +59,22 @@ def output_all(difference, parsed_args, has_differences):
         },
     }
 
+    result = {k: v for k, v in FORMATS.items() if v['target'] is not None}
+
     # If no output specified, default to printing --text output to stdout
-    if not any(x['target'] for x in FORMATS.values()):
+    if not result:
         parsed_args.text_output = FORMATS['text']['target'] = '-'
+        result['text'] = FORMATS['text']
+
+    logger.debug(
+        "Will generate the following formats: %s", ", ".join(result.keys()),
+    )
+
+    return result
 
-    for name, data in FORMATS.items():
-        if data['target'] is None:
-            continue
 
+def output_all(config, difference, parsed_args, has_differences):
+    for name, data in config.items():
         logger.debug("Generating %r output at %r", name, data['target'])
 
         with profile('output', name):

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


More information about the diffoscope mailing list