Make datastore find & update operations async
This commit is contained in:
parent
28e8b9025e
commit
e659d15384
@ -207,15 +207,20 @@ class Activity(Window, gtk.Container):
|
|||||||
self.jobject['preview'] = ''
|
self.jobject['preview'] = ''
|
||||||
self.jobject['icon-color'] = profile.get_color().to_string()
|
self.jobject['icon-color'] = profile.get_color().to_string()
|
||||||
self.jobject.file_path = ''
|
self.jobject.file_path = ''
|
||||||
try:
|
datastore.write(self.jobject,
|
||||||
datastore.write(self.jobject)
|
reply_handler=self._internal_jobject_create_cb,
|
||||||
except Exception, e:
|
error_handler=self._internal_jobject_error_cb)
|
||||||
logging.error(e)
|
|
||||||
else:
|
else:
|
||||||
self.jobject = None
|
self.jobject = None
|
||||||
|
|
||||||
self.connect('focus-out-event', self._focus_out_event_cb)
|
self.connect('focus-out-event', self._focus_out_event_cb)
|
||||||
|
|
||||||
|
def _internal_jobject_create_cb(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def _internal_jobject_error_cb(self, err):
|
||||||
|
logging.debug("Error creating activity datastore object: %s" % err)
|
||||||
|
|
||||||
def _focus_out_event_cb(self, widget, event):
|
def _focus_out_event_cb(self, widget, event):
|
||||||
if self.jobject:
|
if self.jobject:
|
||||||
self.save()
|
self.save()
|
||||||
@ -234,6 +239,12 @@ class Activity(Window, gtk.Container):
|
|||||||
"""
|
"""
|
||||||
raise NotImplementedError
|
raise NotImplementedError
|
||||||
|
|
||||||
|
def _internal_save_cb(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def _internal_save_error_cb(self, err):
|
||||||
|
logging.debug("Error saving activity object to datastore: %s" % err)
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
"""Request that the activity is saved to the Journal."""
|
"""Request that the activity is saved to the Journal."""
|
||||||
try:
|
try:
|
||||||
@ -241,7 +252,9 @@ class Activity(Window, gtk.Container):
|
|||||||
self.write_file()
|
self.write_file()
|
||||||
except NotImplementedError:
|
except NotImplementedError:
|
||||||
self.jobject.file_path = ''
|
self.jobject.file_path = ''
|
||||||
datastore.write(self.jobject)
|
datastore.write(self.jobject,
|
||||||
|
reply_handler=self._internal_save_cb,
|
||||||
|
error_handler=self._internal_save_error_cb)
|
||||||
|
|
||||||
def _internal_joined_cb(self, activity, success, err):
|
def _internal_joined_cb(self, activity, success, err):
|
||||||
"""Callback when join has finished"""
|
"""Callback when join has finished"""
|
||||||
|
@ -71,20 +71,22 @@ def get(object_id):
|
|||||||
def create():
|
def create():
|
||||||
return DSObject(object_id=None, metadata={}, file_path=None)
|
return DSObject(object_id=None, metadata={}, file_path=None)
|
||||||
|
|
||||||
def write(ds_object):
|
def write(ds_object, reply_handler=None, error_handler=None):
|
||||||
logging.debug('datastore.write')
|
logging.debug('datastore.write')
|
||||||
if ds_object.object_id:
|
if ds_object.object_id:
|
||||||
dbus_helpers.update(ds_object.object_id,
|
dbus_helpers.update(ds_object.object_id,
|
||||||
ds_object.metadata,
|
ds_object.metadata,
|
||||||
ds_object.file_path)
|
ds_object.file_path,
|
||||||
|
reply_handler=reply_handler,
|
||||||
|
error_handler=error_handler)
|
||||||
else:
|
else:
|
||||||
ds_object.object_id = dbus_helpers.create(ds_object.metadata,
|
ds_object.object_id = dbus_helpers.create(ds_object.metadata,
|
||||||
ds_object.file_path)
|
ds_object.file_path)
|
||||||
# TODO: register the object for updates
|
# TODO: register the object for updates
|
||||||
logging.debug('Written object %s to the datastore.' % ds_object.object_id)
|
logging.debug('Written object %s to the datastore.' % ds_object.object_id)
|
||||||
|
|
||||||
def find(query):
|
def find(query, reply_handler=None, error_handler=None):
|
||||||
object_ids = dbus_helpers.find({})
|
object_ids = dbus_helpers.find(query, reply_handler, error_handler)
|
||||||
objects = []
|
objects = []
|
||||||
for object_id in object_ids:
|
for object_id in object_ids:
|
||||||
objects.append(get(object_id))
|
objects.append(get(object_id))
|
||||||
|
@ -54,13 +54,18 @@ def create(properties, filename):
|
|||||||
logging.debug('dbus_helpers.create: ' + object_id)
|
logging.debug('dbus_helpers.create: ' + object_id)
|
||||||
return object_id
|
return object_id
|
||||||
|
|
||||||
def update(uid, properties, filename):
|
def update(uid, properties, filename, reply_handler=None, error_handler=None):
|
||||||
logging.debug('dbus_helpers.update: %s, %s, %s' % (uid, properties, filename))
|
logging.debug('dbus_helpers.update: %s, %s, %s' % (uid, properties, filename))
|
||||||
try:
|
try:
|
||||||
logging.debug(get_contents(filename))
|
logging.debug(get_contents(filename))
|
||||||
except UnicodeDecodeError:
|
except UnicodeDecodeError:
|
||||||
pass
|
pass
|
||||||
_data_store.update(uid, dbus.Dictionary(properties), filename)
|
if reply_handler and error_handler:
|
||||||
|
_data_store.update(uid, dbus.Dictionary(properties), filename,
|
||||||
|
reply_handler=reply_handler,
|
||||||
|
error_handler=error_handler)
|
||||||
|
else:
|
||||||
|
_data_store.update(uid, dbus.Dictionary(properties), filename)
|
||||||
|
|
||||||
def get_properties(uid):
|
def get_properties(uid):
|
||||||
props = _data_store.get_properties(uid)
|
props = _data_store.get_properties(uid)
|
||||||
@ -76,8 +81,12 @@ def get_filename(uid):
|
|||||||
pass
|
pass
|
||||||
return filename
|
return filename
|
||||||
|
|
||||||
def find(query):
|
def find(query, reply_handler, error_handler):
|
||||||
return _data_store.find(query)
|
if reply_handler and error_handler:
|
||||||
|
return _data_store.find(query, reply_handler=reply_handler,
|
||||||
|
error_handler=error_handler)
|
||||||
|
else:
|
||||||
|
return _data_store.find(query)
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user