<commit_before># Copyright (C) 2006-2007 Red Hat, Inc.
# Copyright (C) 2007, One Laptop Per Child
#
# 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.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# 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.

import logging

import dbus
import dbus.glib
import gobject

from sugar import util

DS_DBUS_SERVICE = "org.laptop.sugar.DataStore"
DS_DBUS_INTERFACE = "org.laptop.sugar.DataStore"
DS_DBUS_PATH = "/org/laptop/sugar/DataStore"

_bus = dbus.SessionBus()
_data_store = dbus.Interface(_bus.get_object(DS_DBUS_SERVICE, DS_DBUS_PATH),
                             DS_DBUS_INTERFACE)

def create(properties, filename):
    object_id = _data_store.create(dbus.Dictionary(properties), filename)
    logging.debug('dbus_helpers.create: ' + object_id)
    return object_id

def update(uid, properties, filename, reply_handler=None, error_handler=None, timeout=-1):
    logging.debug('dbus_helpers.update: %s, %s, %s' % (uid, filename, properties))
    if reply_handler and error_handler:
        _data_store.update(uid, dbus.Dictionary(properties), filename,
                reply_handler=reply_handler,
                error_handler=error_handler,
                timeout=timeout)
    else:
        _data_store.update(uid, dbus.Dictionary(properties), filename)

def delete(uid):
    logging.debug('dbus_helpers.delete: %r' % uid)
    _data_store.delete(uid)
        
def get_properties(uid):
    logging.debug('dbus_helpers.get_properties: %s' % uid)
    return _data_store.get_properties(uid)

def get_filename(uid):
    filename = _data_store.get_filename(uid)
    logging.debug('dbus_helpers.get_filename: %s, %s' % (uid, filename))
    return filename

def find(query, reply_handler, error_handler):
    logging.debug('dbus_helpers.find: %r' % 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)

def mount(uri, options):
    return _data_store.mount(uri, options)

def unmount(mount_point_id):
    _data_store.unmount(mount_point_id)

def mounts():
    return _data_store.mounts()

def get_unique_values(key):
    return _data_store.get_uniquevaluesfor(key, dbus.Dictionary({}, signature='ss'))
<commit_msg>Rewrite dbus_helpers to not make a dbus connection on import. #2773<commit_after># Copyright (C) 2006-2007 Red Hat, Inc.
# Copyright (C) 2007, One Laptop Per Child
#
# 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.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# 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.

import logging

import dbus
import dbus.glib
import gobject

from sugar import util

DS_DBUS_SERVICE = "org.laptop.sugar.DataStore"
DS_DBUS_INTERFACE = "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()
        _data_store = dbus.Interface(_bus.get_object(DS_DBUS_SERVICE,
                                                     DS_DBUS_PATH),
                                     DS_DBUS_INTERFACE)
    return _data_store

def create(properties, filename):
    object_id = _get_data_store().create(dbus.Dictionary(properties), filename)
    logging.debug('dbus_helpers.create: ' + object_id)
    return object_id

def update(uid, properties, filename, reply_handler=None, error_handler=None, timeout=-1):
    logging.debug('dbus_helpers.update: %s, %s, %s' % (uid, filename, properties))
    if reply_handler and error_handler:
        _get_data_store().update(uid, dbus.Dictionary(properties), filename,
                reply_handler=reply_handler,
                error_handler=error_handler,
                timeout=timeout)
    else:
        _get_data_store().update(uid, dbus.Dictionary(properties), filename)

def delete(uid):
    logging.debug('dbus_helpers.delete: %r' % uid)
    _get_data_store().delete(uid)
        
def get_properties(uid):
    logging.debug('dbus_helpers.get_properties: %s' % uid)
    return _get_data_store().get_properties(uid)

def get_filename(uid):
    filename = _get_data_store().get_filename(uid)
    logging.debug('dbus_helpers.get_filename: %s, %s' % (uid, filename))
    return filename

def find(query, reply_handler, error_handler):
    logging.debug('dbus_helpers.find: %r' % query)
    if reply_handler and error_handler:
        return _get_data_store().find(query, reply_handler=reply_handler,
                error_handler=error_handler)
    else:
        return _get_data_store().find(query)

def mount(uri, options):
    return _get_data_store().mount(uri, options)

def unmount(mount_point_id):
    _get_data_store().unmount(mount_point_id)

def mounts():
    return _get_data_store().mounts()

def get_unique_values(key):
    return _get_data_store().get_uniquevaluesfor(key, dbus.Dictionary({}, signature='ss'))

{'fraction_non_alphanumeric': 0.09347790372925907, 'fraction_numerical': 0.009857072449482503, 'mean_word_length': 3.8821170809943863, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2624092', 'n_tokens_mistral': 1907, 'n_tokens_neox': 1853, 'n_words': 527}