-
Notifications
You must be signed in to change notification settings - Fork 13
/
RunCLI.py
140 lines (101 loc) · 2.7 KB
/
RunCLI.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
import os
import sys
from RunGUI import ItemRandomiser
def runCLI(arguments):
arg_error = False
if "input" not in arguments:
print("No --input or -i provided.", file=sys.stderr)
arg_error = True
if "output" not in arguments:
print("No --output or -o provided.", file=sys.stderr)
arg_error = True
if "mode" not in arguments:
print("No --mode or -m provided.", file=sys.stderr)
arg_error = True
if "race" in arguments and "log" in arguments:
print("Cannot use race mode and spoiler log.", file=sys.stderr)
arg_error = True
use_seed = None
if "seed" in arguments:
use_seed = arguments["seed"]
if "race" in arguments :
if type(arguments["race"]) is not bool:
race_mode = arguments["race"]
else:
race_mode = None
else:
race_mode = None
if arg_error:
return
#app = QApplication(sys.argv)
#form = RunWindow()
# Need to load settings, etc.
item_rando = ItemRandomiser(GUI=None)
if race_mode is None:
settingsFile = arguments["mode"]
item_rando.loadSettings(settingsFile)
rom_md5 = None
else:
data = item_rando.LoadRaceModeSettings(raceString=race_mode)
use_seed = data[2]
rom_md5 = data[3]
flags = {"Spoiler" : "log" in arguments, "RaceMode": "race" in arguments}
print(flags, arguments)
item_rando.runRandomizer(in_file=arguments["input"], out_file=arguments["output"],
seed=use_seed, run_flags=flags, requiredMD5=rom_md5)
#form.romPath = arguments["input"]
#form.runRandomizer(cli=True, outputFile=arguments["output"])
if arg_error:
return
def convertArgument(argument):
if argument == "i":
return "input"
if argument == "o":
return "output"
if argument == "m":
return "mode"
if argument == "s":
return "seed"
if argument == "l":
return "log"
if argument == "r":
return "race"
return argument
def parseArguments():
parsed_args = {}
read_next_arg = 0
for argument in sys.argv:
if os.getcwd() in argument:
continue
if read_next_arg > 0 and argument.startswith("-"):
arg_name = convertArgument(arg_name)
parsed_args[arg_name] = True
if argument.startswith("--"):
arg_name = argument[2:]
read_next_arg = 2
pass
elif argument.startswith("-"):
arg_name = argument[1:]
read_next_arg = 1
pass
elif read_next_arg > 0:
if read_next_arg == 1:
arg_name = convertArgument(arg_name)
parsed_args[arg_name] = argument
read_next_arg = 0
else:
parsed_args[argument] = True
if read_next_arg == 2:
parsed_args[arg_name] = True
elif read_next_arg == 1:
parsed_args [convertArgument(arg_name)] = True
return parsed_args
def main():
arguments = parseArguments()
if "cli" in arguments:
runCLI(arguments)
return
else:
print("cli argument must be provided.")
if __name__ == '__main__':
main()