-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
executable file
·65 lines (52 loc) · 1.74 KB
/
run.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
#!/usr/bin/env python3
import argparse
import subprocess
from os import environ as env
import os
parser = argparse.ArgumentParser(
prog="weath3rb0i",
description="The weath3rb0i binary executor",
epilog="Run `cargo run` for the default",
)
binaries_path = os.path.join(os.path.dirname(__file__), './src/bin/')
binaries = os.listdir(binaries_path)
binaries.sort()
binaries.insert(0, 'weath3rb0i')
# Add all parameters globally but only use the ones we require per binary (no checks for extra args)
parser.add_argument("bin", nargs="?", help="Which binary (by id) to run")
parser.add_argument(
"-r", "--release", action="store_true", help="Whether to compile in release mode"
)
parser.add_argument("-q", "--quiet", action="store_true", help="Hide compiler info")
parser.add_argument("--hsize", type=int, help="Max code length for Huffman tree")
args = parser.parse_args()
if args.bin in binaries:
args.bin = binaries.index(args.bin)
else:
try:
args.bin = int(args.bin) if args.bin is not None else None
except ValueError:
args.bin = None
while args.bin is None or args.bin >= len(binaries):
for i, binary in enumerate(binaries[1:]):
print(f"{i+1}) {binary}")
try:
selected_binary = input("Select binary to run: ")
if selected_binary in binaries:
args.bin = binaries.index(selected_binary)
else:
args.bin = int(selected_binary)
except ValueError:
continue
binary = binaries[args.bin]
cmd = ["cargo", "run"]
if args.quiet:
cmd.append("--quiet")
if args.release:
cmd.append("--release")
cmd.extend(["--bin", binary, "--"])
if "FILE" in env:
cmd.append(env["FILE"])
if "DEBUG" in env:
print('(dbg) Command:', cmd)
subprocess.run(cmd)