forked from FlagBrew/PKSM-Scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgenScripts.py
executable file
·63 lines (52 loc) · 1.88 KB
/
genScripts.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
#!/usr/bin/env python3
import shlex, PKSMScript, sys, glob, shutil, os
games = ["LGPE", "USUM", "SM", "ORAS", "XY", "B2W2", "BW", "HGSS", "PT", "DP"]
def main(args):
print("Generating scripts...")
shutil.rmtree("scripts", True)
shutil.rmtree("build", True)
os.mkdir("scripts")
if os.path.exists("src/universal"):
# shutil.copytree("src/universal", "scripts/universal")
cleanCScripts("src/universal")
for game in games:
generate(game)
if os.path.exists("src/" + game.lower()):
cleanCScripts("src/" + game.lower())
else:
os.mkdir("scripts/" + game.lower())
if os.path.exists("build"):
for f in os.listdir("build"):
shutil.move("build/" + f, "scripts/" + game.lower())
scriptFiles = glob.glob("*.pksm")
for pksmFile in scriptFiles:
shutil.move(pksmFile, "scripts/" + game.lower())
def generate(game):
with open(os.path.join("src", "scripts%s.txt" % game)) as pksmArgFile:
for line in pksmArgFile:
if not line.startswith('#'):
line.replace('\\', '/')
pksmArgs = PKSMScript.parser.parse_args(shlex.split(line))
PKSMScript.main(pksmArgs)
def cleanCScripts(folder):
os.mkdir(folder.replace("src/", "scripts/"))
for path, _, files in os.walk(folder):
for fullname in files:
data = ""
with open(os.path.join(path, fullname), 'r', encoding="UTF-8") as f:
data = f.read()
data = data.replace("\r\n", "\n")
# Get rid of all comments
commentIndex = data.find("/*")
while commentIndex != -1:
data = data[:commentIndex] + data[data.find("*/")+2:]
commentIndex = data.find("/*")
commentIndex = data.find("//")
while commentIndex != -1:
data = data[:commentIndex] + \
data[data[commentIndex+2:].find("\n")+1 + commentIndex+2:]
commentIndex = data.find("//")
with open(os.path.join(path.replace("src/", "scripts/"), fullname), 'w', encoding="UTF-8") as f:
f.write(data)
if __name__ == '__main__':
main(sys.argv)