def file_hash(filename):
if not filename:
return None
def _get_full_path(path):
rel_source_path = path.lstrip("/")
if settings.STATIC_ROOT:
full_path = os.path.join(settings.STATIC_ROOT, rel_source_path)
if os.path.exists(full_path):
return full_path
try:
full_path = finders.find(rel_source_path)
except Exception:
full_path = None
return full_path
full_path = _get_full_path(filename)
return None if full_path is None \
else hashlib.md5(open(full_path, 'rb').read()).hexdigest()[:7]
评论列表
文章目录