Tags: patch
Hi, Pabs! I have updated the patch as per suggestions please review it. Thanks! Satyam Zode,
From a1389838a38aecd894e052635e4c3e73f3cf6ef4 Mon Sep 17 00:00:00 2001 From: Satyam Zode <[email protected]> Date: Sun, 12 Jun 2016 11:46:02 +0530 Subject: [PATCH] Added support for argument completion * diffoscope/README.rst: Updated documentation for python-argcomplete * diffoscope/bin/diffoscope: Added env var PYTHON_ARGCOMPLETE_OK * diffoscope/debian/control: Added python-argcomplete as dependencies * diffoscope/debian/rules : Added bash-completion * diffoscope/__main__.py : Added completer class and argument completion support using argcomplete * Closes : #826711 --- README.rst | 5 +++++ bin/diffoscope | 1 + debian/control | 2 ++ debian/rules | 6 +++++- diffoscope/__main__.py | 34 +++++++++++++++++++++++++++++----- 5 files changed, 42 insertions(+), 6 deletions(-) diff --git a/README.rst b/README.rst index 5288e52..093a8ad 100644 --- a/README.rst +++ b/README.rst @@ -59,6 +59,11 @@ Optionally, the following modules will enhance it: ``python-magic``. It is built from `file <http://www.darwinsys.com/file/>`_. Available on Debian and Fedora as ``python3-magic``. +* ``python-argcomplete`` is used for argument completion. + Available on Debian and Fedora as + ``python-argcomplete``. + ``python-argcomplete`` is also available on `PyPI <https://pypi.python.org/pypi/argcomplete/>` as + ``argcomplete``. The various comparators rely on external commands being available. To get a list of them, please run:: diff --git a/bin/diffoscope b/bin/diffoscope index 2393807..2422b70 100755 --- a/bin/diffoscope +++ b/bin/diffoscope @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +# PYTHON_ARGCOMPLETE_OK # -*- coding: utf-8 -*- # # diffoscope: in-depth comparison of files, archives, and directories diff --git a/debian/control b/debian/control index 19619d7..b24fbef 100644 --- a/debian/control +++ b/debian/control @@ -7,9 +7,11 @@ Uploaders: Mattia Rizzolo <[email protected]>, Reiner Herrmann <[email protected]>, Build-Depends: + bash-completion, binutils-multiarch, debhelper (>= 9), dh-python, + python-argcomplete, python3-all, python3-debian, python3-docutils, diff --git a/debian/rules b/debian/rules index b15a73b..5a4e75f 100755 --- a/debian/rules +++ b/debian/rules @@ -8,7 +8,7 @@ ifneq ($(VERSION_dch),$(VERSION_py)) endif %: - dh $@ --with python3 --buildsystem=pybuild + dh $@ --with python3 --with bash-completion --buildsystem=pybuild override_dh_python3: dh_python3 --recommends=python-debian --recommends=rpm-python --recommends=tlsh --recommends=guestfs @@ -27,9 +27,13 @@ override_dh_installman: debian/diffoscope.1 dh_installman -O--buildsystem=pybuild override_dh_clean: + debian/diffoscope.bash-completion rm -f debian/diffoscope.1 dh_clean -O--buildsystem=pybuild +override_dh_auto_build: + register-python-argcomplete diffoscope > debian/diffoscope.bash-completion + diffoscope/presenters/icon.py: favicon.png (echo '# Generated from favicon.png'; \ echo 'FAVICON_BASE64 = """'; \ diff --git a/diffoscope/__main__.py b/diffoscope/__main__.py index ac7913c..3306123 100644 --- a/diffoscope/__main__.py +++ b/diffoscope/__main__.py @@ -1,4 +1,5 @@ #!/usr/bin/env python3 +# PYTHON_ARGCOMPLETE_OK # -*- coding: utf-8 -*- # # diffoscope: in-depth comparison of files, archives, and directories @@ -30,6 +31,10 @@ try: import tlsh except ImportError: tlsh = None +try: + import argcomplete +except ImportError: + argcomplete = None from diffoscope import logger, VERSION, set_locale, clean_all_temp_files import diffoscope.comparators from diffoscope.config import Config @@ -60,25 +65,30 @@ def create_parser(): dest='max_report_size', type=int, help='maximum bytes written in report (default: %d)' % Config.general.max_report_size, - default=Config.general.max_report_size) + default=Config.general.max_report_size).completer=RangeCompleter(0, + Config.general.max_report_size, 200000) parser.add_argument('--separate-file-diff-size', metavar='BYTES', dest='separate_file_diff_size', type=int, help='diff size to load diff on demand, with --html-dir (default: %d)' % Config.general.separate_file_diff_size, - default=Config.general.separate_file_diff_size) + default=Config.general.separate_file_diff_size).completer=RangeCompleter(0, + Config.general.separate_file_diff_size, 20000) parser.add_argument('--max-diff-block-lines', dest='max_diff_block_lines', type=int, help='maximum number of lines per diff block (default: %d)' % Config.general.max_diff_block_lines, - default=Config.general.max_diff_block_lines) + default=Config.general.max_diff_block_lines).completer=RangeCompleter(0, + Config.general.max_diff_block_lines, 5) parser.add_argument('--max-diff-input-lines', dest='max_diff_input_lines', type=int, help='maximum number of lines fed to diff (default: %d)' % Config.general.max_diff_input_lines, - default=Config.general.max_diff_input_lines) + default=Config.general.max_diff_input_lines).completer=RangeCompleter(0, + Config.general.max_diff_input_lines, 2000) parser.add_argument('--fuzzy-threshold', dest='fuzzy_threshold', type=int, help='threshold for fuzzy-matching ' '(0 to disable, %d is default, 400 is high fuzziness)' % (Config.general.fuzzy_threshold), - default=Config.general.fuzzy_threshold) + default=Config.general.fuzzy_threshold).completer=RangeCompleter(0, + 400, 20) parser.add_argument('--new-file', dest='new_file', action='store_true', help='treat absent files as empty') parser.add_argument('--css', metavar='url', dest='css_url', @@ -89,6 +99,12 @@ def create_parser(): parser.add_argument('file2', help='second file to compare') if not tlsh: parser.epilog = 'File renaming detection based on fuzzy-matching is currently disabled. It can be enabled by installing the “tlsh” module available at https://github.com/trendmicro/tlsh' + if argcomplete: + argcomplete.autocomplete(parser) + elif '_ARGCOMPLETE' in os.environ: + print('ERROR: Argument completion requested but Python argcomplete module not installed', file=sys.stderr) + sys.exit(1) + return parser @@ -106,6 +122,14 @@ def make_printer(path): output.close() +class RangeCompleter(object): + def __init__(self, start, end, step): + self.choices = range(start, end + 1, step) + + def __call__(self, **kwargs): + return (str(c) for c in self.choices) + + class ListToolsAction(argparse.Action): def __call__(self, parser, namespace, os_override, option_string=None): from functools import reduce -- 2.1.4
_______________________________________________ Reproducible-builds mailing list [email protected] http://lists.alioth.debian.org/cgi-bin/mailman/listinfo/reproducible-builds
