-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlaunch.py
More file actions
executable file
·48 lines (40 loc) · 1.28 KB
/
launch.py
File metadata and controls
executable file
·48 lines (40 loc) · 1.28 KB
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
#!/usr/bin/env python3
import subprocess
import sys
from argparse import ArgumentParser, ArgumentDefaultsHelpFormatter
def sh(command):
if isinstance(command, str):
command = command.split()
print(*command)
out = subprocess.run(
command, stdout=subprocess.PIPE, stderr=sys.stderr, encoding='utf-8'
)
return out.stdout
def main(count: int, app: str):
for i in range(count):
sh(f'mkfifo /tmp/netchat-fifo-{i}')
for i in range(count):
j = (i + 1) % count
sh(
[
'x-terminal-emulator',
'-e',
app.format(IN=f"/tmp/netchat-fifo-{i}", OUT=f"/tmp/netchat-fifo-{j}"),
]
)
if __name__ == '__main__':
p = ArgumentParser(
description="Generate a network named pipes (FIFO files) and launch the applications.",
formatter_class=ArgumentDefaultsHelpFormatter,
)
p.add_argument(
'count', type=int, help="The number of nodes in the network (must be >= 2)"
)
p.add_argument(
'--app',
default="cargo run -- --input {IN} --output {OUT}",
help="The application to be launched",
)
args = p.parse_args()
assert args.count >= 2, "The number of nodes must be >= 2"
main(args.count, args.app)