1
|
|
|
from tqdm import tqdm |
2
|
|
|
|
3
|
|
|
from dirutility import DirPaths |
4
|
|
|
|
5
|
|
|
|
6
|
|
|
def unique(list1, list2): |
7
|
|
|
""" |
8
|
|
|
Get unique items in list1 that are not in list2 |
9
|
|
|
:return: Unique items only in list 1 |
10
|
|
|
""" |
11
|
|
|
set2 = set(list2) |
12
|
|
|
list1_unique = [x for x in tqdm(list1, desc='Unique', total=len(list1)) if x not in set2] |
13
|
|
|
return list1_unique |
14
|
|
|
|
15
|
|
|
|
16
|
|
|
def unique_venn(list1, list2): |
17
|
|
|
"""Get unique items that are only in list1 and only in list2""" |
18
|
|
|
return unique(list1, list2), unique(list2, list1) |
19
|
|
|
|
20
|
|
|
|
21
|
|
|
def compare_trees(dir1, dir2): |
22
|
|
|
"""Parse two directories and return lists of unique files""" |
23
|
|
|
paths1 = DirPaths(dir1).walk() |
24
|
|
|
paths2 = DirPaths(dir2).walk() |
25
|
|
|
return unique_venn(paths1, paths2) |
26
|
|
|
|
27
|
|
|
|
28
|
|
View Code Duplication |
def main(): |
|
|
|
|
29
|
|
|
from dirutility.gui import CompareTreesGUI |
30
|
|
|
params = CompareTreesGUI().sources |
31
|
|
|
src = params['source'] |
32
|
|
|
dir1_u, dir2_u = compare_trees(src['dir1'], src['dir2']) |
33
|
|
|
|
34
|
|
|
if params['save']: |
35
|
|
|
from databasetools import CSVExport, DictTools |
36
|
|
|
save = params['save'] |
37
|
|
|
if save['csv']: |
38
|
|
|
CSVExport(list(dir1_u), cols=['files'], file_path=save['directory'], file_name='dir1_unique') |
39
|
|
|
CSVExport(list(dir2_u), cols=['files'], file_path=save['directory'], file_name='dir2_unique') |
40
|
|
|
if save['json']: |
41
|
|
|
DictTools(save['directory'], 'dir1_unique').save(list(dir1_u)) |
42
|
|
|
DictTools(save['directory'], 'dir2_unique').save(list(dir2_u)) |
43
|
|
|
print('Done!') |
44
|
|
|
|
45
|
|
|
|
46
|
|
|
if __name__ == "__main__": |
47
|
|
|
main() |
48
|
|
|
|