Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Don't show progress information on --quiet #641

Merged
merged 2 commits into from
Nov 25, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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