Rewrite dbus_helpers to not make a dbus connection on import. #2773
This commit is contained in:
parent
c54fb84b28
commit
26c5ad6ad0
@ -28,55 +28,63 @@ DS_DBUS_SERVICE = "org.laptop.sugar.DataStore"
|
|||||||
DS_DBUS_INTERFACE = "org.laptop.sugar.DataStore"
|
DS_DBUS_INTERFACE = "org.laptop.sugar.DataStore"
|
||||||
DS_DBUS_PATH = "/org/laptop/sugar/DataStore"
|
DS_DBUS_PATH = "/org/laptop/sugar/DataStore"
|
||||||
|
|
||||||
|
_data_store = None
|
||||||
|
|
||||||
|
def _get_data_store():
|
||||||
|
global _data_store
|
||||||
|
|
||||||
|
if not _data_store:
|
||||||
_bus = dbus.SessionBus()
|
_bus = dbus.SessionBus()
|
||||||
_data_store = dbus.Interface(_bus.get_object(DS_DBUS_SERVICE, DS_DBUS_PATH),
|
_data_store = dbus.Interface(_bus.get_object(DS_DBUS_SERVICE,
|
||||||
|
DS_DBUS_PATH),
|
||||||
DS_DBUS_INTERFACE)
|
DS_DBUS_INTERFACE)
|
||||||
|
return _data_store
|
||||||
|
|
||||||
def create(properties, filename):
|
def create(properties, filename):
|
||||||
object_id = _data_store.create(dbus.Dictionary(properties), filename)
|
object_id = _get_data_store().create(dbus.Dictionary(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, reply_handler=None, error_handler=None, timeout=-1):
|
def update(uid, properties, filename, reply_handler=None, error_handler=None, timeout=-1):
|
||||||
logging.debug('dbus_helpers.update: %s, %s, %s' % (uid, filename, properties))
|
logging.debug('dbus_helpers.update: %s, %s, %s' % (uid, filename, properties))
|
||||||
if reply_handler and error_handler:
|
if reply_handler and error_handler:
|
||||||
_data_store.update(uid, dbus.Dictionary(properties), filename,
|
_get_data_store().update(uid, dbus.Dictionary(properties), filename,
|
||||||
reply_handler=reply_handler,
|
reply_handler=reply_handler,
|
||||||
error_handler=error_handler,
|
error_handler=error_handler,
|
||||||
timeout=timeout)
|
timeout=timeout)
|
||||||
else:
|
else:
|
||||||
_data_store.update(uid, dbus.Dictionary(properties), filename)
|
_get_data_store().update(uid, dbus.Dictionary(properties), filename)
|
||||||
|
|
||||||
def delete(uid):
|
def delete(uid):
|
||||||
logging.debug('dbus_helpers.delete: %r' % uid)
|
logging.debug('dbus_helpers.delete: %r' % uid)
|
||||||
_data_store.delete(uid)
|
_get_data_store().delete(uid)
|
||||||
|
|
||||||
def get_properties(uid):
|
def get_properties(uid):
|
||||||
logging.debug('dbus_helpers.get_properties: %s' % uid)
|
logging.debug('dbus_helpers.get_properties: %s' % uid)
|
||||||
return _data_store.get_properties(uid)
|
return _get_data_store().get_properties(uid)
|
||||||
|
|
||||||
def get_filename(uid):
|
def get_filename(uid):
|
||||||
filename = _data_store.get_filename(uid)
|
filename = _get_data_store().get_filename(uid)
|
||||||
logging.debug('dbus_helpers.get_filename: %s, %s' % (uid, filename))
|
logging.debug('dbus_helpers.get_filename: %s, %s' % (uid, filename))
|
||||||
return filename
|
return filename
|
||||||
|
|
||||||
def find(query, reply_handler, error_handler):
|
def find(query, reply_handler, error_handler):
|
||||||
logging.debug('dbus_helpers.find: %r' % query)
|
logging.debug('dbus_helpers.find: %r' % query)
|
||||||
if reply_handler and error_handler:
|
if reply_handler and error_handler:
|
||||||
return _data_store.find(query, reply_handler=reply_handler,
|
return _get_data_store().find(query, reply_handler=reply_handler,
|
||||||
error_handler=error_handler)
|
error_handler=error_handler)
|
||||||
else:
|
else:
|
||||||
return _data_store.find(query)
|
return _get_data_store().find(query)
|
||||||
|
|
||||||
def mount(uri, options):
|
def mount(uri, options):
|
||||||
return _data_store.mount(uri, options)
|
return _get_data_store().mount(uri, options)
|
||||||
|
|
||||||
def unmount(mount_point_id):
|
def unmount(mount_point_id):
|
||||||
_data_store.unmount(mount_point_id)
|
_get_data_store().unmount(mount_point_id)
|
||||||
|
|
||||||
def mounts():
|
def mounts():
|
||||||
return _data_store.mounts()
|
return _get_data_store().mounts()
|
||||||
|
|
||||||
def get_unique_values(key):
|
def get_unique_values(key):
|
||||||
return _data_store.get_uniquevaluesfor(key, dbus.Dictionary({}, signature='ss'))
|
return _get_data_store().get_uniquevaluesfor(key, dbus.Dictionary({}, signature='ss'))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user