diff options
author | Benjamin Saller <bcsaller@objectrealms.net> | 2007-07-16 14:18:10 (GMT) |
---|---|---|
committer | Benjamin Saller <bcsaller@objectrealms.net> | 2007-07-16 14:18:10 (GMT) |
commit | 6df3576dcc93acafbb4d8d22dcd4ab284b64e412 (patch) | |
tree | 4020879ba0dd6aafcc8f775665742ad15e731432 /src | |
parent | d75494ee4695b2b8a08f8f18fe9abf53dcb6159c (diff) |
resolve keys through model
removed testutils.waitforindex
Diffstat (limited to 'src')
-rw-r--r-- | src/olpc/datastore/model.py | 31 | ||||
-rw-r--r-- | src/olpc/datastore/utils.py | 2 | ||||
-rw-r--r-- | src/olpc/datastore/xapianindex.py | 34 |
3 files changed, 39 insertions, 28 deletions
diff --git a/src/olpc/datastore/model.py b/src/olpc/datastore/model.py index 011c3f4..e3f9668 100644 --- a/src/olpc/datastore/model.py +++ b/src/olpc/datastore/model.py @@ -60,14 +60,16 @@ class Property(object): >>> b = Property(key, value, 'binary') """ def __init__(self, key, value, kind=None): - self.key = key - self._value = value + self.kind = kind if kind not in propertyTypes: warnings.warn("Unknown property type: %s on key %s" % \ (kind, key), RuntimeWarning) else: self._impl = propertyTypes[kind] + self.key = key + self.value = value + @classmethod def fromstring(cls, key, value=''): kind = 'string' @@ -105,6 +107,21 @@ class Model(object): m.fields = self.fields.copy() m.fieldnames = self.fieldnames[:] return m + + def fromstring(self, key, value): + """create a property from the key name by looking it up in the + model.""" + kind = None + if ':' in key: key, kind = key.split(':', 1) + + mkind = self.fields[key][1] + if kind and mkind: + if kind != mkind: raise ValueError("""Specified wire + encoding for property %s was %s, expected %s""" %(key, kind, mkind)) + kind = mkind + + return Property(key, value, kind) + def addField(self, key, kind, overrides=None): """ Add a field to the model. @@ -256,19 +273,13 @@ def decode_datetime(value): return datetime.datetime.fromtimestamp(float(value)).isoformat() def datedec(value, dateformat=DATEFORMAT): - ti = time.strptime(value, dateformat) - dt = datetime.datetime(*(ti[:-2])) - dt = dt.replace(microsecond=0) - return dt + return timeparse(value, DATEFORMAT) def dateenc(value, dateformat=DATEFORMAT): if isinstance(value, basestring): # XXX: there is an issue with microseconds not getting parsed - ti = time.strptime(value, dateformat) - value = datetime.datetime(*(ti[:-2])) + value = timeparse(value, DATEFORMAT) value = value.replace(microsecond=0) - # XXX: drop time for now, this is a xapian issue - value = value.date() return value.isoformat() diff --git a/src/olpc/datastore/utils.py b/src/olpc/datastore/utils.py index 5000cfb..2998298 100644 --- a/src/olpc/datastore/utils.py +++ b/src/olpc/datastore/utils.py @@ -122,7 +122,7 @@ def timeparse(t, format): microseconds in the time string. """ try: - return datetime.datetime(*time.strptime(t, format)[0:6]).time() + return datetime.datetime(*time.strptime(t, format)[0:6]) except ValueError, msg: if "%S" in format: msg = str(msg) diff --git a/src/olpc/datastore/xapianindex.py b/src/olpc/datastore/xapianindex.py index ac1fa82..1b27d79 100644 --- a/src/olpc/datastore/xapianindex.py +++ b/src/olpc/datastore/xapianindex.py @@ -235,7 +235,7 @@ class IndexManager(object): """ d = {} for k,v in props.iteritems(): - p = model.Property.fromstring(k, v) + p = self.datamodel.fromstring(k, v) d[p.key] = p return d @@ -244,6 +244,22 @@ class IndexManager(object): Props must contain the following: key -> Property() """ + # + # Version handling + # + # we implicitly create new versions of documents the version + # id should have been set by the higher level system + uid = props.pop('uid', None) + vid = props.pop('vid', None) + + if not uid: + uid = create_uid() + operation = CREATE + + if vid: vid = str(float(vid.value) + 1.0) + else: vid = "1.0" + + # Property mapping via model props = self._mapProperties(props) doc = secore.UnprocessedDocument() add = doc.fields.append @@ -259,22 +275,6 @@ class IndexManager(object): mimetype = mimetype and mimetype.value or 'text/plain' filestuff = (filename, mimetype) - # - # Version handling - # - # we implicitly create new versions of documents the version - # id should have been set by the higher level system - uid = props.pop('uid', None) - vid = props.pop('vid', None) - - if uid: uid = uid.value - else: - uid = create_uid() - operation = CREATE - - if vid: vid = str(float(vid.value) + 1.0) - else: vid = "1.0" - doc.id = uid add(secore.Field('vid', vid)) |