forked from amtep/ck3-tiger
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sort-log.py
executable file
·70 lines (56 loc) · 1.52 KB
/
sort-log.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
#!/usr/bin/python3
import os.path
import sys
fname = sys.argv[1]
print(fname, file=sys.stderr)
try:
text = open(fname, encoding="utf-8").read()
except:
try:
text = open(fname, encoding="windows-1252").read()
except:
# triggers.log has a stray 0x90 in it
text = open(fname, encoding="utf-8", errors="replace").read()
SEPARATOR = "\n--------------------\n\n"
items = text.split(SEPARATOR)
if fname.endswith("event_targets.log"):
header = items[0]
footer = items[-1]
del items[0]
del items[-1]
items.sort()
items.insert(0, header)
items.append(footer)
print(SEPARATOR.join(items))
elif fname.endswith("triggers.log"):
header = items[0:2]
del items[0:1]
items.sort()
items.insert(0, header[1])
items.insert(0, header[0])
print(SEPARATOR.join(items))
elif fname.endswith("effects.log"):
header = items[0]
del items[0]
items.sort()
items.insert(0, header)
print(SEPARATOR.join(items))
elif fname.endswith("modifiers.log"):
items = text.split("\n\n")
sortable = []
for item in items:
lines = item.splitlines()
if len(lines) == 3:
if lines[0].startswith("Printing "):
del lines[0]
elif lines[1].startswith("Extra "):
del lines[1]
if not lines:
continue
lines = [ lines[1], lines[0] ]
sortable.append(lines)
sortable.sort()
for lines in sortable:
print(lines[1])
print(lines[0])
print()