Line | |
---|
1 | #! /usr/bin/python3 |
---|
2 | |
---|
3 | """ |
---|
4 | Ensure UMIDS are unique. |
---|
5 | |
---|
6 | This runs on Python 3. |
---|
7 | """ |
---|
8 | |
---|
9 | # ./check-umids.py src |
---|
10 | |
---|
11 | |
---|
12 | import sys, re, os |
---|
13 | |
---|
14 | ok = True |
---|
15 | umids = {} |
---|
16 | |
---|
17 | for starting_point in sys.argv[1:]: |
---|
18 | for root, dirs, files in os.walk(starting_point): |
---|
19 | for fn in [f for f in files if f.endswith(".py")]: |
---|
20 | fn = os.path.join(root, fn) |
---|
21 | for lineno,line in enumerate(open(fn, "r").readlines()): |
---|
22 | lineno = lineno+1 |
---|
23 | if "umid" not in line: |
---|
24 | continue |
---|
25 | mo = re.search("umid=[\"\']([^\"\']+)[\"\']", line) |
---|
26 | if mo: |
---|
27 | umid = mo.group(1) |
---|
28 | if umid in umids: |
---|
29 | oldfn, oldlineno = umids[umid] |
---|
30 | print("%s:%d: duplicate umid '%s'" % (fn, lineno, umid)) |
---|
31 | print("%s:%d: first used here" % (oldfn, oldlineno)) |
---|
32 | ok = False |
---|
33 | umids[umid] = (fn,lineno) |
---|
34 | |
---|
35 | if ok: |
---|
36 | print("all umids are unique") |
---|
37 | else: |
---|
38 | print("some umids were duplicates") |
---|
39 | sys.exit(1) |
---|
Note: See
TracBrowser
for help on using the repository browser.