-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrun.py
executable file
·62 lines (45 loc) · 1.61 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
#!/usr/bin/env python3
import re
from argparse import ArgumentParser
from subprocess import Popen
RE_CMDLINE_APPEND = re.compile(r"-append '.+'")
def iter_lines(filename):
with open(filename, "r") as fh:
for line in fh:
if line.startswith("#"):
continue
yield line.strip().strip("\\")
def print_wrap(txt):
s = 0
for e in range(0, len(txt), 120):
e+=120
print("{}{}".format(txt[s:e], "" if e >= len(txt) else "\\"))
s = e
def main():
parser = ArgumentParser()
parser.add_argument("topology", help="The NUMA topology file to use")
parser.add_argument("--script", default="qemu.sh", help="The QEMU script to run")
parser.add_argument("--cmdline", default="", help="Extra cmdline arguments")
parser.add_argument("--gdb", default=False, action="store_true", help="Start GDB server")
args = parser.parse_args()
topology_file = args.topology
script_file = args.script
cmdline = args.cmdline
gdb = args.gdb
topology = " ".join(line for line in iter_lines(topology_file))
script_lines = []
for line in iter_lines(script_file):
if cmdline and RE_CMDLINE_APPEND.match(line):
# Index of last quote
idx = len(line) - 1 - line[::-1].find("'")
line = line[0:idx] + " {}'".format(cmdline)
script_lines.append(line)
if (gdb):
script_lines.append("-s -S")
script = " ".join(script_lines)
cmd = "{} {}".format(script, topology)
print_wrap(cmd)
with Popen(cmd, shell=True) as proc:
proc.wait()
if __name__ == "__main__":
main()