-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathclean.py
37 lines (33 loc) · 1.11 KB
/
clean.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
import sys
import os
import shutil
build_paths = [
os.path.join(sys.path[0], 'build/bind/'),
os.path.join(sys.path[0], 'build/hosts/'),
os.path.join(sys.path[0], 'build/pihole/'),
os.path.join(sys.path[0], 'build/dnsmasq/'),
os.path.join(sys.path[0], 'build/pdns/'),
os.path.join(sys.path[0], 'build/mikrotik/'),
]
tmp_paths = [
os.path.join(sys.path[0], 'tmp/blacklist/'),
os.path.join(sys.path[0], 'tmp/whitelist/'),
]
def cleanPaths(paths):
for build in paths:
build_dir_list = os.listdir(build)
for file in build_dir_list:
full_path = build + file
try:
if os.path.isfile(full_path) or os.path.isdir(full_path):
if file != '.gitignore':
os.unlink(full_path)
elif os.path.isdir(full_path):
shutil.rmtree(full_path)
except Exception as e:
raise SystemError('Failed to delete %s. Reason: %s' % (full_path, e))
## FLUSH
print('CLEANUP build dir ...')
cleanPaths(paths=build_paths)
print('CLEANUP tmp dir ...')
cleanPaths(paths=tmp_paths)