-
Notifications
You must be signed in to change notification settings - Fork 1
/
directory_discrepancy.py
57 lines (46 loc) · 1.61 KB
/
directory_discrepancy.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
48
49
50
51
52
53
54
55
56
57
import argparse
import sys
from voussoirkit import betterhelp
from voussoirkit import pathclass
from voussoirkit import niceprints
from voussoirkit import spinal
from voussoirkit import vlogging
log = vlogging.getLogger(__name__, 'directory_discrepancy')
def helper(root, recurse):
root = pathclass.Path(root)
walk = spinal.walk(root, recurse=recurse, yield_directories=True, yield_files=True)
for path in walk:
relative = path.relative_to(root)
yield relative
def directory_discrepancy_argparse(args):
files1 = set(helper(args.dir1, recurse=args.recurse))
files2 = set(helper(args.dir2, recurse=args.recurse))
print(niceprints.equals_header(f'In "{args.dir1}" but not in "{args.dir2}"'))
for discrepancy in sorted(files1.difference(files2)):
print(discrepancy)
print()
print(niceprints.equals_header(f'In "{args.dir2}" but not in "{args.dir1}"'))
for discrepancy in sorted(files2.difference(files1)):
print(discrepancy)
return 0
@vlogging.main_decorator
def main(argv):
parser = argparse.ArgumentParser(
description='''
This program compares two directory and shows which files exist in each
directory that do not exist in the other.
''',
)
parser.add_argument('dir1')
parser.add_argument('dir2')
parser.add_argument(
'--recurse',
action='store_true',
help='''
Also check subdirectories.
''',
)
parser.set_defaults(func=directory_discrepancy_argparse)
return betterhelp.go(parser, argv)
if __name__ == '__main__':
raise SystemExit(main(sys.argv[1:]))