[tor-commits] [tor/master] Practracker: add a --list-overstrict option

dgoulet at torproject.org dgoulet at torproject.org
Thu Aug 1 14:20:43 UTC 2019


commit a5e1fa3a036b0200e049625c427080881b276730
Author: Nick Mathewson <nickm at torproject.org>
Date:   Wed Jul 17 15:06:34 2019 +0200

    Practracker: add a --list-overstrict option
    
    This option lists every exception that is stricter than it needs to
    be.
    
    Part of 30752
---
 scripts/maint/practracker/practracker.py | 12 ++++++++++++
 scripts/maint/practracker/problem.py     | 17 +++++++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/scripts/maint/practracker/practracker.py b/scripts/maint/practracker/practracker.py
index 0dc63f765..1b6502fe5 100755
--- a/scripts/maint/practracker/practracker.py
+++ b/scripts/maint/practracker/practracker.py
@@ -56,6 +56,7 @@ else:
 def consider_file_size(fname, f):
     """Consider file size issues for 'f' and return the number of new issues was found"""
     file_size = metrics.get_file_len(f)
+
     if file_size > MAX_FILE_SIZE:
         p = problem.FileSizeProblem(fname, file_size)
         if ProblemVault.register_problem(p):
@@ -164,6 +165,8 @@ def main(argv):
     parser = argparse.ArgumentParser(prog=progname)
     parser.add_argument("--regen", action="store_true",
                         help="Regenerate the exceptions file")
+    parser.add_argument("--list-overstrict", action="store_true",
+                        help="List over-strict exceptions")
     parser.add_argument("--exceptions",
                         help="Override the location for the exceptions file")
     parser.add_argument("topdir", default=".", nargs="?",
@@ -213,6 +216,15 @@ See doc/HACKING/HelpfulTools.md for more information on using practracker.\
 """.format(found_new_issues, exceptions_file)
         print(new_issues_str)
 
+    if args.list_overstrict:
+        def k_fn(tup):
+            return tup[0].key()
+        for (ex,p) in sorted(ProblemVault.list_overstrict_exceptions(), key=k_fn):
+            if p is None:
+                print(ex, "->", 0)
+            else:
+                print(ex, "->", p.metric_value)
+
     sys.exit(found_new_issues)
 
 if __name__ == '__main__':
diff --git a/scripts/maint/practracker/problem.py b/scripts/maint/practracker/problem.py
index c82c5db57..751ceb910 100644
--- a/scripts/maint/practracker/problem.py
+++ b/scripts/maint/practracker/problem.py
@@ -22,6 +22,9 @@ class ProblemVault(object):
     def __init__(self, exception_fname=None):
         # Exception dictionary: { problem.key() : Problem object }
         self.exceptions = {}
+        # Exception dictionary: maps key to the problem it was used to
+        # suppress.
+        self.used_exception_for = {}
 
         if exception_fname == None:
             return
@@ -71,9 +74,23 @@ class ProblemVault(object):
         if problem.is_worse_than(self.exceptions[problem.key()]):
             print(problem)
             return True
+        else:
+            self.used_exception_for[problem.key()] = problem
 
         return False
 
+    def list_overstrict_exceptions(self):
+        """Return an iterator of tuples containing (ex,prob) where ex is an
+           exceptions in this vault that are stricter than it needs to be, and
+           prob is the worst problem (if any) that it covered.
+        """
+        for k in self.exceptions:
+            e = self.exceptions[k]
+            p = self.used_exception_for.get(k)
+            if p is None or e.is_worse_than(p):
+                yield (e, p)
+
+
 class Problem(object):
     """
     A generic problem in our source code. See the subclasses below for the





More information about the tor-commits mailing list