Update directory_discrepancy.
This commit is contained in:
parent
af9ae8f5ac
commit
7cfa47b279
1 changed files with 56 additions and 13 deletions
|
@ -1,20 +1,63 @@
|
||||||
|
'''
|
||||||
|
directory_discrepancy
|
||||||
|
=====================
|
||||||
|
|
||||||
|
This program compares two directory and shows which files exist in each
|
||||||
|
directory that do not exist in the other.
|
||||||
|
|
||||||
|
> directory_discrepancy dir1 dir2
|
||||||
|
|
||||||
|
flags:
|
||||||
|
--recurse:
|
||||||
|
Also check subdirectories.
|
||||||
|
'''
|
||||||
import os
|
import os
|
||||||
|
import argparse
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
dir1 = sys.argv[1]
|
from voussoirkit import betterhelp
|
||||||
dir2 = sys.argv[2]
|
from voussoirkit import pathclass
|
||||||
|
from voussoirkit import operatornotify
|
||||||
|
from voussoirkit import spinal
|
||||||
|
from voussoirkit import vlogging
|
||||||
|
|
||||||
files1 = set(os.listdir(dir1))
|
log = vlogging.getLogger(__name__, 'directory_discrepancy')
|
||||||
files2 = set(os.listdir(dir2))
|
|
||||||
|
|
||||||
print(f'In "{dir1}" but not in "{dir2}":')
|
def helper(root, recurse):
|
||||||
print('=============================')
|
root = pathclass.Path(root)
|
||||||
for discrepancy in sorted(files1.difference(files2)):
|
walk = spinal.walk(root, recurse=recurse, yield_directories=True, yield_files=True)
|
||||||
print(discrepancy)
|
for path in walk:
|
||||||
|
relative = path.relative_to(root)
|
||||||
|
yield relative
|
||||||
|
|
||||||
print()
|
def directory_discrepancy_argparse(args):
|
||||||
|
files1 = set(helper(args.dir1, recurse=args.recurse))
|
||||||
|
files2 = set(helper(args.dir2, recurse=args.recurse))
|
||||||
|
|
||||||
print(f'In "{dir2}" but not in "{dir1}":')
|
print(f'In "{args.dir1}" but not in "{args.dir2}":')
|
||||||
print('=============================')
|
print('=============================')
|
||||||
for discrepancy in sorted(files2.difference(files1)):
|
for discrepancy in sorted(files1.difference(files2)):
|
||||||
print(discrepancy)
|
print(discrepancy)
|
||||||
|
|
||||||
|
print()
|
||||||
|
|
||||||
|
print(f'In "{args.dir2}" but not in "{args.dir1}":')
|
||||||
|
print('=============================')
|
||||||
|
for discrepancy in sorted(files2.difference(files1)):
|
||||||
|
print(discrepancy)
|
||||||
|
|
||||||
|
|
||||||
|
def main(argv):
|
||||||
|
argv = vlogging.set_level_by_argv(log, argv)
|
||||||
|
|
||||||
|
parser = argparse.ArgumentParser(description=__doc__)
|
||||||
|
|
||||||
|
parser.add_argument('dir1')
|
||||||
|
parser.add_argument('dir2')
|
||||||
|
parser.add_argument('--recurse', action='store_true')
|
||||||
|
parser.set_defaults(func=directory_discrepancy_argparse)
|
||||||
|
|
||||||
|
return betterhelp.single_main(argv, parser, __doc__)
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
raise SystemExit(main(sys.argv[1:]))
|
||||||
|
|
Loading…
Reference in a new issue