Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomeu Vizoso <tomeu@tomeuvizoso.net>2008-10-22 15:19:12 (GMT)
committer Tomeu Vizoso <tomeu@tomeuvizoso.net>2008-10-22 15:19:12 (GMT)
commitb69646ef143afbaebb97bba3c41d9789959ea6bb (patch)
treef0f943ca0d7ef9be8e801f952b0e0131172ba50d
parentd17026bd22db5d8b2a924ec2e19ea8e4a5adcd09 (diff)
#8867: add an extension to the retrieved files
-rw-r--r--src/olpc/datastore/datastore.py11
-rw-r--r--src/olpc/datastore/filestore.py12
2 files changed, 19 insertions, 4 deletions
diff --git a/src/olpc/datastore/datastore.py b/src/olpc/datastore/datastore.py
index 8186960..6bef90c 100644
--- a/src/olpc/datastore/datastore.py
+++ b/src/olpc/datastore/datastore.py
@@ -23,6 +23,8 @@ import os
import dbus
import gobject
+from sugar import mime
+
from olpc.datastore import layoutmanager
from olpc.datastore import migration
from olpc.datastore.layoutmanager import MAX_QUERY_LIMIT
@@ -215,7 +217,14 @@ class DataStore(dbus.service.Object):
sender_keyword='sender')
def get_filename(self, uid, sender=None):
user_id = dbus.Bus().get_unix_user(sender)
- return self._file_store.retrieve(uid, user_id)
+ extension = self._get_extension(uid)
+ return self._file_store.retrieve(uid, user_id, extension)
+
+ def _get_extension(self, uid):
+ mime_type = self._metadata_store.get_property(uid, 'mime_type')
+ if mime_type is None or not mime_type:
+ return ''
+ return mime.get_primary_extension(mime_type)
@dbus.service.method(DS_DBUS_INTERFACE,
in_signature='s',
diff --git a/src/olpc/datastore/filestore.py b/src/olpc/datastore/filestore.py
index a567175..8c170bc 100644
--- a/src/olpc/datastore/filestore.py
+++ b/src/olpc/datastore/filestore.py
@@ -71,7 +71,7 @@ class FileStore(object):
async_copy = AsyncCopy(file_path, destination_path, completion_cb)
async_copy.start()
- def retrieve(self, uid, user_id):
+ def retrieve(self, uid, user_id, extension):
"""Place the file associated to a given entry into a directory where the
user can read it. The caller is reponsible for deleting this file.
@@ -95,18 +95,24 @@ class FileStore(object):
if not os.path.exists(destination_dir):
os.makedirs(destination_dir)
- destination_path = os.path.join(destination_dir, uid)
+ if extension is None:
+ extension = ''
+ elif extension:
+ extension = '.' + extension
+
+ destination_path = os.path.join(destination_dir, uid + extension)
attempt = 1
while os.path.exists(destination_path):
if attempt > 10:
fd, destination_path = tempfile.mkstemp(prefix=uid,
+ suffix=extension,
dir=destination_dir)
del fd
os.unlink(destination_path)
break
else:
- file_name = '%s_%s' % (uid, attempt)
+ file_name = '%s_%s%s' % (uid, attempt, extension)
destination_path = os.path.join(destination_dir, file_name)
attempt += 1