forked from Chupalika/Kaleo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdiff.py
98 lines (83 loc) · 3.11 KB
/
diff.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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
#Reads two output files from shuffleparser and prints any differences between corresponding entries
#Usage: python diff.py input1 input2
#The input files are expected to use the format that is outputted by shuffleparser.py
#Namely:
#- Two line breaks (\n) between entries
#- First line of an entry is the index (which is ignored)
#- The rest of the lines of an entry will be of the format valuename: value
#It's also assumed that entries in the two files will be in the same order (meaning it doesn't check if the indexes are the same... for now)
#This has only been tested with Pokemon, Stage, and Ability data
import sys
from collections import OrderedDict
#here is a list of value names to ignore
ignorelist = ["Background ID", "Layout Index", "Coin reward (first clear)", "Coin reward (repeat clear)"]
inputold = open(sys.argv[1])
contentsold = inputold.read()
entriesold = contentsold.split("\n\n")
inputnew = open(sys.argv[2])
contentsnew = inputnew.read()
entriesnew = contentsnew.split("\n\n")
#find indexes of entries that are different
updatedentryindexes = []
for i in range(len(entriesnew)):
if i >= len(entriesold):
updatedentryindexes.append(i)
elif entriesnew[i] != entriesold[i]:
updatedentryindexes.append(i)
for index in updatedentryindexes:
#print new entries
if index >= len(entriesold):
print entriesnew[index]
#line breaks between entries
print
continue
#get values of old entry
oldentry = entriesold[index]
oldvalues = oldentry.split("\n")
oldvaluesdict = OrderedDict()
for i in range(len(oldvalues)):
#ignore index
if i == 0:
continue
value = oldvalues[i]
varname = value[0:value.find(":")]
varvalue = value[value.find(":")+2:]
#ignore values in ignorelist
if varname in ignorelist:
continue
oldvaluesdict[varname] = varvalue
#get values of new entry
newentry = entriesnew[index]
newvalues = newentry.split("\n")
newvaluesdict = OrderedDict()
for i in range(len(newvalues)):
#ignore index
if i == 0:
continue
value = newvalues[i]
varname = value[0:value.find(":")]
varvalue = value[value.find(":")+2:]
#ignore values in ignorelist
if varname in ignorelist:
continue
newvaluesdict[varname] = varvalue
#find differences and print them out!
try:
#for Pokemon
print "Index {}: {}".format(index, newvaluesdict["Name"])
except KeyError:
#for Stages
try:
print "Index {}: {}".format(index, newvaluesdict["Pokemon"])
except KeyError:
print "Index {}".format(index)
for key in newvaluesdict.keys():
try:
oldvalue = oldvaluesdict[key]
newvalue = newvaluesdict[key]
if oldvalue != newvalue:
print "{}: {} -> {}".format(key, oldvalue, newvalue)
except KeyError:
print "{}: (empty) -> {}".format(key, newvaluesdict[key])
#line breaks between entries
print