|
|
|
@ -30,14 +30,10 @@ import syslog
|
|
|
|
|
import tempfile
|
|
|
|
|
|
|
|
|
|
try:
|
|
|
|
|
import hashlib
|
|
|
|
|
HAVE_HASHLIB=True
|
|
|
|
|
except ImportError:
|
|
|
|
|
import md5
|
|
|
|
|
HAVE_HASHLIB=False
|
|
|
|
|
from hashlib import md5 as _md5
|
|
|
|
|
except ImportError:
|
|
|
|
|
from md5 import md5 as _md5
|
|
|
|
|
|
|
|
|
|
# Since hashlib is only available in 2.5 and onwards, this module
|
|
|
|
|
# uses md5 which is available in 2.4.
|
|
|
|
|
|
|
|
|
|
# ===========================================
|
|
|
|
|
# Support methods
|
|
|
|
@ -66,13 +62,18 @@ def write_temp_file(data):
|
|
|
|
|
return path
|
|
|
|
|
|
|
|
|
|
def md5(filename):
|
|
|
|
|
''' compute md5sum, return None if file is not present '''
|
|
|
|
|
if not os.path.exists(filename):
|
|
|
|
|
return None
|
|
|
|
|
if HAVE_HASHLIB:
|
|
|
|
|
return hashlib.md5(file(filename).read()).hexdigest()
|
|
|
|
|
else:
|
|
|
|
|
return md5.new(file(filename).read()).hexdigest()
|
|
|
|
|
''' Return MD5 hex digest of local file, or None if file is not present. '''
|
|
|
|
|
if not os.path.exists(filename):
|
|
|
|
|
return None
|
|
|
|
|
digest = _md5()
|
|
|
|
|
blocksize = 64 * 1024
|
|
|
|
|
infile = open(filename, 'rb')
|
|
|
|
|
block = infile.read(blocksize)
|
|
|
|
|
while block:
|
|
|
|
|
digest.update(block)
|
|
|
|
|
block = infile.read(blocksize)
|
|
|
|
|
infile.close()
|
|
|
|
|
return digest.hexdigest()
|
|
|
|
|
|
|
|
|
|
# ===========================================
|
|
|
|
|
|
|
|
|
|