2021-06-14 14:55:49 +00:00
|
|
|
#! /usr/bin/python3
|
|
|
|
|
|
|
|
"""
|
|
|
|
Ensure UMIDS are unique.
|
|
|
|
|
|
|
|
This runs on Python 3.
|
|
|
|
"""
|
2010-08-04 07:17:13 +00:00
|
|
|
|
2016-04-06 23:57:41 +00:00
|
|
|
# ./check-umids.py src
|
2010-08-04 07:17:13 +00:00
|
|
|
|
2019-03-22 10:40:58 +00:00
|
|
|
from __future__ import print_function
|
|
|
|
|
2010-08-04 07:17:13 +00:00
|
|
|
import sys, re, os
|
|
|
|
|
|
|
|
ok = True
|
|
|
|
umids = {}
|
|
|
|
|
2016-04-06 23:57:41 +00:00
|
|
|
for starting_point in sys.argv[1:]:
|
|
|
|
for root, dirs, files in os.walk(starting_point):
|
|
|
|
for fn in [f for f in files if f.endswith(".py")]:
|
|
|
|
fn = os.path.join(root, fn)
|
|
|
|
for lineno,line in enumerate(open(fn, "r").readlines()):
|
|
|
|
lineno = lineno+1
|
|
|
|
if "umid" not in line:
|
|
|
|
continue
|
|
|
|
mo = re.search("umid=[\"\']([^\"\']+)[\"\']", line)
|
|
|
|
if mo:
|
|
|
|
umid = mo.group(1)
|
|
|
|
if umid in umids:
|
|
|
|
oldfn, oldlineno = umids[umid]
|
2019-03-22 10:40:58 +00:00
|
|
|
print("%s:%d: duplicate umid '%s'" % (fn, lineno, umid))
|
|
|
|
print("%s:%d: first used here" % (oldfn, oldlineno))
|
2016-04-06 23:57:41 +00:00
|
|
|
ok = False
|
|
|
|
umids[umid] = (fn,lineno)
|
2010-08-04 07:17:13 +00:00
|
|
|
|
|
|
|
if ok:
|
2019-03-22 10:40:58 +00:00
|
|
|
print("all umids are unique")
|
2010-08-04 07:17:13 +00:00
|
|
|
else:
|
2019-03-22 10:40:58 +00:00
|
|
|
print("some umids were duplicates")
|
2010-08-04 07:17:13 +00:00
|
|
|
sys.exit(1)
|