From 2a3c727dfed7465090c2b9bae2f5ac88b3c6dca0 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Mon, 5 Aug 2019 17:31:49 -0400 Subject: Make includes interface more like the rest of practracker Everything else assumes that somebody else will open the file for it. --- scripts/maint/practracker/includes.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) (limited to 'scripts/maint/practracker/includes.py') diff --git a/scripts/maint/practracker/includes.py b/scripts/maint/practracker/includes.py index fbd68f4f52..fcc527c983 100755 --- a/scripts/maint/practracker/includes.py +++ b/scripts/maint/practracker/includes.py @@ -103,11 +103,9 @@ class Rules(object): "Forbidden include of {}".format(include), is_advisory=self.is_advisory) - def applyToFile(self, fname): - with open_file(fname) as f: - #print(fname) - for error in self.applyToLines(iter(f), "{}:".format(fname)): - yield error + def applyToFile(self, fname, f): + for error in self.applyToLines(iter(f), "{}:".format(fname)): + yield error def noteUnusedRules(self): for p in self.patterns: @@ -200,14 +198,14 @@ def toposort(graph, limit=100): return all_levels -def consider_include_rules(fname): +def consider_include_rules(fname, f): dirpath = os.path.split(fname)[0] rules_fname = os.path.join(dirpath, RULES_FNAME) rules = load_include_rules(os.path.join(dirpath, RULES_FNAME)) if rules is None: return - for err in rules.applyToFile(fname): + for err in rules.applyToFile(fname, f): yield err list_unused = False @@ -221,8 +219,9 @@ def walk_c_files(topdir="src"): for fname in fnames: if fname_is_c(fname): fullpath = os.path.join(dirpath,fname) - for err in consider_include_rules(fullpath): - yield err + with open(fullpath) as f: + for err in consider_include_rules(fullpath, f): + yield err def run_check_includes(topdir, list_unused=False, log_sorted_levels=False, list_advisories=False): -- cgit v1.2.3-54-g00ecf