-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch
executable file
·56 lines (41 loc) · 1.33 KB
/
search
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
#!/usr/bin/env python
import argparse
import glob
import os
import sys
def parse_args():
parser = argparse.ArgumentParser("search for jobdirs")
parser.add_argument("jobid", type=int, nargs="?")
parser.add_argument("-v", "--verbose", action="store_true")
return parser.parse_args()
def main():
args = parse_args()
if args.verbose:
print(f"searching for jobid: {args.jobid}")
slurm_launcher_root = os.environ["SLURM_LAUNCHER_ROOT"]
if args.verbose:
print(f"SLURM_LAUNCHER_ROOT: {slurm_launcher_root}")
files = sorted(glob.glob(os.path.join(slurm_launcher_root, "*", "*", "jobid")))
if args.verbose:
print(f"found {len(files)} jobs")
if args.verbose:
print("\nsearching...")
found = None
for path in files:
jid = int(open(path, "r").read())
if args.verbose:
print(jid, os.path.dirname(path))
if args.jobid and jid == args.jobid:
found = os.path.dirname(path)
if not args.verbose:
break
if args.verbose:
print("searching... done!\n")
if found is not None:
print(found)
print()
# fallback to printing slurm info
if (args.jobid is not None):
os.system(f"scontrol show jobid -dd {args.jobid}")
if __name__ == "__main__":
sys.exit(main())