forked from PeterJCLaw/srcomp-kiosk
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun-cmd
More file actions
executable file
·36 lines (27 loc) · 796 Bytes
/
run-cmd
File metadata and controls
executable file
·36 lines (27 loc) · 796 Bytes
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
#!/usr/bin/env python3
import argparse
import fnmatch
import subprocess
from pathlib import Path
def main(pattern, command):
names = (Path(__file__).parent / 'pi-names').read_text().splitlines(keepends=False)
if pattern:
names = fnmatch.filter(names, pattern)
for name in names:
print(f'--- {name} ---')
subprocess.run(['ssh', name, *command])
print()
def parse_args():
parser = argparse.ArgumentParser()
parser.add_argument(
'--pattern',
help="Run only on names which match this fnmatch pattern.",
)
parser.add_argument(
'command',
nargs=argparse.ONE_OR_MORE,
help="The command to run.",
)
return parser.parse_args()
if __name__ == '__main__':
main(**parse_args().__dict__)