|
|
|
import hashlib
|
|
import os
|
|
|
|
def getMD5Hash(file, block_size=2**20):
|
|
f = open(file)
|
|
md5 = hashlib.md5()
|
|
while True:
|
|
data = f.read(block_size)
|
|
if not data:
|
|
break
|
|
md5.update(data)
|
|
md5Hash = md5.hexdigest()
|
|
return md5Hash
|
|
|
|
|
|
def getFileName(file):
|
|
basename = os.path.basename(file)
|
|
filename = os.path.splitext(basename)
|
|
return filename[0]
|
|
|
|
|
|
def getMimeType(path):
|
|
if path.endswith(".iso"):
|
|
return "application/x-iso9660-image"
|
|
elif path.endswith(".md5"):
|
|
return "text/plain"
|