-
Notifications
You must be signed in to change notification settings - Fork 3
/
modlist.py
55 lines (42 loc) · 1.22 KB
/
modlist.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
#!/usr/bin/python
import os
import json
import pprint
import modanalyzer
"""Given a kind, get id -> mod -> key/value. Used for showing conflicts."""
def sliceAcross(contents, kind):
sliced = {}
for mod, content in contents.iteritems():
for id, data in content.get(kind, {}).iteritems():
id = intIfInt(id)
if not sliced.has_key(id):
sliced[id] = {}
sliced[id][mod] = data
return sliced
"""Get n as an integer, if it can be parsed as an integer."""
def intIfInt(n):
try:
return int(n)
except:
return n
def getKinds(contents):
kinds = set()
for mod, content in contents.iteritems():
for kind in content.keys():
kinds.add(kind)
return kinds
def showSlice(sliced):
for id in sorted(sliced.keys()):
mods = sliced[id].keys()
print id, "\t", "\t".join(mods)
def main():
content = modanalyzer.load()
for kind in getKinds(content):
print
print "*" * (len(kind) + 4)
print "*", kind, "*"
print "*" * (len(kind) + 4)
showSlice(sliceAcross(content, kind))
#print json.dumps(content, sort_keys=True, indent=1)
if __name__ == "__main__":
main()