-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
50 lines (35 loc) · 1.36 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import argparse
import json
class Module(object):
def __init__(self, key, source, version, module_dir):
self.key = key
self.source = source
self.version = version
self.dir = module_dir
def main():
parser = argparse.ArgumentParser()
parser.add_argument('path', type=str, help='path to modules.json')
args = parser.parse_args()
modules = []
with open(args.path) as stream:
input_data = json.loads(stream.read())
for module in input_data['Modules']:
if not all(key in module for key in ('Key', 'Source', 'Version', 'Dir')):
continue
modules.append(Module(module['Key'], module['Source'], module['Version'], module['Dir']))
sources = list(set([module.source for module in modules]))
diverged = False
for source in sources:
same_source_modules = [module for module in modules if module.source == source]
uniques = list({object_.version: object_ for object_ in same_source_modules}.values())
if len(uniques) > 1:
diverged = True
print('Diverged module version detected for module: {}'.format(source))
print('Resources:')
for res in uniques:
print('Directory: {}, key: {}, version: {}'.format(res.dir, res.key, res.version))
if diverged:
exit(1)
else:
exit(0)
main()