-
Notifications
You must be signed in to change notification settings - Fork 1
/
pms-parse-dump-compo-places.py
57 lines (46 loc) · 1.71 KB
/
pms-parse-dump-compo-places.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
#!/usr/bin/env python3
import argparse
import sys
import xml.dom.minidom
parser = argparse.ArgumentParser()
parser.add_argument("datafile")
parser.add_argument("pms_datafile")
args = parser.parse_args()
pms_dom = xml.dom.minidom.parse(open(args.pms_datafile, "r"))
iddata = {}
compos = pms_dom.getElementsByTagName("compo")
for compo in compos:
if compo.getAttribute("resultspublic") != "True":
continue
entries = compo.getElementsByTagName("entry")
for entry in entries:
entry_id = entry.getAttribute("id")
entry_position_str = entry.getAttribute("place") or '0'
techniques = entry.getAttribute("techniques")
if len(techniques) == 0:
techniques = None
platform = entry.getAttribute("platform")
if len(platform) == 0:
platform = None
entry_position = int(entry_position_str) or None
iddata[entry_id] = (entry_position, techniques, platform)
import asmmetadata
parsed = asmmetadata.parse_file(open(args.datafile))
for entry in parsed.entries:
if 'pms-id' not in entry:
continue
_, _, pms_id = entry['pms-id'].split("/")
if pms_id not in iddata:
# This probably means that results of a category are not public.
continue
place, techniques, platform = iddata[pms_id]
entry['position'] = place
if techniques is not None:
# techniques = techniques.replace("\\", "\\\\")
# techniques = techniques.replace("\n", "\\n")
entry['techniques'] = techniques
if platform is not None:
entry['platform'] = platform
for section in parsed.sections:
asmmetadata.reorder_positioned_section_entries(section['entries'])
asmmetadata.print_metadata(sys.stdout, parsed)