# HG changeset patch # User Pierre-Yves David # Date 1268765577 -3600 # Node ID b1f4fcef99b327d8a37673bd94327c6781fb7a84 # Parent 5f92bde72eef1fdf3b1230dfe62682d49462f6c5 check-code: Add a ``checkfile`` function The part of the code actually checking each file is moved in the ``checkfile`` function to allow external reuses. diff -r 5f92bde72eef -r b1f4fcef99b3 contrib/check-code.py --- a/contrib/check-code.py Tue Mar 16 19:52:56 2010 +0100 +++ b/contrib/check-code.py Tue Mar 16 19:52:57 2010 +0100 @@ -133,6 +133,36 @@ ('test script', r'(.*/)?test-[^.~]*$', testfilters, testpats), ('c', r'.*\.c$', cfilters, cpats), ] +def checkfile(f): + """checks style and portability of a given file""" + for name, match, filters, pats in checks: + fc = 0 + if not re.match(match, f): + continue + pre = post = open(f).read() + if "no-" + "check-code" in pre: + break + for p, r in filters: + post = re.sub(p, r, post) + # print post # uncomment to show filtered version + z = enumerate(zip(pre.splitlines(), post.splitlines(True))) + for n, l in z: + if "check-code" + "-ignore" in l[0]: + continue + lc = 0 + for p, msg in pats: + if re.search(p, l[1]): + if not lc: + print "%s:%d:" % (f, n + 1) + print " > %s" % l[0] + print " %s" % msg + lc += 1 + fc += 1 + if fc == 15: + print " (too many errors, giving up)" + break + break + if __name__ == "__main__": if len(sys.argv) == 1: @@ -141,30 +171,4 @@ check = sys.argv[1:] for f in check: - for name, match, filters, pats in checks: - fc = 0 - if not re.match(match, f): - continue - pre = post = open(f).read() - if "no-" + "check-code" in pre: - break - for p, r in filters: - post = re.sub(p, r, post) - # print post # uncomment to show filtered version - z = enumerate(zip(pre.splitlines(), post.splitlines(True))) - for n, l in z: - if "check-code" + "-ignore" in l[0]: - continue - lc = 0 - for p, msg in pats: - if re.search(p, l[1]): - if not lc: - print "%s:%d:" % (f, n + 1) - print " > %s" % l[0] - print " %s" % msg - lc += 1 - fc += 1 - if fc == 15: - print " (too many errors, giving up)" - break - break + checkfile(f)