[Reproducible-commits] [debbindiff] 02/02: Make max report size a command-line option

Jérémy Bobbio lunar at moszumanska.debian.org
Fri Jan 9 08:53:53 UTC 2015


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

lunar pushed a commit to branch master
in repository debbindiff.

commit 7e69b0680090ef8f4c95245d00078526bc46bf68
Author: Jérémy Bobbio <lunar at debian.org>
Date:   Fri Jan 9 08:51:34 2015 +0000

    Make max report size a command-line option
---
 debbindiff.py                 |  6 +++++-
 debbindiff/presenters/html.py | 12 +++++++-----
 debian/debbindiff.1.rst       | 13 +++++++------
 3 files changed, 19 insertions(+), 12 deletions(-)

diff --git a/debbindiff.py b/debbindiff.py
index daaef02..621d6da 100755
--- a/debbindiff.py
+++ b/debbindiff.py
@@ -38,6 +38,9 @@ def create_parser():
                         default=False, help='display debug messages')
     parser.add_argument('--html', metavar='output', dest='html_output',
                         help='write HTML report to given file')
+    parser.add_argument('--max-report-size', metavar='BYTES',
+                        dest='max_report_size', type=int,
+                        help='maximum bytes written in report')
     parser.add_argument('--css', metavar='url', dest='css_url',
                         help='link to an extra CSS for the HTML report')
     parser.add_argument('file1', help='first file to compare')
@@ -57,7 +60,8 @@ def main():
         def print_func(*args, **kwargs):
             kwargs['file'] = output
             print(*args, **kwargs)
-        output_html(differences, css_url=parsed_args.css_url, print_func=print_func)
+        output_html(differences, css_url=parsed_args.css_url, print_func=print_func,
+                    max_page_size=parsed_args.max_report_size)
     if len(differences) > 0:
         sys.exit(1)
 
diff --git a/debbindiff/presenters/html.py b/debbindiff/presenters/html.py
index 88568ff..ae47d1d 100644
--- a/debbindiff/presenters/html.py
+++ b/debbindiff/presenters/html.py
@@ -95,20 +95,20 @@ FOOTER = """
 </html>
 """
 
-MAX_PAGE_SIZE = 2000 * 2 ** 10  # 2000 kB
+DEFAULT_MAX_PAGE_SIZE = 2000 * 2 ** 10  # 2000 kB
 
 
 class PrintLimitReached(Exception):
     pass
 
 
-def create_limited_print_func(print_func):
+def create_limited_print_func(print_func, max_page_size):
     def limited_print_func(s, force=False):
         if not hasattr(limited_print_func, 'char_count'):
             limited_print_func.char_count = 0
         print_func(s)
         limited_print_func.char_count += len(s)
-        if not force and limited_print_func.char_count >= MAX_PAGE_SIZE:
+        if not force and limited_print_func.char_count >= max_page_size:
             raise PrintLimitReached()
     return limited_print_func
 
@@ -185,10 +185,12 @@ def output_header(css_url, print_func):
                         })
 
 
-def output_html(differences, css_url=None, print_func=None):
+def output_html(differences, css_url=None, print_func=None, max_page_size=None):
     if print_func is None:
         print_func = print
-    print_func = create_limited_print_func(print_func)
+    if max_page_size is None:
+        max_page_size = DEFAULT_MAX_PAGE_SIZE
+    print_func = create_limited_print_func(print_func, max_page_size)
     try:
         output_header(css_url, print_func)
         for difference in differences:
diff --git a/debian/debbindiff.1.rst b/debian/debbindiff.1.rst
index f5fd6ea..c97fb34 100644
--- a/debian/debbindiff.1.rst
+++ b/debian/debbindiff.1.rst
@@ -14,7 +14,7 @@ highlight differences between two builds of Debian packages
 SYNOPSIS
 ========
 
-  debbindiff [-h] [--version] [--debug] [--html output] [--css url] file1 file2
+  debbindiff [-h] [--version] [--debug] [--html output] [--max-report-size bytes] [--css url] file1 file2
 
 DESCRIPTION
 ===========
@@ -31,11 +31,12 @@ project.
 OPTIONS
 =======
 
--h, --help     show this help message and exit
---version      show program's version number and exit
---debug        display debug messages
---html output  write HTML report to given file
---css url      link to an extra CSS for the HTML report
+-h, --help               show this help message and exit
+--version                show program's version number and exit
+--debug                  display debug messages
+--html output            write HTML report to given file
+--max-report-size bytes  maximum bytes written in report
+--css url                link to an extra CSS for the HTML report
 
 SEE ALSO
 ========

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



More information about the Reproducible-commits mailing list