From 97b4410203f8fb7318b0965bfa58925b71a807db Mon Sep 17 00:00:00 2001 From: Oleg Broytman Date: Wed, 13 Dec 2017 15:53:00 +0300 Subject: [PATCH] Feat(cmp): Add option -s --silent --quiet --- TODO | 3 --- docs/index.rst | 10 +++++++++- docs/news.rst | 4 +++- scripts/cmp.py | 18 +++++++++++------- tests/test_cmp.py | 2 +- 5 files changed, 24 insertions(+), 13 deletions(-) diff --git a/TODO b/TODO index 4553922..b6e728a 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,3 @@ -Add option -s --quiet --silent for cmp.py. - - Extend remove-old-files.py: add option -v/--verbose to report every removed file. diff --git a/docs/index.rst b/docs/index.rst index 014ff62..8e4112a 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -25,7 +25,15 @@ Compare two files. Usage:: - cmp.py file1 file2 + cmp.py [-i] [-s --silent --quiet] file1 file2 + +Options:: + + -i, --inhibit-progress-bar + inhibit progress bar + -s, --silent, --quiet + be silent (implied -i) + remove-old-files.py ~~~~~~~~~~~~~~~~~~~ diff --git a/docs/news.rst b/docs/news.rst index 2489f64..516d88e 100644 --- a/docs/news.rst +++ b/docs/news.rst @@ -1,11 +1,13 @@ News ==== -Version 0.6.0 (2017-10-??) +Version 0.6.0 (2017-12-??) -------------------------- * rm.py ask interactively to remove read-only files or directories. +* Add options -s --silent --quiet for cmp.py. + * Add option -f for rm.py. * PyPy. diff --git a/scripts/cmp.py b/scripts/cmp.py index 9fac08c..00ad28d 100755 --- a/scripts/cmp.py +++ b/scripts/cmp.py @@ -6,11 +6,12 @@ import os import sys -def report(): +def report(silent): if show_pbar: global pbar del pbar - sys.stderr.write("Files differ at %d megabayte block\n" % count) + if not silent: + sys.stderr.write("Files differ at %d megabayte block\n" % count) global diff diff = True @@ -19,11 +20,14 @@ if __name__ == '__main__': parser = argparse.ArgumentParser(description='Remove old files') parser.add_argument('-i', '--inhibit-progress-bar', action='store_true', help='inhibit progress bar') + parser.add_argument('-s', '--silent', '--quiet', action='store_true', + help='be silent (implied -i)') parser.add_argument('fname1', help='the first file name') parser.add_argument('fname2', help='the second file name') args = parser.parse_args() - show_pbar = not args.inhibit_progress_bar and sys.stderr.isatty() + show_pbar = not args.inhibit_progress_bar and not args.silent \ + and sys.stderr.isatty() if show_pbar: try: @@ -57,19 +61,19 @@ if __name__ == '__main__': if block1 and block2: if len(block1) != len(block2): - report() + report(args.silent) break elif block1: - report() + report(args.silent) break elif block2: - report() + report(args.silent) break else: break if block1 != block2: - report() + report(args.silent) break count += 1 diff --git a/tests/test_cmp.py b/tests/test_cmp.py index efdd43a..a461aac 100755 --- a/tests/test_cmp.py +++ b/tests/test_cmp.py @@ -22,4 +22,4 @@ def test_cmp_equal(): create_file('test3', 'test3') create_file('test4', 'test4') assert subprocess.call( - [sys.executable, test_prog_path, "-i", "test3", "test4"]) == 1 + [sys.executable, test_prog_path, "-s", "test3", "test4"]) == 1 -- 2.39.2