Add function to generate MD5 digest
This will allow appengine nodes to verify the source has been
copied correctly.
@@ -5,12 +5,14 @@ import hashlib
import random
import string
+
def random_password_generator():
""" Generates a random six character password with letters and digits. """
characters = string.letters + string.digits
pwd_size = constants.PASSWORD_SIZE
return ''.join((random.choice(characters)) for x in range(pwd_size))
+
def encrypt_password(username, password):
"""Salts the given password with the provided username and encrypts it.
@@ -22,3 +24,22 @@ def encrypt_password(username, password):
The SHA1-encrypted password.
"""
return hashlib.sha1(username + password).hexdigest()
+
+
+def get_md5(location):
+ """ Get a file's MD5 checksum.
+
+ Args:
+ location: A string specifying the location of the file to check.
+ Returns:
+ A string containing the checksum with hexidecimal encoding.
+ """
+ md5 = hashlib.md5()
+ chunk_size = 64 * 1024
+ with open(location, 'rb') as source:
+ chunk = source.read(chunk_size)
+ while len(chunk) > 0:
+ md5.update(chunk)
+ chunk = source.read(chunk_size)
+
+ return md5.hexdigest()
