more verbose hash check

This commit is contained in:
q
2016-12-21 20:57:05 +02:00
parent 7662a59a7e
commit 6b57aadf88

View File

@@ -17,6 +17,7 @@ MINSIZE=0
MIME=magic.open(magic.MAGIC_NONE)
#MIME=magic.open(magic.MAGIC_MIME)
MIME.load()
ANIM=['-','\\','|','/','-','_','_']
def setup_options():
parser=ArgumentParser(description="Maintains the list of images sqlite file")
@@ -106,7 +107,7 @@ def add_single(conn,filename,change=False,hash=None,minsize=0,fullfile=False):
fsize=os.path.getsize(filename)
mime=MIME.file(filename.encode('UTF-8'))
except IOError:
print("File not found. Bad link?")
print("File '%s' not found. Bad link?"%(filename,))
return
except UnicodeDecodeError:
mime="NA"
@@ -310,11 +311,16 @@ def get_folder_contents(db,path):
def get_md5(filename,fullfile=False):
''' returns content based hash, only first 50Mb is read, unless user wants the whole file '''
if fullfile:
block_size=2**20
anim_i=0
block_size=2**24
md5 = hashlib.md5()
with open(filename,'rb') as f:
for chunk in iter(lambda: f.read(block_size), b''):
sys.stdout.write('\r'+ANIM[anim_i])
sys.stdout.flush()
anim_i=(anim_i+1)%len(ANIM)
md5.update(chunk)
sys.stdout.write('\r')
return md5.hexdigest()
return hashlib.md5(open(filename,'rb').read(1024*1024*50)).hexdigest()