Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorBenjamin Saller <bcsaller@objectrealms.net>2007-07-30 16:48:06 (GMT)
committer Benjamin Saller <bcsaller@objectrealms.net>2007-07-30 16:48:06 (GMT)
commitb56dfd73ba5aeae93c9375cf97452e80fbe66e84 (patch)
tree960a4f64a8491e120bccf26e436ad64349e94f81 /src
parentdfefc1f8623611f5ce2615a62679f349f7428f75 (diff)
wip on versioning
Diffstat (limited to 'src')
-rw-r--r--src/olpc/datastore/datastore.py40
-rw-r--r--src/olpc/datastore/deltastream.py45
2 files changed, 77 insertions, 8 deletions
diff --git a/src/olpc/datastore/datastore.py b/src/olpc/datastore/datastore.py
index 19342e2..9883da3 100644
--- a/src/olpc/datastore/datastore.py
+++ b/src/olpc/datastore/datastore.py
@@ -56,7 +56,6 @@ class DataStore(dbus.service.Object):
self.backends.append(backendClass)
## MountPoint API
- #@utils.sanitize_dbus
@dbus.service.method(DS_DBUS_INTERFACE,
in_signature="sa{sv}",
out_signature='s')
@@ -98,7 +97,6 @@ class DataStore(dbus.service.Object):
"""
return [mp.descriptor() for mp in self.mountpoints.itervalues()]
- #@utils.sanitize_dbus
@dbus.service.method(DS_DBUS_INTERFACE,
in_signature="s",
out_signature="")
@@ -184,7 +182,38 @@ class DataStore(dbus.service.Object):
return mp
# PUBLIC API
- #@utils.sanitize_dbus
+ @dbus.service.method(DS_DBUS_INTERFACE,
+ in_signature='a{sv}s',
+ out_signature='ss')
+ def checkin(self, props, filelike=None):
+ """Check in a new content object. When uid is included in the
+ properties this is considered an update to the content object
+ which automatically creates a new revision.
+
+ This method returns the uid and version id tuple.
+ """
+ mp = self._resolveMountpoint(props)
+ uid = props.get('uid')
+ if uid:
+ # this is an update operation
+
+ else:
+ # this is a create operation
+
+ return uid, vid
+
+
+ @dbus.service.method(DS_DBUS_INTERFACE,
+ in_signature='ss',
+ out_signature='a{sv}s')
+ def checkout(self, uid, vid=None):
+ """Check out a revision of a document. Returns the properties
+ of that version and a filename with the contents of that
+ version.
+ """
+ pass
+
+
@dbus.service.method(DS_DBUS_INTERFACE,
in_signature='a{sv}s',
out_signature='s')
@@ -234,7 +263,6 @@ class DataStore(dbus.service.Object):
return d, len(d)
- #@utils.sanitize_dbus
@dbus.service.method(DS_DBUS_INTERFACE,
in_signature='a{sv}',
out_signature='aa{sv}u')
@@ -369,7 +397,6 @@ class DataStore(dbus.service.Object):
continue
return c
- #@utils.sanitize_dbus
@dbus.service.method(DS_DBUS_INTERFACE,
in_signature='s',
out_signature='s')
@@ -380,7 +407,6 @@ class DataStore(dbus.service.Object):
except AttributeError: pass
return ''
- #@utils.sanitize_dbus
@dbus.service.method(DS_DBUS_INTERFACE,
in_signature='s',
out_signature='a{sv}')
@@ -407,7 +433,6 @@ class DataStore(dbus.service.Object):
return results
- #@utils.sanitize_dbus
@dbus.service.method(DS_DBUS_INTERFACE,
in_signature='sa{sv}s',
out_signature='')
@@ -426,7 +451,6 @@ class DataStore(dbus.service.Object):
@dbus.service.signal(DS_DBUS_INTERFACE, signature="s")
def Updated(self, uid): pass
- #@utils.sanitize_dbus
@dbus.service.method(DS_DBUS_INTERFACE,
in_signature='s',
out_signature='')
diff --git a/src/olpc/datastore/deltastream.py b/src/olpc/datastore/deltastream.py
new file mode 100644
index 0000000..f880a07
--- /dev/null
+++ b/src/olpc/datastore/deltastream.py
@@ -0,0 +1,45 @@
+"""
+deltastream
+~~~~~~~~~~~~~~~~~~~~
+A forward or backward stream of delta information used to manage file
+versions efficiently
+
+"""
+
+__author__ = 'Benjamin Saller <bcsaller@objectrealms.net>'
+__docformat__ = 'restructuredtext'
+__copyright__ = 'Copyright ObjectRealms, LLC, 2007'
+__license__ = 'The GNU Public License V2+'
+
+
+import bsdiff
+FULL = 1
+PATCH = 2
+
+class DeltaStream(object):
+ """Record and Reconstruct objects from a forward diff chain. When diff
+ size/distance from the original is over a threshold we record a
+ new version in its entirety
+ """
+
+ def _record(self, old_fn, new_fn):
+ od = open(old_fn, 'r').read()
+ nd = open(new_fn, 'r').read()
+
+ #XXX: This needs to be done more memory efficiently
+ patch = bsdiff.Patch(od, nd)
+ # XXX: again, memory inefficient
+ if len(str(patch)) < (len(nd) / 2.0):
+ # The patch is larger than some threshold, we want to
+ # record a new full version rather than a patch
+ return FULL, nd
+ else:
+ return PATCH, patch
+
+ def record(self, old_fn, new_fn):
+ mode, data = self._record(old_fn, new_fn)
+ if mode is FULL:
+ pass
+ elif mode is PATCH:
+ pass
+