Skip to content
This repository has been archived by the owner on May 17, 2021. It is now read-only.

Commit

Permalink
Add '--discard' option
Browse files Browse the repository at this point in the history
  • Loading branch information
ruslo committed Oct 1, 2015
1 parent 8facfc2 commit 29164e0
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 16 deletions.
16 changes: 15 additions & 1 deletion bin/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
36 changes: 22 additions & 14 deletions bin/detail/call.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion bin/detail/logging.py
Original file line number Diff line number Diff line change
Expand Up @@ -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')

0 comments on commit 29164e0

Please sign in to comment.