Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Saller <bcsaller@objectrealms.net>2007-07-22 19:34:49 (GMT)
committer Benjamin Saller <bcsaller@objectrealms.net>2007-07-22 19:34:49 (GMT)
commit00570bc517b6698af52eca2f27d115e4c3c16d0c (patch)
treefe628544adbf5f140c39b5f4ae3f7e74de9a9b1a
parent64b7f95ba456e4c2e00b9c866804b71435203e07 (diff)
inplace files return themselves on request for filename
files should be created on demand and not just on a generic 'get' call
-rw-r--r--src/olpc/datastore/backingstore.py18
-rw-r--r--src/olpc/datastore/model.py16
-rw-r--r--tests/mountpoints.txt18
3 files changed, 45 insertions, 7 deletions
diff --git a/src/olpc/datastore/backingstore.py b/src/olpc/datastore/backingstore.py
index 13ec2ee..5aede54 100644
--- a/src/olpc/datastore/backingstore.py
+++ b/src/olpc/datastore/backingstore.py
@@ -340,13 +340,13 @@ class FileBackingStore(BackingStore):
self._writeContent(uid, filelike, replace=False)
return uid
- def get(self, uid, env=None, allowMissing=False):
+ def get(self, uid, env=None, allowMissing=False, includeFile=False):
content = self.indexmanager.get(uid)
if not content: raise KeyError(uid)
path = self._translatePath(uid)
fp = None
# not all content objects have a file
- if os.path.exists(path):
+ if includeFile and os.path.exists(path):
fp = open(path, 'r')
# now return a Content object from the model associated with
# this file object
@@ -478,7 +478,18 @@ class InplaceFileBackingStore(FileBackingStore):
self.update(uid, metadata, source)
self.indexmanager.flush()
return
-
+
+ def _translatePath(self, uid):
+ try: content = self.indexmanager.get(uid)
+ except KeyError: return None
+ return os.path.join(self.uri, content.get_property('filename'))
+
+ def _targetFile(self, uid, target=None, ext=None, env=None):
+ # in this case the file should really be there unless it was
+ # deleted in place or something which we typically isn't allowed
+ targetpath = self._translatePath(uid)
+ return open(targetpath, 'rw')
+
# File Management API
def create(self, props, filelike):
# the file would have already been changed inplace
@@ -508,7 +519,6 @@ class InplaceFileBackingStore(FileBackingStore):
self.walker.join()
self.indexmanager.stop()
-
def complete_indexing(self):
if self.walker and self.walker.isAlive():
self.walker.join()
diff --git a/src/olpc/datastore/model.py b/src/olpc/datastore/model.py
index 46f2225..4c592be 100644
--- a/src/olpc/datastore/model.py
+++ b/src/olpc/datastore/model.py
@@ -167,6 +167,10 @@ class Model(object):
args = self.fields[fn]
addField(args[0], **args[2])
+
+# Properties we don't automatically include in properties dict
+EXCLUDED_PROPERTIES = ['fulltext', ]
+
class Content(object):
"""A light weight proxy around Xapian Documents from secore.
This provides additional methods which are used in the
@@ -199,6 +203,8 @@ class Content(object):
def properties(self):
d = {}
for k, v in self.data.iteritems():
+ if k in EXCLUDED_PROPERTIES: continue
+
if isinstance(v, list) and len(v) == 1:
v = v[0]
field = self._model.fields.get(k)
@@ -238,8 +244,14 @@ class Content(object):
return None, None
def get_file(self):
- if not hasattr(self, "_file") or self._file.closed is True:
- self.backingstore.get(self.id)
+ if not hasattr(self, "_file") or not self._file or \
+ self._file.closed is True:
+ target, ext = self.suggestName()
+ try:
+ targetfile = self.backingstore._targetFile(self.id, target, ext)
+ self._file = targetfile
+ except OSError:
+ self._file = None
return self._file
def set_file(self, fileobj):
diff --git a/tests/mountpoints.txt b/tests/mountpoints.txt
index 2146c71..c1f4619 100644
--- a/tests/mountpoints.txt
+++ b/tests/mountpoints.txt
@@ -137,7 +137,23 @@ Verify that we can get the properties of objects on the inplace
stores.
>>> uid = result[0]['uid']
->>> assert ds.get_properties(uid)['title'] == "doc4"
+>>> props = ds.get_properties(uid)
+>>> assert props['title'] == "doc4"
+
+
+Currently sugar defines doing a copy as zeroing out the uid and
+changing the mountpoint. Lets copy an object from mp3 to mp1, the
+primary store.
+>>> props['mountpoint'] = mountpoint
+>>> fn = ds.get_filename(uid)
+
+>>> copyuid = ds.create(props, fn)
+
+>>> ds.complete_indexing()
+
+>>> result, count = ds.find(dict(fulltext="four"))
+>>> assert count == 2
+
>>> ds.stop(); del ds