!/usr/bin/python
coding=utf-8
from hashlib
from sys
from os
from fnmatch
CHUNK_SIZE=8192
def find_specific_files(root,patterns=['*'],exclude_dirs=[]):
pass
def get_chunk(filename):
with open(filename) as f:
while True:
chunk=f.read(CHUNK_SIZE)
if not chunk:
break
else:
yield chunk
def get_file_checksum(filename):
h=hashlib.md5()
for chunk in get_chunk(filename):
h.update(chunk)
return h.hexdigest()
def main():
sys.argv.append("")
directory=sys.argv[1]
if not os.path.isdir(directory)
raise SystemExit("{0} is not a directory".format(directory))
record={}
for item in find_specific_files(directory):
checksum=get_file_checksum(item)
if checksum in record:
print('find {0} vs {1}'.format(record[checksum],item))
else:
record[checksum]=item
if name=='main':
main()