[diffoscope] 02/03: Can tidy diffoscope.presenters.utils now we don't have to special-case profiling.

Chris Lamb chris at chris-lamb.co.uk
Mon Jan 2 19:25:56 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 7222ff3e00653e26b698cd1053faeb8f053739de
Author: Chris Lamb <lamby at debian.org>
Date:   Mon Jan 2 18:24:37 2017 +0000

    Can tidy diffoscope.presenters.utils now we don't have to special-case profiling.
    
    Gbp-Dch: Ignore
---
 diffoscope/presenters/utils.py | 46 +++++++++++++++++++++++-------------------
 1 file changed, 25 insertions(+), 21 deletions(-)

diff --git a/diffoscope/presenters/utils.py b/diffoscope/presenters/utils.py
index 041d29f..066b4b7 100644
--- a/diffoscope/presenters/utils.py
+++ b/diffoscope/presenters/utils.py
@@ -33,26 +33,36 @@ def output_all(difference, parsed_args, has_differences):
     Generate all known output formats.
     """
 
+    if difference is None:
+        return
+
+    FORMATS = {
+        'text': {
+            'fn': text,
+            'target': parsed_args.text_output,
+        },
+        'html': {
+            'fn': html,
+            'target': parsed_args.html_output,
+        },
+        'html_directory': {
+            'fn': html_directory,
+            'target': parsed_args.html_output_directory,
+        },
+    }
+
     # If no output specified, default to printing --text output to stdout
-    if not any((
-        parsed_args.text_output,
-        parsed_args.html_output,
-        parsed_args.html_output_directory,
-    )):
-        parsed_args.text_output = '-'
-
-    for name, fn, target in (
-        ('text', text, parsed_args.text_output),
-        ('html', html, parsed_args.html_output),
-        ('html_directory', html_directory, parsed_args.html_output_directory),
-    ):
-        if target is None:
+    if not any(x['target'] for x in FORMATS.values()):
+        FORMATS['text']['target'] = '-'
+
+    for name, data in FORMATS.items():
+        if data['target'] is None:
             continue
 
-        logger.debug("Generating %r output at %r", name, target)
+        logger.debug("Generating %r output at %r", name, data['target'])
 
         with profile('output', name):
-            fn(difference, parsed_args, has_differences)
+            data['fn'](difference, parsed_args, has_differences)
 
 def text(difference, parsed_args, has_differences):
     # As a sppecial case, write an empty file instead of an empty diff.
@@ -70,9 +80,6 @@ def text(difference, parsed_args, has_differences):
         output_text(difference, print_func=fn, color=color)
 
 def html(difference, parsed_args, has_differences):
-    if difference is None:
-        return
-
     with make_printer(parsed_args.html_output) as fn:
         output_html(
             difference,
@@ -81,9 +88,6 @@ def html(difference, parsed_args, has_differences):
         )
 
 def html_directory(difference, parsed_args, has_differences):
-    if difference is None:
-        return
-
     output_html_directory(
         parsed_args.html_output_directory,
         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