X-Git-Url: https://git.mdrn.pl/audio.git/blobdiff_plain/d64f05ea901ccb7e61eacd9a5579bb81138b193d..1afbdde3f6504b6e0505fd31a27c028ddc402f02:/apps/archive/utils.py?ds=sidebyside diff --git a/apps/archive/utils.py b/apps/archive/utils.py index 6e0a8d1..3e89a8b 100755 --- a/apps/archive/utils.py +++ b/apps/archive/utils.py @@ -1,4 +1,7 @@ from hashlib import sha1 +import os +import os.path +from django.core.files.storage import FileSystemStorage from django.core.files.uploadedfile import UploadedFile @@ -15,8 +18,27 @@ class ExistingFile(UploadedFile): pass +class OverwriteStorage(FileSystemStorage): + + def _save(self, name, content): + if self.exists(name): + self.delete(name) + return super(OverwriteStorage, self)._save(name, content) + + def get_available_name(self, name): + return name + + def sha1_file(f): sha = sha1() for piece in iter(lambda: f.read(1024*1024), ''): sha.update(piece) return sha.hexdigest() + + +def all_files(root_path): + root_len = len(root_path) + for path, dirs, files in os.walk(root_path): + for fname in files: + yield os.path.join(path, fname)[root_len:].lstrip('/') +