diff options
author | Sascha Silbe <sascha-pgp@silbe.org> | 2014-05-22 19:40:36 (GMT) |
---|---|---|
committer | Sascha Silbe <sascha-pgp@silbe.org> | 2014-05-22 19:48:02 (GMT) |
commit | 4c6414569ce05625aeac001127962682aa916bb8 (patch) | |
tree | 70644fafc67398a8564a71ed157dd88beb87d0d4 | |
parent | dc8b667fc3e6bf855762deb775c83ea12bd07a6b (diff) |
WIP: Add support for native gdatastore APIgdatastore-native-api
There's currently a problem with this: gdatastore change_metadata() is
buggy: it only updates the index, not git. So changes don't propagate
to other instances.
-rw-r--r-- | fsemulation.py | 67 |
1 files changed, 49 insertions, 18 deletions
diff --git a/fsemulation.py b/fsemulation.py index 8e89fef..9fc6eb2 100644 --- a/fsemulation.py +++ b/fsemulation.py @@ -35,6 +35,9 @@ DS_DBUS_INTERFACE1 = 'org.laptop.sugar.DataStore' DS_DBUS_PATH1 = '/org/laptop/sugar/DataStore' DS_DBUS_INTERFACE2 = 'org.laptop.sugar.DataStore2' DS_DBUS_PATH2 = '/org/laptop/sugar/DataStore2' +GDS_DBUS_SERVICE = 'org.silbe.GDataStore' +GDS_DBUS_INTERFACE1 = 'org.silbe.GDataStore1' +GDS_DBUS_PATH1 = '/org/silbe/GDataStore1' # nearly infinite DBUS_TIMEOUT_MAX = 2 ** 31 / 1000 @@ -102,6 +105,18 @@ class DataStore(object): self._data_store_version = 0 bus = dbus.SessionBus() try: + self._data_store = dbus.Interface(bus.get_object(GDS_DBUS_SERVICE, + GDS_DBUS_PATH1), GDS_DBUS_INTERFACE1) + self._data_store.find({'tree_id': 'invalid'}, + {'metadata': ['tree_id']}) + self.supports_versions = True + logging.info('gdatastore found') + return + + except dbus.DBusException: + logging.debug('No gdatastore found') + + try: self._data_store = dbus.Interface(bus.get_object(DS_DBUS_SERVICE, DS_DBUS_PATH2), DS_DBUS_INTERFACE2) self._data_store.find({'tree_id': 'invalid'}, @@ -138,7 +153,8 @@ class DataStore(object): """ query = self._merge_root_query(query) - if self._data_store.dbus_interface == DS_DBUS_INTERFACE2: + if self._data_store.dbus_interface in [GDS_DBUS_INTERFACE1, + DS_DBUS_INTERFACE2]: options = {'metadata': ['tree_id', 'version_id'], 'order_by': ['-timestamp']} return [(unicode(entry['tree_id']), unicode(entry['version_id'])) @@ -169,7 +185,8 @@ class DataStore(object): query = self._merge_root_query(query) properties = list(_USEFUL_PROPS) - if self._data_store.dbus_interface == DS_DBUS_INTERFACE2: + if self._data_store.dbus_interface in [GDS_DBUS_INTERFACE1, + DS_DBUS_INTERFACE2]: properties += ['parent_id', 'tree_id', 'version_id'] options = {'metadata': properties, 'all_versions': True, 'order_by': ['-timestamp']} @@ -214,7 +231,8 @@ class DataStore(object): assert isinstance(name, unicode) query = self._merge_root_query(query) - if self._data_store.dbus_interface == DS_DBUS_INTERFACE2: + if self._data_store.dbus_interface in [GDS_DBUS_INTERFACE1, + DS_DBUS_INTERFACE2]: options = {'metadata': [name], 'all_versions': True} entries = self._data_store.find(query, options, timeout=DBUS_TIMEOUT_MAX, @@ -234,12 +252,10 @@ class DataStore(object): """Return True if the given object_id identifies a data store entry""" try: entry = self.get_properties(object_id, self._root_query.keys()) - except dbus.DBusException, exception: - if exception.get_dbus_name() == DBUS_PYTHON_VALUE_ERROR: - return False - raise - - return True + except ValueError: + return False + else: + return True @synchronised def check_tree_id(self, tree_id): @@ -262,7 +278,8 @@ class DataStore(object): query_string = u'%s:"%s"' % (name, word.replace(u'"', u'')) query = dict(self._root_query) - if self._data_store.dbus_interface == DS_DBUS_INTERFACE2: + if self._data_store.dbus_interface in [GDS_DBUS_INTERFACE1, + DS_DBUS_INTERFACE2]: options = {'limit': 1} results = self._data_store.text_search(query, query_string, options, @@ -284,7 +301,8 @@ class DataStore(object): Returns a dictionary with unicode strings as keys and values. """ query = dict(self._root_query) - if self._data_store.dbus_interface == DS_DBUS_INTERFACE2: + if self._data_store.dbus_interface in [GDS_DBUS_INTERFACE1, + DS_DBUS_INTERFACE2]: tree_id, version_id = object_id assert isinstance(tree_id, unicode) assert isinstance(version_id, unicode) @@ -396,7 +414,8 @@ class DataStore(object): if not self.check_object_id(object_id): raise ValueError('Object %r does not exist' % (object_id, )) - if self._data_store.dbus_interface == DS_DBUS_INTERFACE2: + if self._data_store.dbus_interface in [GDS_DBUS_INTERFACE1, + DS_DBUS_INTERFACE2]: tree_id, version_id = object_id self._data_store.delete(tree_id, version_id, timeout=DBUS_TIMEOUT_MAX) @@ -415,10 +434,11 @@ class DataStore(object): if (not isinstance(key, unicode)) or (not isinstance(value, unicode))] - if self._data_store.dbus_interface == DS_DBUS_INTERFACE2: + if self._data_store.dbus_interface == GDS_DBUS_INTERFACE1: + return self._data_store.create(properties, '') + elif self._data_store.dbus_interface == DS_DBUS_INTERFACE2: return self._data_store.save('', '', properties, '', False, timeout=DBUS_TIMEOUT_MAX) - else: return self._data_store.create(properties, '', False) @@ -430,11 +450,14 @@ class DataStore(object): if not self.check_object_id(object_id): raise ValueError('Object %r does not exist' % (object_id, )) + if self._data_store.dbus_interface == GDS_DBUS_INTERFACE1: + tree_id, version_id = object_id + return self._data_store.get_data_path(tree_id, version_id, + byte_arrays=True) if self._data_store.dbus_interface == DS_DBUS_INTERFACE2: tree_id, version_id = object_id return self._data_store.get_data(tree_id, version_id, byte_arrays=True) - else: return self._data_store.get_filename(object_id, byte_arrays=True) @@ -461,7 +484,14 @@ class DataStore(object): assert isinstance(path, str) properties = self.get_properties(object_id) - if self._data_store.dbus_interface == DS_DBUS_INTERFACE2: + properties.pop('version_id', None) + if self._data_store.dbus_interface == GDS_DBUS_INTERFACE1: + tree_id, parent_id = object_id + child_id = self._data_store.add_version( + tree_id, parent_id, properties, path, timeout=DBUS_TIMEOUT_MAX, + byte_arrays=True) + return unicode(tree_id), unicode(child_id) + elif self._data_store.dbus_interface == DS_DBUS_INTERFACE2: tree_id, parent_id = object_id res = self._data_store.save(tree_id, parent_id, properties, path, False, timeout=DBUS_TIMEOUT_MAX, @@ -517,7 +547,8 @@ class DataStore(object): return metadata_unicode def _change_metadata(self, object_id, metadata): - if self._data_store.dbus_interface == DS_DBUS_INTERFACE2: + if self._data_store.dbus_interface in [GDS_DBUS_INTERFACE1, + DS_DBUS_INTERFACE2]: tree_id, version_id = object_id self._data_store.change_metadata(tree_id, version_id, metadata) @@ -816,7 +847,7 @@ class ByVersionIdDirectory(Directory): for version_id in self._ds.list_versions(self._tree_id): object_id = (self._tree_id, version_id) - yield (object_id, DSObject(self._fs, object_id)) + yield (version_id, DSObject(self._fs, object_id)) class ByTreeIdDirectory(Directory): |