-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
genScripts.py
executable file
·69 lines (58 loc) · 2.13 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
64
65
66
67
68
69
#!/usr/bin/env python3
import shlex, PKSMScript, sys, glob, shutil, os
games = ["LGPE", "USUM", "SM", "ORAS", "XY", "B2W2", "BW", "HGSS", "PT", "DP", "RS", "E", "FRLG"]
def main(args):
print("Generating scripts...")
script_list = []
shutil.rmtree("scripts", True)
shutil.rmtree("build", True)
os.mkdir("scripts")
if os.path.exists("src/universal"):
# shutil.copytree("src/universal", "scripts/universal")
script_list.extend(cleanCScripts("src/universal"))
for game in games:
script_list.extend(generate(game))
if os.path.exists("src/" + game.lower()):
script_list.extend(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())
with open("script_list.txt", "w", encoding="UTF-8") as f:
f.write("\n".join(script_list))
def generate(game):
path = os.path.join("src", "scripts%s.txt" % game)
script_list = []
if os.path.exists(path):
with open(path, 'r', encoding="UTF-8") as pksmArgFile:
for line in pksmArgFile:
if not line.startswith('#'):
line.replace('\\', '/')
pksmArgs = PKSMScript.parser.parse_args(shlex.split(line))
PKSMScript.main(pksmArgs)
if pksmArgs.d:
script_list.append(f"{game.lower()}/{pksmArgs.d}/{pksmArgs.output}.pksm")
else:
script_list.append(f"{game.lower()}/{pksmArgs.output}.pksm")
return script_list
def cleanCScripts(folder):
os.mkdir(folder.replace("src/", "scripts/"))
scripts_list = []
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")
outpath = os.path.join(path.replace("src/", "scripts/"), fullname)
os.makedirs(name=os.path.dirname(outpath), exist_ok=True)
with open(outpath, 'w', encoding="UTF-8") as f:
f.write(data)
scripts_list.append(f"{path[4:]}/{fullname}")
return scripts_list
if __name__ == '__main__':
main(sys.argv)