generate_static_names: Fix case where no base specified.

This commit is contained in:
Neil Williams
2011-10-23 00:30:44 -07:00
parent 4d2c3c2835
commit 034e1f151b

View File

@@ -6,13 +6,17 @@ import json
import base64
import shutil
def generate_static_name(name, base=None, shorthash=None):
def generate_static_name(name, base=None):
"""Generate a unique filename.
Unique filenames are generated by base 64 encoding the first 64 bits of
the SHA1 hash. This hash string is added to the filename before the extension.
"""
if base: path = os.path.join(base, name)
if base:
path = os.path.join(base, name)
else:
path = name
sha = hashlib.sha1(open(path).read()).digest()
shorthash = base64.urlsafe_b64encode(sha[0:8]).rstrip("=")
name, ext = os.path.splitext(name)