Пример #1
0
def getsum(path, method):
	f = open(path,"rb")
	progress = None
	size = stat(path).st_size
	if Globals.progress and size != 0:
		widgets = ["%s" % Console.trimstring(basename(path).encode("utf-8")), Percentage(), ' ', Bar(left="[", right="]"), ' ', ETA()]
		progress = ProgressBar(term_width=Globals.consolesize, widgets=widgets, maxval=size).start()
	#lol arbitrary 2MB
	try: h = Hash(f.read(2097152), method)
	except Exception as e: 
		LogUtil.printlog("Error: %s in %s" % (e, path))
		return
	if Globals.progress and progress: progress.update(f.tell())
	try: chunk = f.read(2097152)
	except Exception as e: 
		LogUtil.printlog("Error: %s in %s" % (e, path))
		return
	if Globals.progress and progress: progress.update(f.tell())
	while chunk:
		h.update(chunk)
		try: chunk = f.read(2097152)
		except Exception as e: 
			LogUtil.printlog("Error: %s in %s" % (e, path))
			return
		if Globals.progress and progress: progress.update(f.tell())
	f.close()
	#if Globals.progress: progress.finish()
	if Globals.progress: Console.clearline()
	return h.gibehex()