-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathclear.py
45 lines (34 loc) · 1.06 KB
/
clear.py
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
import argparse
import os
import random
import torch
import os
import misc_utils as utils
def parse_args():
# experiment specifics
parser = argparse.ArgumentParser()
parser.add_argument('tag', type=str, default='cache', nargs='?',
help='folder name to clear')
parser.add_argument('--rm', action='store_true', help='debug mode')
return parser.parse_args()
opt = parse_args()
paths = ['checkpoints', 'logs', 'results']
if opt.tag.startswith('logs/'):
opt.tag = opt.tag[5:]
if opt.rm:
for path in paths:
p = os.path.join(path, opt.tag)
if os.path.isdir(p):
command = 'rm -r ' + p
print(command)
os.system(command)
else:
for path in paths:
tmp = os.path.join('_.trash', utils.get_time_stamp(), path)
utils.try_make_dir(tmp)
p = os.path.join(path, opt.tag)
if os.path.isdir(p):
command = 'mv %s %s' % (p, tmp)
print(command)
os.system(command)
utils.color_print("Directory '%s' cleared." % opt.tag, 1)