From e75b4591cc36540111a428dffd629eb3d0474674 Mon Sep 17 00:00:00 2001 From: David Brooks Date: Thu, 5 Oct 2017 11:39:18 +1300 Subject: [PATCH] Python: turn off output when updating path to Python unless `--verbose` given. --- distrib/bin/set_python_path.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/distrib/bin/set_python_path.py b/distrib/bin/set_python_path.py index 5d43d49382..c1d1eae968 100644 --- a/distrib/bin/set_python_path.py +++ b/distrib/bin/set_python_path.py @@ -43,6 +43,7 @@ import os import re import sys +import logging import marshal import argparse import subprocess @@ -97,8 +98,8 @@ def update_script(script_filename, new_path): else: args[0] = new_bin + logging.info('S: %s', script_filename) lines[0] = '#!%s\n' % ' '.join(args) - print('S %s' % script_filename) with open(script_filename, 'w') as f: f.writelines(lines) @@ -111,7 +112,6 @@ def update_scripts(bin_dir, new_path): def update_pyc(filename, new_path): """Updates the filenames stored in pyc files.""" - print("PYCL %s" % filename) with open(filename, 'rb') as f: if sys.version_info < (3, 3): magic = f.read(8) else: magic = f.read(12) @@ -138,7 +138,7 @@ def _process(code): new_code = _process(code) if new_code is not code: - print('B %s' % filename) + logging.info('B: %s', filename) with open(filename, 'wb') as f: f.write(magic) marshal.dump(new_code, f) @@ -209,12 +209,18 @@ def main(): parser.add_argument('--update-path', dest='update_path', help='Path to scripts. Set to "auto" ' 'for autodetection') + parser.add_argument('--verbose', dest='verbose', + help='Show names of updated scripts') + parser.add_argument('path', help='Path to new Python installation.') args = parser.parse_args() if not args.update_path: args.update_path = 'auto' + if not args.verbose: + logging.disable(logging.INFO) + rv = 0 if not update_paths(args.path, args.update_path): rv = 1