added pprint action
This commit is contained in:
parent
3ddd76fcce
commit
8cb421c6e4
1 changed files with 21 additions and 4 deletions
|
@ -14,8 +14,19 @@ Options:
|
||||||
-b <blocksize>, --block-size=<blocksize> size of block used when reading
|
-b <blocksize>, --block-size=<blocksize> size of block used when reading
|
||||||
file's content [default: 4096]
|
file's content [default: 4096]
|
||||||
-d <hashalg>, --digest-alg=<hashalg> secure hash algorithm [default: md5]
|
-d <hashalg>, --digest-alg=<hashalg> secure hash algorithm [default: md5]
|
||||||
-a <action>, --action=<action> action on duplicate files (print,
|
-a <action>, --action=<action> action on duplicate files (pprint,
|
||||||
remove, move) [default: print]
|
print, remove, move) [default: pprint]
|
||||||
|
-remove removes duplicate files except
|
||||||
|
first found
|
||||||
|
-move moves duplicate files to
|
||||||
|
duplicates driectory, except first
|
||||||
|
found
|
||||||
|
-print prints result directory where
|
||||||
|
keys are hash values and values are
|
||||||
|
list of duplicate file paths
|
||||||
|
-pprint prints sets of duplicate file
|
||||||
|
paths each in it's line where sets
|
||||||
|
are separated by blank newline
|
||||||
-m <directory>, --move=<directory> move duplicate files to directory
|
-m <directory>, --move=<directory> move duplicate files to directory
|
||||||
(used with move action)
|
(used with move action)
|
||||||
[default: ./dups]
|
[default: ./dups]
|
||||||
|
@ -136,10 +147,16 @@ def main():
|
||||||
print('Invalid block size "%s"' % args['--block-size'])
|
print('Invalid block size "%s"' % args['--block-size'])
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if action == 'print':
|
if action == 'print' or action == 'pprint':
|
||||||
dups = file_dups(topdirs, args['--digest-alg'], args['--block-size'])
|
dups = file_dups(topdirs, args['--digest-alg'], args['--block-size'])
|
||||||
spam = dict(dups)
|
spam = dict(dups)
|
||||||
if spam:
|
if spam:
|
||||||
|
if action == 'pprint':
|
||||||
|
for h, fpaths in _dict_iter_items(spam):
|
||||||
|
for path in fpaths:
|
||||||
|
print(path)
|
||||||
|
print('')
|
||||||
|
else:
|
||||||
print(json.dumps(spam, indent=4))
|
print(json.dumps(spam, indent=4))
|
||||||
elif action == 'move':
|
elif action == 'move':
|
||||||
mv_file_dups(topdirs, args['--digest-alg'], args['--block-size'],
|
mv_file_dups(topdirs, args['--digest-alg'], args['--block-size'],
|
||||||
|
|
Loading…
Reference in a new issue