1 from hashlib import sha1
5 from django.core.files.storage import FileSystemStorage
6 from django.core.files.uploadedfile import UploadedFile
9 class ExistingFile(UploadedFile):
10 def __init__(self, path, *args, **kwargs):
12 return super(ExistingFile, self).__init__(*args, **kwargs)
14 def temporary_file_path(self):
21 class OverwriteStorage(FileSystemStorage):
22 def _save(self, name, content):
25 return super(OverwriteStorage, self)._save(name, content)
27 def get_available_name(self, name, max_length):
33 for piece in iter(lambda: f.read(1024 * 1024), b""):
35 return sha.hexdigest()
38 def all_files(root_path):
39 root_len = len(root_path)
40 for path, dirs, files in os.walk(root_path, followlinks=True):
42 if '\n' in fname: continue
43 yield os.path.join(path, fname)[root_len:].lstrip("/")