From: Guillaume Pellerin Date: Sun, 10 Nov 2013 08:58:48 +0000 (+0100) Subject: check upload tmp_dir existence X-Git-Tag: 1.5.0rc3~42 X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=843360d6f8e55421acb18d2573092e9f50863684;p=telemeta.git check upload tmp_dir existence --- diff --git a/example/sandbox/settings.py b/example/sandbox/settings.py index 0a380300..fe913c79 100644 --- a/example/sandbox/settings.py +++ b/example/sandbox/settings.py @@ -161,3 +161,5 @@ LOGIN_REDIRECT_URL = reverse_lazy('telemeta-desk-lists') EMAIL_HOST = 'localhost' DEFAULT_FROM_EMAIL = 'webmaster@parisson.com' + +FILE_UPLOAD_TEMP_DIR = '/tmp' \ No newline at end of file diff --git a/telemeta/backup/core.py b/telemeta/backup/core.py index 9c1e1c08..395d7909 100644 --- a/telemeta/backup/core.py +++ b/telemeta/backup/core.py @@ -56,14 +56,14 @@ class CollectionSerializer(object): if len(buffer) == 0: break hash.update(buffer) - file.close() + file.close() return hash.hexdigest() def __get_media_filename(self, item): return str(item.id) + ".wav" def store(self, dest_dir): - """Serialize and store the collection with related items and media + """Serialize and store the collection with related items and media files into a subdirectory of the provided directory """ coll_dir = dest_dir + "/" + str(self.collection.id) @@ -89,7 +89,7 @@ class CollectionSerializer(object): md5_file.close() def get_xml(self): - """Return a string containing the XML representation of the collection + """Return a string containing the XML representation of the collection and related items """ impl = getDOMImplementation() @@ -117,5 +117,5 @@ class CollectionSerializer(object): tree.free() return xml - + diff --git a/telemeta/views/collection.py b/telemeta/views/collection.py index c02b8e41..c40ccb12 100644 --- a/telemeta/views/collection.py +++ b/telemeta/views/collection.py @@ -178,7 +178,10 @@ class CollectionPackageView(View): import json collection = self.get_object() - temp = tempfile.TemporaryFile(prefix=settings.FILE_UPLOAD_TEMP_DIR+os.sep) + tmp_dir = getattr(settings, "FILE_UPLOAD_TEMP_DIR") + if not tmp_dir: + tmp_dir = '/tmp' + temp = tempfile.TemporaryFile(prefix=tmp_dir+os.sep) archive = zipfile.ZipFile(temp, 'w', zipfile.ZIP_DEFLATED, allowZip64=True) serializer = CollectionSerializer(collection) archive.writestr('%s/%s%s' % (collection.code, collection.code, '.xml'),