-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclean_up.py
More file actions
executable file
·90 lines (75 loc) · 2.21 KB
/
clean_up.py
File metadata and controls
executable file
·90 lines (75 loc) · 2.21 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#!/usr/bin/env python
import subprocess
import shutil
import os
import pprint
def getLast():
run = subprocess.run(
"nextflow log | tail -n 1 | cut -f 3",
shell=True,
capture_output=True,
)
if not run.returncode:
return run.stdout.decode()
def logRun(run):
run = subprocess.run(
f"nextflow log {run}",
shell=True,
capture_output=True,
)
if not run.returncode:
return run.stdout.decode().splitlines()
def getOtherDirs():
run = subprocess.run(
"find ./work/ -maxdepth 2 -mindepth 2 -type d -exec readlink -f {} \\;",
shell=True,
capture_output=True,
)
if not run.returncode:
return run.stdout.decode().splitlines()
def getEmpty():
run = subprocess.run(
"find ./work/ -type d -empty -exec readlink -f {} \\;",
shell=True,
capture_output=True,
)
if not run.returncode:
return run.stdout.decode().splitlines()
def killWork(work_dirs):
for f in work_dirs:
if os.path.isdir(f):
print(f"Deleting {f}")
shutil.rmtree(f)
def cli():
last_run = getLast()
keep = logRun(last_run)
others = getOtherDirs()
while True:
ask = input(
"\n"
" What would you like to do? [V]iew last run name, [L]ist last "
"run paths, [C]lean up paths, [E]xit "
).lower()
if ask == "e":
break
elif ask == "v":
print(f"Last run: {last_run}")
elif ask == "l":
pprint.pprint(keep)
elif ask == "c":
confirm = input("Run nextflow clean? [Y/N] ").lower()
if confirm == "y":
subprocess.run(
f"nextflow clean -but {last_run.strip()} -f",
capture_output=True,
shell=True,
)
to_delete = set(others) - set(last_run)
print("The following work directories will be deleted")
pprint.pprint(to_delete)
confirm = input("Continue? [Y/N]").lower()
if confirm == "y":
killWork(to_delete)
killWork(getEmpty())
if __name__ == "__main__":
cli()