-
Notifications
You must be signed in to change notification settings - Fork 0
/
refactorTool.py
839 lines (588 loc) · 20.8 KB
/
refactorTool.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
import sys
import re
import os
import os.path
# Ok, this is kind of a mess, but it currently seems to work without major crashes or causing any
# invalid code output, at least as far as I have been able to check.
# (choices[\(\)\w,\- \"]+?\W)(120)(\W)
writeToFiles = False
def getFuncDict():
funcFind = re.compile(r"(if\s?\(eventNo\s?==\s?\d*?\))\W*\{\W*")
funcExtr = re.compile(r"if\s?\(eventNo\s?==\s?(\d*)\)\W*?{\W*(\w+).*?\(\);\W+(?:(?:return;))")
eventF = open("./includes/doEvent.as", "r")
eventS = eventF.read()
eventF.close()
#eventS = funcFind.sub(r"\1", eventS)
print "done"
#print eventS
res = funcExtr.findall(eventS)
res = dict(res)
for key, value in res.iteritems():
print key, value
#print funcExtr.search(eventS).groups()
#print funcExtr.search(eventS).group(0)
#print res
#Ok, now we have a eventNo <-> function name dictionary
return res
def cleanEventNumbers():
res = getFuncDict()
simpleCRe = re.compile(r"[ ]simpleChoices\([\w\"\ \,\?!]*?\);")
choicesRe = re.compile(r"choices\([\w\"\ \,\?!]*?\);")
doYesNoRe = re.compile(r"doYesNo\([\w\"\ \,\?!]*?\);")
doNextRe = re.compile(r"doNext\(\d*?\);")
searchREs = [simpleCRe, choicesRe, doYesNoRe, doNextRe]
filelist = os.listdir("./includes")
#print filelist
for filename in filelist:
if filename.endswith(".as") and not filename.find("doEvent")+1: #Iterate over all the .as files in ./includes, and skip the doEvent file
#print filename
with open(os.path.join("./includes", filename), "r") as fileH:
tmp = fileH.read()
# BRUTE FORCE IT. BECAUSE LAZY
tmpO = tmp
for repRe in searchREs:
#print repRe.pattern
insertionPoint = 0
while repRe.search(tmp[insertionPoint:]):
m = repRe.search(tmp[insertionPoint:])
start, length = m.start()+insertionPoint, len(m.group())
prefix, call, postfix = tmp[:start], tmp[start:start+length], tmp[start+length:]
oldCall = call
for key, value in res.iteritems():
if key in call:
#print key, value
call = call.replace(key, value)
if oldCall != call:
print "Old:", oldCall
print "New:", call
tmp = prefix+call+postfix
insertionPoint = start+length
if len(tmp)-len(tmpO) != 0:
print len(tmpO), len(tmp)
print "Length Delta", len(tmp)-len(tmpO)
if writeToFiles:
with open(os.path.join("./includes", filename), "w") as fileH:
tmp = fileH.write(tmp)
return res
#
def cleanStaleDoEventIfs(evNumDict = {}):
numExtr = re.compile(r"if\s?\(eventNo == (\d*)\)")
with open("./includes/doEvent.as", "r") as eventF:
eventS = eventF.read()
print "Cleaning doEvent If statements"
filelist = os.listdir("./includes")
files = {}
#Pull all the as files into memory.
for filename in filelist:
print "Loading", filename
if filename.endswith(".as") and not filename.find("doEvent")+1 and not filename.find("flagDefs")+1:
with open(os.path.join("./includes", filename), "r") as fileH:
tmp = fileH.read()
files[filename] = tmp
matches = numExtr.finditer(eventS)
print "event = ", matches
uses = {}
for match in matches:
num = match.group(1)
numUnused = True
for fName, fContents in files.iteritems():
if num in fContents:
if fName in uses:
uses[fName].append(num)
else:
uses[fName] = [num]
#print "num exists", num, " in ", fName
numUnused = False
break
if numUnused:
start, length = match.start(), len(match.group())
prefix, call, postfix = eventS[:start], eventS[start:start+length], eventS[start+length:]
#num = call.split()[-1].rstrip("\)")
print start, length, num
if (num in prefix) or (num in postfix):
#print "used elsewhere in doEvent.as"
pass
else:
#print "Entirely Unused!", num
call = call.replace("eventNo", " false ")
eventS = prefix+call+postfix
keyList = []
for key, value in uses.iteritems():
valueStr = ""
for num in value:
if num in evNumDict:
print "Have event number!"
valueStr += "%s (%s)," % (num, evNumDict[num])
else:
valueStr += "%s," % (num)
valueStr = valueStr.rstrip(", ")
keyList.append("%s = %s" % (key, valueStr))
keyList.sort()
for item in keyList:
print item
if writeToFiles:
with open("./includes/doEvent.as", "w") as eventF:
eventF.write(eventS)
def removeDisabledDoEventIfs():
disabledIfExtr = re.compile(r"(?://[\w\-\s]*\s*)*(?:else)?\s+if\s?\(\s*false\s* == \d+\)\s+\{[\w\s\(\)\;/]+\}")
emptyIfExtr = re.compile(r"(?://[\w\-\s]*\s*)*(?:else)?\s+if\s?\(\s*(?:(?:false)|(?:eventNo))\s* == \d+\)\s+\{\W+return;\W+\}")
with open("./includes/doEvent.as", "r") as eventF:
eventS = eventF.read()
print "Cleaning doEvent If statements"
eventS = disabledIfExtr.sub("", eventS)
if writeToFiles:
with open("./includes/doEvent.as", "w") as eventF:
eventF.write(eventS)
def getFlagDict():
with open("FlagDictionary.txt", "r") as fd:
lines = fd.readlines()
ret = {}
for line in lines:
num, desc = line.split("=", 1)
desc = desc.split("/")[-1]
num = num.rstrip().lstrip()
desc = desc.rstrip().lstrip()
ret[int(num)] = desc
return ret
def cleanFlags():
with open("flagDefsNamed.as", "r") as fA:
good = fA.readlines()
maxLen = 0
targetLen = 70
out = {}
flagDict = getFlagDict()
for line in good:
if "=" and ";" in line:
prefix, postfix = line.split("=", 1)
prefix = prefix.rstrip().lstrip()
postfix = postfix.rstrip().lstrip()
num_s, comment = postfix.split(";")
comment = comment.split("/")[-1]
if maxLen < len(prefix):
maxLen = len(prefix)
num_i = int(num_s)
tmp = prefix + " "*(targetLen - len(prefix))
tmp += "=" + " "*(5-len(num_s)) + num_s + "; // " + comment
if num_i in flagDict:
if not flagDict[num_i] in tmp:
tmp += flagDict[num_i]
else:
print "In tmp already = ", flagDict[num_i]
out[num_i] = tmp
else:
if line.rstrip().lstrip() != "":
print "Wut:", line
print "done"
print maxLen
outL = []
for x in range(3000):
if x in out:
outL.append(out[x])
else:
prefix = "const UNKNOWN_FLAG_NUMBER_%05d:int" % x
tmp = prefix + " "*(targetLen - len(prefix))
tmp += "=" + " "*(5-len(str(x))) + str(x) + ";"
if x in flagDict:
tmp += " // %s" % flagDict[x]
outL.append(tmp)
with open("flagDefs.as", "w") as outF:
for x in outL:
#print x
outF.write("%s\n" % x)
#for key, value in out.iteritems():
# print key, value
def insertFlags():
with open("flagDefs.as", "r") as flagsF:
lines = flagsF.readlines()
flags = {}
for line in lines:
prefix, postfix = line.split("=", 1)
prefix = prefix.rstrip().lstrip().split()[-1].split(":")[0]
postfix = postfix.rstrip().lstrip().split(";")[0]
print postfix, prefix
flags[postfix] = prefix
#Ok, now we have a eventNo <-> event number macro
flagRE = re.compile(r"flags\[(\d*?)\]")
filelist = os.listdir("./includes")
print filelist
flagNum = 0
for filename in filelist:
if filename.endswith(".as"): #Iterate over all the .as files in ./includes, and skip the doEvent file
with open(os.path.join("./includes", filename), "r") as fileH:
tmp = fileH.read()
# BRUTE FORCE IT. BECAUSE LAZY
tmpO = tmp
insertionPoint = 0
while flagRE.search(tmp[insertionPoint:]):
m = flagRE.search(tmp[insertionPoint:])
start, length = m.start(1)+insertionPoint, len(m.group(1))
# print m.group(), m.group(1)
insertionPoint = start+length
flagNum += 1
prefix, call, postfix = tmp[:start], tmp[start:start+length], tmp[start+length:]
oldCall = call
call = call.replace(call, flags[call])
# if oldCall != call:
# print "Old:", oldCall
# print "New:", call
tmp = prefix+call+postfix
if len(tmp)-len(tmpO) != 0:
print filename
print len(tmpO), len(tmp)
print "Length Delta", len(tmp)-len(tmpO)
if writeToFiles:
with open(os.path.join("./includes", filename), "w") as fileH:
tmp = fileH.write(tmp)
'''
insertionPoint = start+length
print len(tmpO), len(tmp)
print "Length Delta", len(tmp)-len(tmpO)
'''
print "Total Integer flag indices:", flagNum
def functionYoink():
funcs = {}
flagRE = re.compile(r"function ([\w]*?)\(")
filelist = os.listdir("./includes")
print filelist
flagNum = 0
for filename in filelist:
if filename.endswith(".as"): #Iterate over all the .as files in ./includes, and skip the doEvent file
with open(os.path.join("./includes", filename), "r") as fileH:
tmp = fileH.read()
print "Functions in file %s:" % filename
for item in flagRE.findall(tmp):
print " %s" % item
nameLen = len(item)
if nameLen in funcs:
funcs[nameLen].append(item)
else:
funcs[nameLen] = [item]
for x in range(250):
if x in funcs:
print "Name length = ", x
for name in funcs[x]:
print " %s" % name
# Woot! More recursion! I'm on a fucking roll!
def refactorIfs(inStr):
# I feel dirty even having written this regex
ifExtr = re.compile(r"((\[if\W?\(\W?\w+\W?[><=!]+\W?\w+\W?\)\W*?\\\"[\w \[\].,]+?\\\")(\W?else\W?)?(\\\"[\w \[\].,]+?\\\")?\])")
retStr = ""
match = ifExtr.search(inStr)
if match:
start, length = match.start(), len(match.group(0))
print "Match start", start, "Length", length
prefix, call, postfix = inStr[:start], inStr[start:start+length], inStr[start+length:]
#print "Call = ", call
#print "Matches = ", match.groups()
newText = ""
newText += match.group(2).replace(r"\"", "")
if match.group(4):
# print match.groups()
# print match.group(2), match.group(4)
print "IF ELSE"
newText += "|"
newText += match.group(4).replace(r"\"", "")
newText += "]"
print call
print newText
retStr = prefix
retStr += newText
retStr += refactorIfs(postfix)
else:
retStr = inStr
# searched = ifExtr.findall(inStr)
# if searched:
# for item in searched:
# print item
return retStr
def modifyParserIfStatements():
filelist = os.listdir("./includes")
for filename in filelist:
if filename.endswith(".as"): #Iterate over all the .as files in ./includes
with open(os.path.join("./includes", filename), "r") as fileH:
tmp = fileH.read()
print "filename:", filename, "------------------------------------------------"
cleaned = refactorIfs(tmp)
if cleaned != tmp:
print "Changes!"
with open(os.path.join("./includes", filename), "w") as fileH:
fileH.write(cleaned)
def cleanAddButtons():
funcFind = re.compile(r"(if\(eventNo == \d*?\) )\{\W*")
funcExtr = re.compile(r"if\s?\(eventNo == (\d*)\)\W*?{\W*(\w+).*?\(\)")
eventF = open("./includes/doEvent.as", "r")
eventS = eventF.read()
eventF.close()
eventS = funcFind.sub(r"\1", eventS)
print "done"
#print eventS
res = funcExtr.findall(eventS)
res = dict(res)
print res
#Ok, now we have a eventNo <-> function name dictionary
buttonRE = re.compile(r"((?:addButton)|(?:anotherButton))\((\w+?),\s?(\"[\"\\A-Za-z0-9]+?\"),\s?eventParser,\s?(\d+?)\)")
searchREs = [buttonRE]
filelist = os.listdir("./includes")
print filelist
for filename in filelist:
if filename.endswith(".as") and not filename.find("doEvent")+1: #Iterate over all the .as files in ./includes, and skip the doEvent file
print filename
with open(os.path.join("./includes", filename), "r") as fileH:
tmp = fileH.read()
# BRUTE FORCE IT. BECAUSE LAZY
tmpO = tmp
for repRe in searchREs:
#print repRe.pattern
insertionPoint = 0
while repRe.search(tmp[insertionPoint:]):
m = repRe.search(tmp[insertionPoint:])
start, length = m.start()+insertionPoint, len(m.group())
prefix, call, postfix = tmp[:start], tmp[start:start+length], tmp[start+length:]
oldCall = call
for key, value in res.iteritems():
if key in call:
key = "eventParser,%s" % key
print key, value
call = call.replace(key, value)
if oldCall != call:
print "Old:", oldCall
print "New:", call
tmp = prefix+call+postfix
insertionPoint = start+length
if len(tmp)-len(tmpO) != 0:
print len(tmpO), len(tmp)
print "Length Delta", len(tmp)-len(tmpO)
#with open(os.path.join("./includes", filename), "w") as fileH:
# tmp = fileH.write(tmp)
def cleanupChoiceSection(inStr):
cleanRE1 = re.compile(r"(?:rando|choice) = rand\(\d\);")
cleanRE2 = re.compile(r"(?:else )?(?:if\((?:rando|choice) == \d\) )?descript \+?= ")
cleanRE3 = re.compile(r"[\t\r\n]*")
cleaners = [cleanRE1, cleanRE2, cleanRE3]
#print "Old - ", inStr
new = inStr
for regex in cleaners:
new = regex.sub("", new)
new = new.replace(";", ", ")
new = new.rstrip(", ")
new = "descript += randomChoice(%s);" % new
print "New = ", new
return new
def cleanupRandomChoices():
randomCleanupRE = re.compile(r"((?:rando|choice) = rand\((\d)\);(?:\s+(?:else )?(?:if\((?:rando|choice) == \d\) )?descript \+?= \"[a-zA-Z- ]+\";)+)")
with open("./includes/descriptors.as", "r") as eventF:
eventS = eventF.read()
inStr = eventS
print "Cleaning descriptors If statements"
match = randomCleanupRE.search(inStr)
outStr = ""
matchStr = ""
while match:
print match.start(), match.end()
matches = match.groups()
print int(matches[1]) == matches[0].count("\n"), int(matches[1]), matches[0].count("\n")
start, end = match.start(), match.end()
outStr += inStr[:start]
if int(matches[1]) == matches[0].count("\n"):
print "Replacing!"
outStr += cleanupChoiceSection(inStr[start:end])
else:
outStr += inStr[start:end]
print inStr[start:end]
inStr = inStr[end:]
match = randomCleanupRE.search(inStr)
if not match:
outStr += inStr
#eventS = disabledIfExtr.sub("", eventS)
print len(eventS) == len(outStr), len(eventS), len(outStr)
if writeToFiles:
with open("./includes/descriptors.as", "w") as eventF:
eventF.write(outStr)
def findFunctionsWithoutExit():
filelist = os.listdir("./includes")
print filelist
for filename in filelist:
if filename.endswith(".as") and "latex" in filename:
print filename
with open(os.path.join("./includes", filename), "r") as fileH:
tmp = fileH.read()
funcs = tmp.split("function")
for func in funcs:
if not ("addButton" in func or "doNext" in func):
print "No Buttons!"
print func
def pronouninate():
filelist = ["arian.as", "rubi.as"]
repDict = {
re.compile(r"\"\s?\+\s?arianMF\(\"He\",\"She\"\)\s?\+\s?\"") : "[Arian Ey]",
re.compile(r"\"\s?\+\s?arianMF\(\"he\",\"she\"\)\s?\+\s?\"") : "[Arian ey]",
re.compile(r"\"\s?\+\s?arianMF\(\"him\",\"her\"\)\s?\+\s?\"") : "[Arian em]",
re.compile(r"\"\s?\+\s?arianMF\(\"himself\",\"herself\"\)\s?\+\s?\"") : "[Arian emself]",
re.compile(r"\"\s?\+\s?arianMF\(\"His\",\"Her\"\)\s?\+\s?\"") : "[Arian Eir]",
re.compile(r"\"\s?\+\s?arianMF\(\"his\",\"her\"\)\s?\+\s?\"") : "[Arian eir]",
re.compile(r"\"\s?\+\s?arianMF\(\"His\",\"Hers\"\)\s?\+\s?\"") : "[Arian Eirs]",
re.compile(r"\"\s?\+\s?arianMF\(\"his\",\"hers\"\)\s?\+\s?\"") : "[Arian eirs]",
re.compile(r"\"\s?\+\s?arianMF\(\"man\",\"woman\"\)\s?\+\s?\"") : "[Arian man]",
re.compile(r"\"\s?\+\s?rubiMF\(\"he\",\"she\"\)\s?\+\s?\"") : "[rubi ey]",
re.compile(r"\"\s?\+\s?rubiMF\(\"He\",\"She\"\)\s?\+\s?\"") : "[rubi Ey]",
re.compile(r"\"\s?\+\s?rubiMF\(\"him\",\"her\"\)\s?\+\s?\"") : "[rubi em]",
re.compile(r"\"\s?\+\s?rubiMF\(\"himself\",\"herself\"\)\s?\+\s?\"") : "[rubi emself]",
re.compile(r"\"\s?\+\s?rubiMF\(\"his\",\"her\"\)\s?\+\s?\"") : "[rubi eir]",
re.compile(r"\"\s?\+\s?rubiMF\(\"His\",\"Her\"\)\s?\+\s?\"") : "[rubi Eir]",
re.compile(r"\"\s?\+\s?rubiMF\(\"man\",\"woman\"\)\s?\+\s?\"") : "[rubi man]"
}
print repDict
for filename in filelist:
if filename.endswith(".as"): #Iterate over all the .as files in ./includes
with open(os.path.join("./includes", filename), "r") as fileH:
tmp = fileH.read()
print "filename:", filename, "------------------------------------------------"
cleaned = tmp
for regex, replacement in repDict.iteritems():
results = set()
print regex, replacement
for item in regex.findall(tmp):
results.add(item)
#print item
#for item in results:
# print item
cleaned = regex.sub(replacement, cleaned)
if cleaned != tmp:
print "Changes!"
if writeToFiles:
print "Writing File!"
with open(os.path.join("./includes", filename), "w") as fileH:
fileH.write(cleaned)
def parseDefLine(line):
prefix, postfix = line.split("=", 1)
prefix = prefix.rstrip().lstrip().split()[-1].split(":")[0]
postfix = postfix.rstrip().lstrip().split(";")[0]
print postfix, prefix
return postfix, prefix
def insertDescripts():
with open("./includes/flagDefs.as", "r") as flagsF:
content = flagsF.read()
prefix, content = content.split("// Description constants")
content, postfix = content.split("// End Description constants")
#lines = flagsF.readlines()
#print content
sections = content.split("//")
#print sections
descriptoSection = {}
for item in sections:
item = item.rstrip().lstrip()
lines = item.split("\n")
sectionKey = lines[0]
if sectionKey != "":
sectionKey = "\.%s\s?(?:==|=|!=|<|>|<=|>=)\s?(\d+)" % sectionKey
print "sectionKey", sectionKey
descriptoSection[sectionKey] = {}
for line in lines[1:]:
key, value = parseDefLine(line)
descriptoSection[sectionKey][key] = value
print descriptoSection
filename = "appearance.as"
for key, value in descriptoSection.iteritems():
print key, value
#sys.exit()
#Ok, now we have a eventNo <-> event number macro
#print flags
#flagRE = re.compile(r"flags\[(\d*?)\]")
filelist = os.listdir("./includes")
print filelist
flagNum = 0
for filename in filelist:
if filename.endswith(".as") and filename != "flagDefs.as": #Iterate over all the .as files in ./includes, and skip the doEvent file
print "Processing file ", filename, " --------------------------------------------------------------"
with open(os.path.join("./includes", filename), "r") as fileH:
tmp = fileH.read()
# BRUTE FORCE IT. BECAUSE LAZY
tmpO = tmp
for reStr, lookupDict in descriptoSection.iteritems():
#print reStr, lookupDict
insertionPoint = 0
curRe = re.compile(reStr)
print "Re pattern = ", curRe.pattern
while tmp != None and curRe.search(tmp):
m = curRe.search(tmp[insertionPoint:])
start, length = m.start(1)+insertionPoint, len(m.group(1))
#print m.group(), m.group(1)
insertionPoint = start+length
prefix, call, postfix = tmp[:start], tmp[start:start+length], tmp[start+length:]
#print call, " replacement = ", lookupDict[call]
oldCall = call
call = call.replace(call, lookupDict[call])
if oldCall != call:
print "Old:", oldCall
print "New:", call
tmp = prefix+call+postfix
if len(tmp)-len(tmpO) != 0:
print filename
print len(tmpO), len(tmp)
print "Length Delta", len(tmp)-len(tmpO)
if writeToFiles:
with open(os.path.join("./includes", filename), "w") as fileH:
tmp = fileH.write(tmp)
'''
insertionPoint = start+length
print len(tmpO), len(tmp)
print "Length Delta", len(tmp)-len(tmpO)
'''
print "Total Integer flag indices:", flagNum
def updateFlagNames():
import flagRefactor
changeList = flagRefactor.getChangedFlags()
if not changeList:
print "You have no changes in flagRefactor.py!"
print "Exiting early because there are no changes to be made"
return
filelist = os.listdir("./includes")
print filelist
flagNum = 0
for filename in filelist:
if filename.endswith(".as"): #Iterate over all the .as files in ./includes, and skip the doEvent file
print "Processing file ", filename, " --------------------------------------------------------------"
with open(os.path.join("./includes", filename), "r") as fileH:
tmp = fileH.read()
tmpO = tmp
for oldVal, newVal in changeList:
tmp = tmp.replace(oldVal, newVal)
if len(tmp)-len(tmpO) != 0:
print filename
print len(tmpO), len(tmp)
print "Length Delta", len(tmp)-len(tmpO)
if writeToFiles:
with open(os.path.join("./includes", filename), "w") as fileH:
tmp = fileH.write(tmp)
# finally, clean out the changes from the script so we'll not try to replace them again in the future.
with open("flagRefactor.py", "r") as fileH:
tmp = fileH.read()
tmpO = tmp
for oldVal, newVal in changeList:
tmp = tmp.replace(oldVal, newVal)
if writeToFiles:
with open("flagRefactor.py", "w") as fileH:
tmp = fileH.write(tmp)
if __name__ == "__main__":
print "OMG WE'S BREAKIN STUF!!111one!"
if len(sys.argv) > 1:
if "--writeFiles" in sys.argv:
print "This run will write to files!"
writeToFiles = True
#cleanEventNumbers()
#cleanStaleDoEventIfs(getFuncDict())
#removeDisabledDoEventIfs()
#cleanFlags()
#insertFlags()
#functionYoink()
#modifyParserIfStatements()
#cleanAddButtons()
#cleanupRandomChoices()
#findFunctionsWithoutExit()
#pronouninate()
#insertDescripts()
updateFlagNames()
if not writeToFiles:
print "Did not write files because"
print "--writeFiles not specified"
print "Complete"