-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclear_working_dir.py
More file actions
executable file
·53 lines (49 loc) · 1.74 KB
/
clear_working_dir.py
File metadata and controls
executable file
·53 lines (49 loc) · 1.74 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
import shutil
import sys
import os
# This script deletes the working directories of Browntotate-1.2.0/runs and Browntotate-1.2.0/Brownaming-1.0.0/runs except for
# the directory names specified in the command
# python clear_working_dir.py <directory name to excluse>
def prompt_user(dir, delete_all=False):
parent = os.path.abspath(os.path.dirname(dir))
if delete_all:
return True
response = input(f"\nDo you want to delete the directory {os.path.abspath(dir)}? [y] \n 'y' for yes\n 'n' for no\n 'a' for all: you accept to delete all directories in {parent}\n").strip().lower()
if response == 'a':
return 'a'
elif response == 'y' or response == '':
return True
elif response == 'n':
return False
else:
return prompt_user(dir)
delete_all_remaining = False
for dir in os.listdir("Brownaming-1.0.0/runs"):
dir_path = os.path.join("Brownaming-1.0.0/runs", dir)
if os.path.isdir(dir_path) and dir not in sys.argv:
if delete_all_remaining:
shutil.rmtree(dir_path)
print(f"Deleted directory: {dir}")
prompt = prompt_user(dir_path)
if prompt == 'a':
delete_all_remaining = True
shutil.rmtree(dir_path)
print(f"Deleted directory: {dir}")
elif prompt:
shutil.rmtree(dir_path)
print(f"Deleted directory: {dir}")
delete_all_remaining = False
for dir in os.listdir("runs"):
dir_path = os.path.join("runs", dir)
if os.path.isdir(dir_path) and dir not in sys.argv:
if delete_all_remaining:
shutil.rmtree(dir_path)
print(f"Deleted directory: {dir}")
prompt = prompt_user(dir_path)
if prompt == 'a':
delete_all_remaining = True
shutil.rmtree(dir_path)
print(f"Deleted directory: {dir}")
elif prompt:
shutil.rmtree(dir_path)
print(f"Deleted directory: {dir}")