-
Notifications
You must be signed in to change notification settings - Fork 1.5k
/
clean.py
28 lines (21 loc) · 847 Bytes
/
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
import os.path
import os
import shutil
class CleanTask:
def __init__(self, args, project):
self.args = args
self.project = project
def __is_project_path(self, path):
proj_path = os.path.abspath('.')
return not os.path.commonprefix(
[proj_path, os.path.abspath(path)]
) == proj_path
def __is_protected_path(self, path):
abs_path = os.path.abspath(path)
protected_paths = self.project['source-paths'] + self.project['test-paths'] + ['.']
protected_abs_paths = [os.path.abspath for p in protected_paths]
return abs_path in set(protected_abs_paths) or self.__is_project_path(abs_path)
def run(self):
for path in self.project['clean-targets']:
if not self.__is_protected_path(path):
shutil.rmtree(path, True)