From caa2b925077d5a78d6b585b337578ec621d968b2 Mon Sep 17 00:00:00 2001 From: Tony Duckles Date: Thu, 26 Jan 2012 00:32:15 -0600 Subject: [PATCH] Additive verbosity command-line args --- svn2svn/run/svn2svn.py | 41 ++++++++++++++++++++++----------------- svn2svn/shell.py | 4 ++-- svn2svn/ui.py | 13 +++++++------ tests/make-replay-repo.sh | 2 +- 4 files changed, 33 insertions(+), 27 deletions(-) diff --git a/svn2svn/run/svn2svn.py b/svn2svn/run/svn2svn.py index 2f26aec..60a6e18 100644 --- a/svn2svn/run/svn2svn.py +++ b/svn2svn/run/svn2svn.py @@ -59,6 +59,9 @@ def commit_from_svn_log_entry(log_entry, files=None, keep_author=False, target_r options += ["--with-revprop", "%s=%s" % (key, str(revprops[key]))] if files: options += list(files) + if ui.get_level() >= ui.EXTRA: + ui.status(">> commit_from_svn_log_entry: Pre-commit _wc_target status:", level=ui.EXTRA, color='CYAN') + ui.status(run_svn(["status"]), level=ui.EXTRA, color='CYAN') output = run_svn(options) rev = None if output: @@ -223,18 +226,19 @@ def find_svn_ancestors(svn_repos_url, base_path, source_path, source_rev, prefix working_path = working_path.replace(d['path'], d['copyfrom_path']) working_rev = d['copyfrom_rev'] ancestors.append({'path': working_path, 'revision': working_rev}) - max_len = 0 - for idx in range(len(ancestors)): - d = ancestors[idx] - max_len = max(max_len, len(d['path']+"@"+str(d['revision']))) - ui.status(prefix + ">> find_svn_ancestors: Found parent ancestors:", level=ui.DEBUG, color='YELLOW_B') - for idx in range(len(ancestors)-1): - d = ancestors[idx] - d_next = ancestors[idx+1] - ui.status(prefix + " [%s] %s <-- %s", idx, - str(d['path']+"@"+str(d['revision'])).ljust(max_len), - str(d_next['path']+"@"+str(d_next['revision'])).ljust(max_len), - level=ui.DEBUG, color='YELLOW') + if ui.get_level() >= ui.DEBUG: + max_len = 0 + for idx in range(len(ancestors)): + d = ancestors[idx] + max_len = max(max_len, len(d['path']+"@"+str(d['revision']))) + ui.status(prefix + ">> find_svn_ancestors: Found parent ancestors:", level=ui.DEBUG, color='YELLOW_B') + for idx in range(len(ancestors)-1): + d = ancestors[idx] + d_next = ancestors[idx+1] + ui.status(prefix + " [%s] %s <-- %s", idx, + str(d['path']+"@"+str(d['revision'])).ljust(max_len), + str(d_next['path']+"@"+str(d_next['revision'])).ljust(max_len), + level=ui.DEBUG, color='YELLOW') else: ui.status(prefix + ">> find_svn_ancestors: No ancestor-chain found: %s", svn_repos_url+base_path+"/"+source_path+"@"+str(source_rev), level=ui.DEBUG, color='YELLOW') @@ -611,12 +615,10 @@ def run_parser(parser): parser.remove_option("--help") parser.add_option("-h", "--help", dest="show_help", action="store_true", help="show this help message and exit") - parser.add_option("-v", "--verbose", dest="verbosity", const=ui.VERBOSE, - default=10, action="store_const", - help="enable additional output") - parser.add_option("--debug", dest="verbosity", const=ui.DEBUG, - action="store_const", - help="enable debugging output") + parser.add_option("-v", "--verbose", dest="verbosity", action="count", default=1, + help="enable additional output (use -vv or -vvv for more)") + parser.add_option("--debug", dest="verbosity", const=ui.DEBUG, action="store_const", + help="enable debugging output (same as -vvv)") options, args = parser.parse_args() if options.show_help: parser.print_help() @@ -625,6 +627,9 @@ def run_parser(parser): prog_name = os.path.basename(sys.argv[0]) print prog_name, full_version sys.exit(0) + if options.verbosity < 10: + # Expand multiple "-v" arguments to a real ui._level value + options.verbosity *= 10 ui.update_config(options) return options, args diff --git a/svn2svn/shell.py b/svn2svn/shell.py index a86594a..988dba6 100644 --- a/svn2svn/shell.py +++ b/svn2svn/shell.py @@ -93,7 +93,7 @@ def _run_raw_command(cmd, args, fail_if_stderr=False, no_fail=False): if cmd == 'svn' and args[0] in ['status', 'st', 'log', 'info', 'list', 'propset', 'update', 'up', 'cleanup', 'revert']: # Show status-only commands (commands which make no changes to WC) in dim-blue color = 'BLUE' - ui.status("$ %s", cmd_string, level=ui.DEBUG, color=color) + ui.status("$ %s", cmd_string, level=ui.EXTRA, color=color) try: pipe = Popen([cmd] + args, executable=cmd, stdout=PIPE, stderr=PIPE) except OSError: @@ -111,7 +111,7 @@ def _run_raw_command(cmd, args, fail_if_stderr=False, no_fail=False): return out def _run_raw_shell_command(cmd, no_fail=False): - ui.status("* %s", cmd, level=ui.DEBUG, color='BLUE') + ui.status("* %s", cmd, level=ui.EXTRA, color='BLUE') st, out = commands.getstatusoutput(cmd) if st != 0 and not nofail: raise ExternalCommandFailed( diff --git a/svn2svn/ui.py b/svn2svn/ui.py index 457bbd8..6a96b16 100644 --- a/svn2svn/ui.py +++ b/svn2svn/ui.py @@ -24,13 +24,12 @@ def termwidth(): pass return 80 - # Log levels ERROR = 0 DEFAULT = 10 VERBOSE = 20 -DEBUG = 30 - +EXTRA = 30 +DEBUG = 40 # SGR foreground color codes _colors = { @@ -43,11 +42,9 @@ _colors = { 'CYAN': '36', 'CYAN_B': '96', 'WHITE': '37', 'WHITE_B': '97' } - # Configuration _level = DEFAULT - def status(msg, *args, **kwargs): """Write a status message. @@ -89,8 +86,12 @@ def status(msg, *args, **kwargs): stream.write(msg) stream.flush() - def update_config(options): """Update UI configuration.""" global _level _level = options.verbosity + +def get_level(): + """Verbosity level""" + global _level + return _level diff --git a/tests/make-replay-repo.sh b/tests/make-replay-repo.sh index 52938d0..491560d 100755 --- a/tests/make-replay-repo.sh +++ b/tests/make-replay-repo.sh @@ -19,4 +19,4 @@ echo "" # svn2svn /trunk svn mkdir -q -m "Add /trunk" $REPOURL/trunk -../svn2svn.py -a -v file://$PWD/_repo_ref/trunk file://$PWD/_repo_replay/trunk +../svn2svn.py -a $1 file://$PWD/_repo_ref/trunk file://$PWD/_repo_replay/trunk -- 2.45.2