practracker: better warning/regen handling

Now that there is only one toplevel place where we print problems,
we can redirect just that one print to a file when we are
regenerating the exceptions.txt file.  Previously we redirected
sys.stdout, which is naughty, and forced us to send warnings (and
warnings alone) to stderr.
This commit is contained in:
Nick Mathewson
2019-07-30 11:54:05 -04:00
parent 3f303c102a
commit a79e2c2975
2 changed files with 5 additions and 8 deletions
+5 -4
View File
@@ -192,11 +192,11 @@ def main(argv):
if args.regen:
tmpname = exceptions_file + ".tmp"
tmpfile = open(tmpname, "w")
sys.stdout = tmpfile
sys.stdout.write(HEADER)
problem_file = tmpfile
ProblemVault = problem.ProblemVault()
else:
ProblemVault = problem.ProblemVault(exceptions_file)
problem_file = sys.stdout
# 2.1) Adjust the exceptions so that we warn only about small problems,
# and produce errors on big ones.
@@ -208,10 +208,11 @@ def main(argv):
for item in filt.filter(consider_all_metrics(files_list)):
status = ProblemVault.register_problem(item)
if status == problem.STATUS_ERR:
print(item)
print(item, file=problem_file)
found_new_issues += 1
elif status == problem.STATUS_WARN:
item.warn()
# warnings always go to stdout.
print("(warning) {}".format(item))
if args.regen:
tmpfile.close()