diff options
author | Benjamin Saller <bcsaller@objectrealms.net> | 2007-07-22 19:34:49 (GMT) |
---|---|---|
committer | Benjamin Saller <bcsaller@objectrealms.net> | 2007-07-22 19:34:49 (GMT) |
commit | 00570bc517b6698af52eca2f27d115e4c3c16d0c (patch) | |
tree | fe628544adbf5f140c39b5f4ae3f7e74de9a9b1a /src | |
parent | 64b7f95ba456e4c2e00b9c866804b71435203e07 (diff) |
inplace files return themselves on request for filename
files should be created on demand and not just on a generic 'get' call
Diffstat (limited to 'src')
-rw-r--r-- | src/olpc/datastore/backingstore.py | 18 | ||||
-rw-r--r-- | src/olpc/datastore/model.py | 16 |
2 files changed, 28 insertions, 6 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): |