Don't show progress information on --quiet
Resolves:
@@ -220,9 +220,7 @@ class BanditManager(object):
:return: -
'''
- # display progress, if number of files warrants it
- if len(self.files_list) > self.progress:
- sys.stderr.write("%s [" % len(self.files_list))
+ self._show_progress("%s [" % len(self.files_list))
# if we have problems with a file, we'll remove it from the files_list
# and add it to the skipped list instead
@@ -234,8 +232,7 @@ class BanditManager(object):
if len(self.files_list) > self.progress:
# is it time to update the progress indicator?
if count % self.progress == 0:
- sys.stderr.write("%s.. " % count)
- sys.stderr.flush()
+ self._show_progress("%s.. " % count, flush=True)
try:
if fname == '-':
sys.stdin = os.fdopen(sys.stdin.fileno(), 'rb', 0)
@@ -247,9 +244,7 @@ class BanditManager(object):
self.skipped.append((fname, e.strerror))
new_files_list.remove(fname)
- if len(self.files_list) > self.progress:
- sys.stderr.write("]\n")
- sys.stderr.flush()
+ self._show_progress("]\n", flush=True)
# reflect any files which may have been skipped
self.files_list = new_files_list
@@ -257,6 +252,22 @@ class BanditManager(object):
# do final aggregation of metrics
self.metrics.aggregate()
+ def _show_progress(self, message, flush=False):
+ '''Show progress on stderr
+
+ Write progress message to stderr, if number of files warrants it and
+ log level is high enough.
+
+ :param message: The message to write to stderr
+ :param flush: Whether to flush stderr after writing the message
+ :return:
+ '''
+ if len(self.files_list) > self.progress and \
+ LOG.getEffectiveLevel() <= logging.INFO:
+ sys.stderr.write(message)
+ if flush:
+ sys.stderr.flush()
+
def _parse_file(self, fname, fdata, new_files_list):
try:
# parse the current file
