]> git.ipfire.org Git - thirdparty/tor.git/commitdiff
practracker: better warning/regen handling
authorNick Mathewson <nickm@torproject.org>
Tue, 30 Jul 2019 15:54:05 +0000 (11:54 -0400)
committerNick Mathewson <nickm@torproject.org>
Tue, 30 Jul 2019 15:54:05 +0000 (11:54 -0400)
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.

scripts/maint/practracker/practracker.py
scripts/maint/practracker/problem.py

index fb6649bdcb64587b96cc2e4ce0deb476894fed97..a60b0a8425ea89e1fec40cdd791b8863d1df32b6 100755 (executable)
@@ -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()
index d162e19ef90c4a4b27a6bcea64b09ac335289b67..d09e94151823c9fc4c6cbd286a123e192022b697 100644 (file)
@@ -145,10 +145,6 @@ class Item(object):
         else:
             return STATUS_OK
 
-    def warn(self):
-        """Warn about this problem on stderr only."""
-        print("(warning) {}".format(self), file=sys.stderr)
-
     def key(self):
         """Generate a unique key that describes this problem that can be used as a dictionary key"""
         # Item location is a filesystem path, so we need to normalize this