-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtestPython.py
80 lines (64 loc) · 2.71 KB
/
testPython.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
import os
import sys
import shutil
import re
import fileUtils
inputFolder = sys.argv[1]
def capitalize(input):
parts = input.split('_')
capitalizedParts = []
for part in parts:
capitalizedParts.append(part[0].upper() + part[1:])
return ''.join(capitalizedParts)
def toFileName(baseName, suffix):
fileName = 'K'
fileName += baseName
fileName += suffix
return fileName
class FileChanger(fileUtils.FileChanger):
def __init__(self, snakeCaseName, capitalizedName):
self.snakeCaseName = snakeCaseName
self.capitalizedName = capitalizedName
def changeContents(self, contents):
snakeCaseName = self.snakeCaseName
capitalizedName = self.capitalizedName
if snakeCaseName in ['camera_switch_event', 'studio_switch_event']:
contents = re.sub(r'KTimelineFlatPainter', 'KTimelineCirclePainter', contents)
contents = re.sub(r'DAYARC', capitalizedName.upper(), contents)
contents = re.sub(r'day_arc', snakeCaseName, contents)
contents = re.sub(r'DAY_ARC', snakeCaseName.upper(), contents)
contents = re.sub(r'DayArc', capitalizedName, contents)
camelCaseName = capitalizedName[0].lower() + capitalizedName[1:]
contents = re.sub(r'dayArc', camelCaseName, contents)
return contents
suffixes = []
for _, _, filenames in os.walk(os.path.join(inputFolder, 'day_arc')):
for filename in filenames:
if filename.endswith('.cc'):
suffixes.append(filename[7:-3])
else:
suffixes.append(filename[7:-2])
suffixes = set(suffixes)
def fillDirectory(dirname):
for suffix in suffixes:
snakeCaseName = 'day_arc'
animationName = capitalize(snakeCaseName)
baseName = toFileName(animationName, suffix)
inputHeader = os.path.join(inputFolder, snakeCaseName, baseName + '.h')
inputImpl = os.path.join(inputFolder, snakeCaseName, baseName + '.cc')
animationName = capitalize(dirname)
baseName = toFileName(animationName, suffix)
headerPath = os.path.join(inputFolder, dirname, baseName + '.h')
implPath = os.path.join(inputFolder, dirname, baseName + '.cc')
shutil.copyfile(inputHeader, headerPath)
shutil.copyfile(inputImpl, implPath)
fileChanger = FileChanger(dirname, animationName)
fileChanger.run(headerPath)
fileChanger = FileChanger(dirname, animationName)
fileChanger.run(implPath)
print(' animation/types/' + dirname + '/' + baseName + '.h')
print(' animation/types/' + dirname + '/' + baseName + '.cc')
for _, dirnames, filenames in os.walk(inputFolder):
for dirname in dirnames:
if dirname != 'day_arc':
fillDirectory(dirname)