summaryrefslogtreecommitdiff
path: root/src/leap/soledad/backends/openstack.py
diff options
context:
space:
mode:
authordrebs <drebs@leap.se>2012-12-10 12:05:31 -0200
committerdrebs <drebs@leap.se>2012-12-10 12:05:31 -0200
commitb3090f710e3777bad2a9f996444e5099883c9f03 (patch)
treeb129323e5277ac2fc854f8f58a408dc092e6c128 /src/leap/soledad/backends/openstack.py
parentf89f2e0fe490899ecc4baf3395f3441111da328f (diff)
Add CouchDB u1db backend.
Diffstat (limited to 'src/leap/soledad/backends/openstack.py')
-rw-r--r--src/leap/soledad/backends/openstack.py20
1 files changed, 5 insertions, 15 deletions
diff --git a/src/leap/soledad/backends/openstack.py b/src/leap/soledad/backends/openstack.py
index f8563d81..5f2a2771 100644
--- a/src/leap/soledad/backends/openstack.py
+++ b/src/leap/soledad/backends/openstack.py
@@ -1,5 +1,4 @@
from u1db import errors
-from u1db.backends import CommonBackend
from u1db.remote.http_target import HTTPSyncTarget
from swiftclient import client
from soledad.backends.objectstore import ObjectStore
@@ -10,16 +9,15 @@ class OpenStackDatabase(ObjectStore):
def __init__(self, auth_url, user, auth_key, container):
"""Create a new OpenStack data container."""
- super(OpenStackDatabase, self)
self._auth_url = auth_url
self._user = user
self._auth_key = auth_key
self._container = container
- self.set_document_factory(LeapDocument)
self._connection = swiftclient.Connection(self._auth_url, self._user,
self._auth_key)
self._get_auth()
- self._ensure_u1db_data()
+ # this will ensure transaction and sync logs exist and are up-to-date.
+ super(OpenStackDatabase, self)
#-------------------------------------------------------------------------
# implemented methods from Database
@@ -33,6 +31,7 @@ class OpenStackDatabase(ObjectStore):
"""
try:
response, contents = self._connection.get_object(self._container, doc_id)
+ # TODO: change revision to be a dictionary element?
rev = response['x-object-meta-rev']
return self._factory(doc_id, rev, contents)
except swiftclient.ClientException:
@@ -51,21 +50,12 @@ class OpenStackDatabase(ObjectStore):
results.append(doc)
return (generation, results)
- def put_doc(self, doc):
- if doc.doc_id is None:
- raise errors.InvalidDocId()
- self._check_doc_id(doc.doc_id)
- self._check_doc_size(doc)
- # TODO: check for conflicts?
+ def _put_doc(self, doc, new_rev):
new_rev = self._allocate_doc_rev(doc.rev)
+ # TODO: change revision to be a dictionary element?
headers = { 'X-Object-Meta-Rev' : new_rev }
self._connection.put_object(self._container, doc_id, doc.get_json(),
headers=headers)
- new_gen = self._get_generation() + 1
- trans_id = self._allocate_transaction_id()
- self._transaction_log.append((new_gen, doc.doc_id, trans_id))
- self._set_u1db_data()
- return new_rev
def get_sync_target(self):
return OpenStackSyncTarget(self)