12 parser = argparse.ArgumentParser(description=
'Find duplicate config for athena modules in the current and all subfolders. Scans files ending in *onfig.py or *onfigNew.py. Ignores duplicates listed in given reference file.')
13 parser.add_argument(
'referenceFile', metavar=
'referenceFile', type=str,
14 help=
'Reference file with duplicates to ignore.')
15 args = parser.parse_args()
19 files = glob.glob(
'**/*onfig.py', recursive=
True)
20 files = files + glob.glob(
'**/*onfigNew.py', recursive=
True)
22 for line
in open(file,
'r', encoding=
"utf-8"):
23 match = re.search(
r"CompFactory\.(\w+\.?\w+) ?\(", line)
26 if fun
in functionDict:
27 functionDict[fun].
add(file)
29 functionDict[fun] = {file}
32 for item
in functionDict.items():
34 duplicates[item[0]]=
list(item[1])
36 with open(args.referenceFile)
as f:
37 ref = json.loads(f.read())
39 removedDuplicates = {}
40 for refItem
in ref.items():
41 if refItem[0]
not in duplicates.keys():
42 removedDuplicates[refItem[0]]=refItem[1]
44 newRemoved =
list(
set(refItem[1]) -
set(duplicates[refItem[0]]))
45 if len(newRemoved) > 0:
46 removedDuplicates[refItem[0]]= newRemoved
47 newAdded =
list(
set(duplicates[refItem[0]]) -
set(refItem[1]))
49 addedDuplicates[refItem[0]] = newAdded
50 del duplicates[refItem[0]]
51 if len(duplicates) > 0:
52 addedDuplicates.update(duplicates)
54 if len(addedDuplicates) > 0:
55 print(
"New module instance created which is also created in other configuration file(s), please consider using an existing instance (or update the reference file using generateReferenceFile.py):")
56 print(addedDuplicates)
57 if len(removedDuplicates) > 0:
58 print(
"Please update the reference file, expected duplicates are not found:")
59 print(removedDuplicates)