2007-06-24 14:43:48 +02:00
|
|
|
# Copyright (C) 2006-2007 Red Hat, Inc.
|
2007-05-10 11:01:32 +02:00
|
|
|
# Copyright (C) 2007, One Laptop Per Child
|
|
|
|
#
|
2007-06-24 13:10:53 +02:00
|
|
|
# This library is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
|
|
# License as published by the Free Software Foundation; either
|
|
|
|
# version 2 of the License, or (at your option) any later version.
|
2007-05-10 11:01:32 +02:00
|
|
|
#
|
2007-06-24 13:10:53 +02:00
|
|
|
# This library is distributed in the hope that it will be useful,
|
2007-05-10 11:01:32 +02:00
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2007-06-24 13:10:53 +02:00
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# Lesser General Public License for more details.
|
2007-05-10 11:01:32 +02:00
|
|
|
#
|
2007-06-24 13:10:53 +02:00
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
|
|
# License along with this library; if not, write to the
|
|
|
|
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
|
|
# Boston, MA 02111-1307, USA.
|
2007-07-13 13:20:44 +02:00
|
|
|
|
2007-05-10 11:01:32 +02:00
|
|
|
import logging
|
|
|
|
|
|
|
|
import dbus
|
|
|
|
import dbus.glib
|
|
|
|
|
|
|
|
DS_DBUS_SERVICE = "org.laptop.sugar.DataStore"
|
|
|
|
DS_DBUS_INTERFACE = "org.laptop.sugar.DataStore"
|
|
|
|
DS_DBUS_PATH = "/org/laptop/sugar/DataStore"
|
|
|
|
|
2007-08-15 15:19:40 +02:00
|
|
|
_data_store = None
|
|
|
|
|
|
|
|
def _get_data_store():
|
|
|
|
global _data_store
|
|
|
|
|
|
|
|
if not _data_store:
|
|
|
|
_bus = dbus.SessionBus()
|
|
|
|
_data_store = dbus.Interface(_bus.get_object(DS_DBUS_SERVICE,
|
|
|
|
DS_DBUS_PATH),
|
|
|
|
DS_DBUS_INTERFACE)
|
|
|
|
return _data_store
|
2007-05-10 11:01:32 +02:00
|
|
|
|
2007-09-08 03:53:32 +02:00
|
|
|
def create(properties, filename, transfer_ownership=False):
|
|
|
|
object_id = _get_data_store().create(dbus.Dictionary(properties), filename,
|
|
|
|
transfer_ownership)
|
2007-05-10 11:01:32 +02:00
|
|
|
logging.debug('dbus_helpers.create: ' + object_id)
|
|
|
|
return object_id
|
|
|
|
|
2007-09-08 03:53:32 +02:00
|
|
|
def update(uid, properties, filename, transfer_ownership=False,
|
|
|
|
reply_handler=None, error_handler=None, timeout=-1):
|
|
|
|
debug_props = properties.copy()
|
|
|
|
if debug_props.has_key("preview"):
|
|
|
|
debug_props["preview"] = "<omitted>"
|
2008-04-19 12:04:43 +02:00
|
|
|
logging.debug('dbus_helpers.update: %s, %s, %s, %s' %
|
|
|
|
(uid, filename, debug_props, transfer_ownership))
|
2007-05-16 06:41:45 +02:00
|
|
|
if reply_handler and error_handler:
|
2007-08-15 15:19:40 +02:00
|
|
|
_get_data_store().update(uid, dbus.Dictionary(properties), filename,
|
2007-09-08 03:53:32 +02:00
|
|
|
transfer_ownership,
|
2007-05-16 06:41:45 +02:00
|
|
|
reply_handler=reply_handler,
|
2007-07-26 09:20:38 +02:00
|
|
|
error_handler=error_handler,
|
|
|
|
timeout=timeout)
|
2007-05-16 06:41:45 +02:00
|
|
|
else:
|
2008-04-19 12:04:43 +02:00
|
|
|
_get_data_store().update(uid, dbus.Dictionary(properties),
|
|
|
|
filename, transfer_ownership)
|
2007-05-10 11:01:32 +02:00
|
|
|
|
2007-06-22 17:01:13 +02:00
|
|
|
def delete(uid):
|
|
|
|
logging.debug('dbus_helpers.delete: %r' % uid)
|
2007-08-15 15:19:40 +02:00
|
|
|
_get_data_store().delete(uid)
|
2007-07-13 13:20:44 +02:00
|
|
|
|
2007-05-10 11:01:32 +02:00
|
|
|
def get_properties(uid):
|
2007-05-16 17:01:59 +02:00
|
|
|
logging.debug('dbus_helpers.get_properties: %s' % uid)
|
2007-10-05 22:39:45 +02:00
|
|
|
return _get_data_store().get_properties(uid, byte_arrays=True)
|
2007-05-10 11:01:32 +02:00
|
|
|
|
|
|
|
def get_filename(uid):
|
2007-08-15 15:19:40 +02:00
|
|
|
filename = _get_data_store().get_filename(uid)
|
2007-05-13 18:21:35 +02:00
|
|
|
logging.debug('dbus_helpers.get_filename: %s, %s' % (uid, filename))
|
|
|
|
return filename
|
2007-05-10 11:01:32 +02:00
|
|
|
|
2007-09-10 18:03:40 +02:00
|
|
|
def find(query, properties, reply_handler, error_handler):
|
2007-10-03 21:33:34 +02:00
|
|
|
logging.debug('dbus_helpers.find: %r %r' % (query, properties))
|
2007-05-16 06:41:45 +02:00
|
|
|
if reply_handler and error_handler:
|
2007-09-10 18:03:40 +02:00
|
|
|
return _get_data_store().find(query, properties,
|
|
|
|
reply_handler=reply_handler, error_handler=error_handler)
|
2007-05-16 06:41:45 +02:00
|
|
|
else:
|
2007-09-10 18:03:40 +02:00
|
|
|
return _get_data_store().find(query, properties)
|
2007-05-10 11:01:32 +02:00
|
|
|
|
2007-10-06 11:15:36 +02:00
|
|
|
def mount(uri, options, timeout=-1):
|
|
|
|
return _get_data_store().mount(uri, options, timeout=timeout)
|
2007-06-27 11:36:05 +02:00
|
|
|
|
2007-06-28 10:43:38 +02:00
|
|
|
def unmount(mount_point_id):
|
2007-08-15 15:19:40 +02:00
|
|
|
_get_data_store().unmount(mount_point_id)
|
2007-06-28 10:43:38 +02:00
|
|
|
|
2007-06-27 11:36:05 +02:00
|
|
|
def mounts():
|
2007-08-15 15:19:40 +02:00
|
|
|
return _get_data_store().mounts()
|
2007-06-27 11:36:05 +02:00
|
|
|
|
2007-07-03 17:07:48 +02:00
|
|
|
def get_unique_values(key):
|
2008-04-19 12:04:43 +02:00
|
|
|
return _get_data_store().get_uniquevaluesfor(
|
|
|
|
key, dbus.Dictionary({}, signature='ss'))
|
2007-07-03 17:07:48 +02:00
|
|
|
|
2007-08-29 19:56:43 +02:00
|
|
|
def complete_indexing():
|
|
|
|
return _get_data_store().complete_indexing()
|
|
|
|
|