-
Notifications
You must be signed in to change notification settings - Fork 0
/
cleanup.py
22 lines (20 loc) · 879 Bytes
/
cleanup.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import subprocess
import json
import os
base_dir = "/home/kurse/kurs00054/jo83xafu/issm-output"
res_dir = "RESULTS"
out_dir = "OUT"
if __name__ == "__main__":
jobids_to_keep = []
for result_dir in os.listdir(f"{base_dir}/{res_dir}"):
file_name = "-".join(result_dir.split("-")[:-1])
with open(f"{base_dir}/{res_dir}/{result_dir}/{file_name}.json", "r") as f:
jc = json.loads(f.read())
for job in jc["jobs"].keys():
jobids_to_keep.append(job)
for experiment in os.listdir(f"{base_dir}/{out_dir}"):
if not experiment.split(".", 1)[1] in jobids_to_keep:
print(f"Deleting {experiment}, it is not part of any result!")
subprocess.run(["bash", "-c", f"rm -r {base_dir}/{out_dir}/{experiment}"])
else:
print(f"{experiment} will be kept, it is part of an result!")