-
Notifications
You must be signed in to change notification settings - Fork 1
/
repo-cleaner.py
47 lines (36 loc) · 1.27 KB
/
repo-cleaner.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
46
47
from os.path import isdir
from os import listdir
from utils import get_latest_version, remove_unless_dry_run
import Constants
def check_and_clean(path):
files = listdir(path)
if contains_only_files(files, path):
return
directories = filter_out_nones(files)
latest_version = get_latest_version(directories)
if latest_version is None:
clean_recursively(path, directories)
elif len(directories) == 1:
return
else:
print('Update ' + path.split(Constants.M2_PATH)[1])
for directory_name in directories:
if latest_version in directory_name:
continue
print(directory_name + ' (Has newer version: ' + latest_version + ')')
remove_unless_dry_run(path, directory_name)
def contains_only_files(files, path):
only_files = True
for index, file in enumerate(files):
if isdir('/'.join([path, file])):
only_files = False
else:
files[index] = None
return only_files
def filter_out_nones(files):
return [d for d in files if d is not None]
def clean_recursively(path, directories):
for directory in directories:
check_and_clean('/'.join([path, directory]))
if __name__ == '__main__':
check_and_clean(Constants.M2_PATH)