diff --git a/bin/build.py b/bin/build.py index 8f7a26fd..9b0df0b6 100755 --- a/bin/build.py +++ b/bin/build.py @@ -136,6 +136,20 @@ help="Target to build for the 'cmake --build' command" ) +def PositiveInt(string): + value = int(string) + if value > 0: + return value + m = 'Should be greater that zero: {}'.format(string) + raise argparse.ArgumentTypeError(m) + +parser.add_argument( + '--discard', + type=PositiveInt, + help='Option to reduce output. Discard every N lines of execution messages' + ' (note that full log is still available in log.txt)' +) + args = parser.parse_args() polly_toolchain = detail.toolchain_name.get(args.toolchain) @@ -233,7 +247,7 @@ polly_temp_dir = os.path.join(build_dir, '_3rdParty', 'polly') if not os.path.exists(polly_temp_dir): os.makedirs(polly_temp_dir) -logging = detail.logging.Logging(polly_temp_dir, args.verbose) +logging = detail.logging.Logging(polly_temp_dir, args.verbose, args.discard) if os.name == 'nt': # Windows diff --git a/bin/detail/call.py b/bin/detail/call.py index 984751ae..bdfef348 100644 --- a/bin/detail/call.py +++ b/bin/detail/call.py @@ -8,19 +8,27 @@ import sys import threading -def tee(infile, log_file, console=None): +def tee(infile, discard, log_file, console=None): """Print `infile` to `files` in a separate thread.""" def fanout(): + discard_counter = 0 for line in iter(infile.readline, b''): - for f in [log_file, console]: - if f is None: - continue - s = line.decode('utf-8') - s = s.replace('\r', '') - s = s.replace('\t', ' ') - s = s.rstrip() # strip spaces and EOL - s += '\n' # append stripped EOL back - f.write(s) + s = line.decode('utf-8') + s = s.replace('\r', '') + s = s.replace('\t', ' ') + s = s.rstrip() # strip spaces and EOL + s += '\n' # append stripped EOL back + log_file.write(s) + if console is None: + continue + if discard is None: + console.write(s) + continue + if discard_counter == 0: + console.write(s) + discard_counter += 1 + if discard_counter == discard: + discard_counter = 0 infile.close() t = threading.Thread(target=fanout) t.daemon = True @@ -38,11 +46,11 @@ def teed_call(cmd_args, logging): threads = [] if logging.verbose: - threads.append(tee(p.stdout, logging.log_file, sys.stdout)) - threads.append(tee(p.stderr, logging.log_file, sys.stderr)) + threads.append(tee(p.stdout, logging.discard, logging.log_file, sys.stdout)) + threads.append(tee(p.stderr, logging.discard, logging.log_file, sys.stderr)) else: - threads.append(tee(p.stdout, logging.log_file)) - threads.append(tee(p.stderr, logging.log_file)) + threads.append(tee(p.stdout, logging.discard, logging.log_file)) + threads.append(tee(p.stderr, logging.discard, logging.log_file)) for t in threads: t.join() # wait for IO completion diff --git a/bin/detail/logging.py b/bin/detail/logging.py index e7317b98..4b780e28 100644 --- a/bin/detail/logging.py +++ b/bin/detail/logging.py @@ -4,7 +4,8 @@ import os class Logging: - def __init__(self, polly_temp_dir, verbose): + def __init__(self, polly_temp_dir, verbose, discard): self.verbose = verbose + self.discard = discard self.log_path = os.path.join(polly_temp_dir, 'log.txt') self.log_file = open(self.log_path, 'w')