-
-
Notifications
You must be signed in to change notification settings - Fork 15
/
find-conflicts.py
80 lines (67 loc) · 2.09 KB
/
find-conflicts.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#!/usr/bin/env python
from __future__ import print_function
from jsoncomment import JsonComment
from jsonschema import validate
import glob
import json
import os
import sys
def decode(s):
for encoding in 'utf-8-sig', 'utf-16':
try:
return s.decode(encoding)
except UnicodeDecodeError:
continue
return s.decode('latin-1')
scoop_root = 'C:/Users/ross/scoop'
buckets_root = scoop_root + '/buckets'
buckets = [
scoop_root + '/apps/scoop/current/bucket',
# buckets_root + '/extras',
# buckets_root + '/nirsoft',
# buckets_root + '/rasa'
]
parser = JsonComment(json)
map = {}
for bucket in buckets:
for json in glob.glob(bucket + '/*.json'):
with open(json, 'rb') as f:
jstr = f.read()
jstr_no_bom = decode(jstr)
json_data = parser.loads(jstr_no_bom)
if 'bin' not in json_data:
continue
base = os.path.basename(json)
base = os.path.splitext(base)[0]
dir = os.path.basename(os.path.dirname(json))
repo = dir + '/' + base
bins = json_data['bin']
if len(bins) == 0:
continue
if type(bins).__name__ != 'list':
bins = [bins]
if len(bins) == 0:
continue
if type(bins).__name__ != 'list':
bins = [bins]
for bin in bins:
if type(bin).__name__ == 'list':
if len(bin) > 1:
file = str(bin[1])
else:
file = str(bin[0])
else:
file = bin
file = os.path.basename(file)
file = os.path.splitext(file)[0]
file = file.lower()
if file not in map:
map[file] = {}
map[file][repo] = 1
# print("%s: %s" % (repo, bin))
sfile = sorted(map.keys())
for file in sfile:
if len(map[file]) > 1:
for repo in map[file]:
print("%s: %s" % (file, repo))
sys.exit(0)