-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathevil
executable file
·193 lines (153 loc) · 5.08 KB
/
evil
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
#!/usr/bin/env python3
from os import path
from posixpath import normpath
from re import split, findall
from argparse import ArgumentParser, FileType, REMAINDER
from random import choice
from sys import argv
from copy import copy
import logging
from modules import hellparser
from modules.fetcher import Fetcher
from modules.execute import execute
def readArgumentFile(file):
textfile = file.read()
file.close()
return textfile
# Pattern matching magic
def flatten(xss):
return [x for xs in xss for x in xs]
def parseArgs():
quitMessage = [
"Please don't leave, there's more demons to toast!",
"Let's beat it -- This is turning into a bloodbath!",
"You're trying to say you like DOS better than me, right?",
"I wouldn't leave if I were you. DOS is much worse.",
]
with open("version.txt") as f:
version = f.read()
argParser = ArgumentParser(
prog=argv[0],
description="The most evil launcher ever conceived",
epilog=choice(quitMessage),
usage="%(prog)s [evil options] filename [options to pass to gzdoom]",
)
argParser.add_argument(
"filename", action="store", type=FileType("r"), help="Path to hell file"
)
argParser.add_argument(
"--dry-run", action="store_true", help="Don't do anything, only display"
)
argParser.add_argument(
"--remove-temp",
action="store_true",
help="Remove downloaded temporary files, possibly unsafe.",
)
argParser.add_argument(
"-v",
"--version",
action="version",
help="Display version and exit",
version=f"Evil v{version}",
)
argParser.add_argument(
"-n", "--no-launch", action="store_true", help="Only fetch, do not run `gzdoom`"
)
argParser.add_argument("extraFlags", nargs=REMAINDER)
loggingArg = argParser.add_mutually_exclusive_group()
loggingArg.add_argument(
"--log", action="store_true", help="Write log file (evil.log)"
)
loggingArg.add_argument(
"-V", "--verbose", action="store_true", help="Write log file (evil.log)"
)
return argParser.parse_args()
def main():
arguments = parseArgs()
arguments.filetext = readArgumentFile(arguments.filename)
## Logging
if arguments.log:
logging.basicConfig(
format="[%(levelname)s] :: %(message)s",
filename="evil.log",
filemode="w",
level=logging.DEBUG,
)
elif arguments.verbose:
logging.basicConfig(
format="[%(levelname)s] :: %(message)s",
level=logging.DEBUG,
)
else:
logging.basicConfig(
format="[%(levelname)s] :: %(message)s",
level=logging.WARN,
)
logging.info(f"The command was: `{' '.join(argv)}`")
file = arguments.filetext
cleanFile = hellparser.clean("[]{}", file)
filePath = hellparser.getFilepath(arguments.filename.name)
lines = split("\n", file)
cleanLines = split("\n", cleanFile)
comments = hellparser.getComments(lines)
noComments = copy(lines)
for comment in comments:
for line in cleanLines:
if line == comment:
noComments.remove(line)
noComments = hellparser.sanitize(comments, noComments)
# Find wad and config file
wad = findall(r"\[.+\]", file)[0]
config = findall(r"\{.+\}", file)
if config:
config = config[0]
else:
config = ""
Fetcher().fetchMissing(
cleanLine=cleanLines,
outPath=filePath,
dryRun=arguments.dry_run,
removeTemp=arguments.remove_temp,
)
# Clean the strings
lines = hellparser.flatASS(lines)
file = "\n".join(lines)
mods = hellparser.getMods([wad, config], noComments)
cleanMods = []
for mod in mods:
cleanMods.append(hellparser.parseURL(mod))
mods = hellparser.listToString(cleanMods, filePath)
mods = hellparser.clean("%", mods)
wad = findall(r"\[.+\]", file)[0]
# Clean from `[]` and `%`
wad = hellparser.clean("[]%", wad)
config = findall(r"\{.+\}", file)
if config:
config = hellparser.clean("{}%", config[0])
configCommand = f' -config "{filePath}/{config}"'
else:
configCommand = ""
fileName = arguments.filename.name
logging.info("The hell file is at " f"`{fileName}`")
if wad:
logging.info(f"The wad is `{wad}`")
else:
logging.error(f"WAD not found at {filePath}/{wad}, perhaps a malformed file?")
exit()
if config:
logging.info(f"The config file is `{normpath(config)}`")
if mods:
logging.info(f"The mods are `{mods}`")
modCommand = f" -file {mods}"
else:
modCommand = ""
extraFlags = " " + " ".join(arguments.extraFlags)
command = f'gzdoom -iwad "{path.join(filePath, path.normpath(wad))}"{configCommand}{modCommand}{extraFlags}'
logging.info(
f"""The command {"would" if arguments.dry_run else "will"} be run as
`{command}`
"""
)
if not arguments.dry_run and not arguments.no_launch:
execute(command)
main()