1 from hashlib import sha1
4 from django.core.files.storage import FileSystemStorage
5 from django.core.files.uploadedfile import UploadedFile
8 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):
23 def _save(self, name, content):
26 return super(OverwriteStorage, self)._save(name, content)
28 def get_available_name(self, name, max_length):
34 for piece in iter(lambda: f.read(1024*1024), ''):
36 return sha.hexdigest()
39 def all_files(root_path):
40 root_len = len(root_path)
41 for path, dirs, files in os.walk(root_path):
43 yield os.path.join(path, fname)[root_len:].lstrip('/')