Skip to content

Commit

Permalink
Don't show progress information on --quiet (#641)
Browse files Browse the repository at this point in the history
Resolves: #636
  • Loading branch information
fniessink committed Nov 25, 2020
1 parent 539da77 commit 5d88156
Showing 1 changed file with 19 additions and 8 deletions.
27 changes: 19 additions & 8 deletions bandit/core/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,9 +220,7 @@ def run_tests(self):
: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
Expand All @@ -234,8 +232,7 @@ def run_tests(self):
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)
Expand All @@ -247,16 +244,30 @@ def run_tests(self):
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

# 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
Expand Down

0 comments on commit 5d88156

Please sign in to comment.