Logo Search packages:      
Sourcecode: ubuntuone-client version File versions

dbus_interface.py

# ubuntuone.syncdaemon.dbus_interface - DBus Interface
#
# Author: Guillermo Gonzalez <guillermo.gonzalez@canonical.com>
#
# Copyright 2009 Canonical Ltd.
#
# This program is free software: you can redistribute it and/or modify it
# under the terms of the GNU General Public License version 3, as published
# by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranties of
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
# PURPOSE.  See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program.  If not, see <http://www.gnu.org/licenses/>.
""" DBUS interface module """
import dbus.service

from ubuntuone.syncdaemon.event_queue import EVENTS
from ubuntuone.syncdaemon.interfaces import IMarker
import logging

DBUS_IFACE_NAME = 'com.ubuntuone.SyncDaemon'
DBUS_IFACE_SYNC_NAME = 'com.ubuntuone.SyncDaemon.SyncDaemon'
DBUS_IFACE_STATUS_NAME = DBUS_IFACE_NAME+'.Status'
DBUS_IFACE_EVENTS_NAME = DBUS_IFACE_NAME+'.Events'
DBUS_IFACE_FS_NAME = DBUS_IFACE_NAME+'.FileSystem'
DBUS_IFACE_SHARES_NAME = DBUS_IFACE_NAME+'.Shares'

# NetworkManager State constants
NM_STATE_UNKNOWN = 0
NM_STATE_ASLEEP = 1
NM_STATE_CONNECTING = 2
NM_STATE_CONNECTED = 3
NM_STATE_DISCONNECTED = 4
# NM state -> events mapping
NM_STATE_EVENTS = {NM_STATE_CONNECTED: 'SYS_NET_CONNECTED',
                   NM_STATE_DISCONNECTED: 'SYS_NET_DISCONNECTED'}


00043 class DBusExposedObject(dbus.service.Object):
    """ Base class that provides some helper methods to
    DBus exposed objects.
    """

00048     def __init__(self, bus_name, path):
        """ creates the instance. """
        dbus.service.Object.__init__(self, bus_name=bus_name,
                                     object_path=self.path)

00053     def bool_str(self, value):
        """ return a string value that can be converted back to bool. """
        return 'True' if value else ''

    @dbus.service.signal(DBUS_IFACE_SYNC_NAME, signature='sa{ss}')
00058     def SignalError(self, signal, extra_args):
        """ An error ocurred while trying to emit a signal. """
        pass

00062     def emit_signal_error(self, signal, extra_args):
        """ emit's a Error signal. """
        self.SignalError(signal, extra_args)


00067 class Status(DBusExposedObject):
    """ Represent the status of the syncdaemon """

00070     def __init__(self, bus_name, dbus_iface):
        """ Creates the instance.

        @param bus: the BusName of this DBusExposedObject.
        """
        self.dbus_iface = dbus_iface
        self.action_queue = dbus_iface.action_queue
        self.fs_manager = dbus_iface.fs_manager
        self.path = '/status'
        DBusExposedObject.__init__(self, bus_name=bus_name,
                                   path=self.path)

    @dbus.service.method(DBUS_IFACE_STATUS_NAME,
                         in_signature='', out_signature='a{ss}')
00084     def current_status(self):
        """ return the current status of the system, one of: local_rescan,
        offline, trying_to_connect, server_rescan or online.
        """
        state = self.dbus_iface.main.state.state
        self.emit_status_changed(state)
        state_dict = {'name':state.name,
                      'description':state.description,
                      'is_error':self.bool_str(state.is_error),
                      'is_connected':self.bool_str(state.is_connected),
                      'is_online':self.bool_str(state.is_online)}
        return state_dict

    @dbus.service.method(DBUS_IFACE_STATUS_NAME, out_signature='aa{ss}')
00098     def current_downloads(self):
        """ return list of files with a download in progress. """
        current_downloads = []
        for download in self.action_queue.downloading:
            path = self.fs_manager.get_abspath(download[0],
                              self.fs_manager.get_by_node_id(*download).path)
            info = self.action_queue.downloading[download]
            entry = {'path':path,
                     'share_id':download[0],
                     'node_id':download[1],
                     'deflated_size':str(info.get('deflated_size', -1)),
                     'n_bytes_read':str(info.get('n_bytes_read', -1))}
            current_downloads.append(entry)
        return current_downloads

    @dbus.service.method(DBUS_IFACE_STATUS_NAME,
                         in_signature='', out_signature='aa{ss}')
00115     def current_uploads(self):
        """ return a list of files with a upload in progress """
        current_uploads = []
        for upload in self.action_queue.uploading:
            share_id, node_id = upload
            if IMarker.providedBy(node_id):
                continue
            path = self.fs_manager.get_by_node_id(share_id, node_id).path
            path = self.fs_manager.get_abspath(share_id, path)
            info = self.action_queue.uploading[upload]
            entry = {'path':path,
                     'share_id':upload[0],
                     'node_id':upload[1],
                     'deflated_size':str(info.get('deflated_size', -1)),
                     'n_bytes_written':str(info.get('n_bytes_written', -1))}
            current_uploads.append(entry)
        return current_uploads

    @dbus.service.signal(DBUS_IFACE_STATUS_NAME)
00134     def DownloadStarted(self, path):
        """ Fire a D-BUS signal, notifying a download has started.  """
        pass

    @dbus.service.signal(DBUS_IFACE_STATUS_NAME)
00139     def DownloadFinished(self, path):
        """ Fire a D-BUS signal, notifying a download has finished.  """
        pass

    @dbus.service.signal(DBUS_IFACE_STATUS_NAME)
00144     def UploadStarted(self, path):
        """ Fire a D-BUS signal, notifying an upload has started.  """
        pass

    @dbus.service.signal(DBUS_IFACE_STATUS_NAME)
00149     def UploadFinished(self, path):
        """ Fire a D-BUS signal, notifying an upload has finished.  """
        pass

    @dbus.service.signal(DBUS_IFACE_STATUS_NAME)
00154     def StatusChanged(self, status):
        """ Fire a D-BUS signal, notifying that the status of the
        system changed.
        """
        pass

00160     def emit_status_changed(self, state):
        """ Emits the signal """
        state_dict = {'name':state.name,
                      'description':self.bool_str(state.description),
                      'is_error':self.bool_str(state.is_error),
                      'is_connected':self.bool_str(state.is_connected),
                      'is_online':self.bool_str(state.is_online)}
        self.StatusChanged(state_dict)

00169     def emit_download_started(self, download):
        """ Emits the signal """
        self.DownloadStarted(download)

00173     def emit_download_finished(self, download):
        """ Emits the signal """
        self.DownloadFinished(download)

00177     def emit_upload_started(self, upload):
        """ Emits the signal """
        self.UploadStarted(upload)

00181     def emit_upload_finished(self, upload):
        """ Emits the signal """
        self.UploadFinished(upload)


00186 class Events(DBusExposedObject):
    """ The events of the system translated to D-BUS signals """

00189     def __init__(self, bus_name, event_queue):
        """ Creates the instance.

        @param bus: the BusName of this DBusExposedObject.
        """
        self.event_queue = event_queue
        self.path = '/events'
        DBusExposedObject.__init__(self, bus_name=bus_name,
                                   path=self.path)

    @dbus.service.signal(DBUS_IFACE_EVENTS_NAME,
                         signature='a{ss}')
00201     def Event(self, event_dict):
        """ Fire a D-BUS signal, notifying an event. """
        pass

00205     def emit_event(self, event):
        """ Emits the signal """
        event_dict = {}
        for key, value in event.iteritems():
            event_dict[str(key)] = str(value)
        self.Event(event_dict)

    @dbus.service.method(DBUS_IFACE_EVENTS_NAME, in_signature='sas')
00213     def push_event(self, event_name, args):
        """ Push a event to the event queue """
        str_args = []
        for arg in args:
            str_args.append(str(arg))
        self.event_queue.push(str(event_name), *str_args)


00221 class EventListener(object):
    """ An Event Queue Listener """

00224     def __init__(self, dbus_iface):
        """ created the instance """
        self.dbus_iface = dbus_iface

00228     def _fire_event(self, event_dict):
        """ Calls emit_event in a reactor thread. """
        self.dbus_iface.events.emit_event(event_dict)

00232     def handle_default(self, event_name, *args, **kwargs):
        """ handle all events """
        event_dict = {'event_name':event_name,}
        event_args = list(EVENTS[event_name])
        event_dict.update(kwargs)
        for key in set(event_args).intersection(kwargs.keys()):
            event_args.pop(event_args.index(key))
        for i in xrange(0, len(event_args)):
            event_dict[event_args[i]] = args[i]
        event_dict.update(kwargs)
        self._fire_event(event_dict)

00244     def handle_AQ_DOWNLOAD_STARTED(self, share_id, node_id, server_hash):
        """ handle AQ_DOWNLOAD_STARTED """
        self.handle_default('AQ_DOWNLOAD_STARTED', share_id, node_id,
                            server_hash)
        try:
            mdobj = self.dbus_iface.fs_manager.get_by_node_id(share_id, node_id)
            path = self.dbus_iface.fs_manager.get_abspath(share_id, mdobj.path)
            self.dbus_iface.status.emit_download_started(path)
        except KeyError, e:
            args = dict(message='The md is gone before sending '
                        'DownloadStarted signal',
                        error=str(e),
                        share_id=str(share_id),
                        node_id=str(node_id))
            self.dbus_iface.status.emit_signal_error('DownloadStarted', args)

00260     def handle_AQ_DOWNLOAD_FINISHED(self, share_id, node_id, server_hash):
        """ handle AQ_DOWNLOAD_FINISHED """
        self.handle_default('AQ_DOWNLOAD_FINISHED', share_id,
                            node_id, server_hash)
        try:
            mdobj = self.dbus_iface.fs_manager.get_by_node_id(share_id, node_id)
            path = self.dbus_iface.fs_manager.get_abspath(share_id, mdobj.path)
            self.dbus_iface.status.emit_download_finished(path)
        except KeyError, e:
            # file is gone before we got this
            args = dict(message='The md is gone before sending '
                        'DownloadFinished signal',
                        error=str(e),
                        share_id=str(share_id),
                        node_id=str(node_id))
            self.dbus_iface.status.emit_signal_error('DownloadFinished', args)

00277     def handle_AQ_UPLOAD_STARTED(self, share_id, node_id, hash):
        """ handle AQ_UPLOAD_STARTED """
        self.handle_default('AQ_UPLOAD_STARTED', share_id, node_id, hash)
        try:
            mdobj = self.dbus_iface.fs_manager.get_by_node_id(share_id, node_id)
            path = self.dbus_iface.fs_manager.get_abspath(share_id, mdobj.path)
            self.dbus_iface.status.emit_upload_started(path)
        except KeyError, e:
            args = dict(message='The md is gone before sending '
                        'UploadStarted signal',
                        error=str(e),
                        share_id=str(share_id),
                        node_id=str(node_id))
            self.dbus_iface.status.emit_signal_error('UploadStarted', args)

00292     def handle_AQ_UPLOAD_FINISHED(self, share_id, node_id, hash):
        """ handle AQ_UPLOAD_FINISHED """
        self.handle_default('AQ_UPLOAD_FINISHED', share_id, node_id, hash)
        try:
            mdobj = self.dbus_iface.fs_manager.get_by_node_id(share_id, node_id)
            path = self.dbus_iface.fs_manager.get_abspath(share_id, mdobj.path)
            self.dbus_iface.status.emit_upload_finished(path)
        except KeyError, e:
            # file is gone before we got this
            args = dict(message='The metadata is gone before sending '
                        'UploadFinished signal',
                        error=str(e),
                        share_id=str(share_id),
                        node_id=str(node_id))
            self.dbus_iface.status.emit_signal_error('UploadFinished', args)

00308     def handle_SYS_STATE_CHANGED(self, state):
        """ handle SYS_STATE_CHANGED """
        self.handle_default('SYS_STATE_CHANGED', state)
        self.dbus_iface.status.emit_status_changed(state)

00313     def handle_SV_SHARE_CHANGED(self, message, share):
        """ handle SV_SHARE_CHANGED event, emit's ShareChanged signal. """
        self.handle_default('SV_SHARE_CHANGED', message, share)
        self.dbus_iface.shares.emit_share_changed(message, share)

00318     def handle_AQ_CREATE_SHARE_OK(self, share_id, marker):
        """ handle AQ_CREATE_SHARE_OK event, emit's ShareCreated signal. """
        self.handle_default('AQ_CREATE_SHARE_OK', share_id, marker)
        share = self.dbus_iface.volume_manager.shared.get(share_id)
        share_dict = {}
        if share:
            share_dict.update(self.dbus_iface.shares._get_share_dict(share))
        else:
            share_dict.update(dict(share_id=share_id))
        self.dbus_iface.shares.emit_share_created(share_dict)

00329     def handle_AQ_CREATE_SHARE_ERROR(self, marker, error):
        """ handle AQ_CREATE_SHARE_ERROR event, emit's ShareCreateError signal.
        """
        self.handle_default('AQ_CREATE_SHARE_ERROR', marker, error)
        self.dbus_iface.shares.emit_share_create_error(dict(marker=marker),
                                                       error)


00337 class SyncDaemon(DBusExposedObject):
    """ The Daemon dbus interface. """

00340     def __init__(self, bus_name, dbus_iface):
        """ Creates the instance.

        @param bus: the BusName of this DBusExposedObject.
        """
        self.dbus_iface = dbus_iface
        self.path = '/'
        DBusExposedObject.__init__(self, bus_name=bus_name,
                                   path=self.path)

    @dbus.service.method(DBUS_IFACE_SYNC_NAME,
                         in_signature='', out_signature='')
00352     def connect(self):
        """ Connect to the server. """
        self.dbus_iface.connect()

    @dbus.service.method(DBUS_IFACE_SYNC_NAME,
                         in_signature='', out_signature='')
00358     def disconnect(self):
        """ Disconnect from the server. """
        self.dbus_iface.disconnect()

    @dbus.service.method(DBUS_IFACE_SYNC_NAME,
                         in_signature='', out_signature='s')
00364     def get_rootdir(self):
        """ Returns the root dir/mount point. """
        return self.dbus_iface.main.get_rootdir()

    @dbus.service.method(DBUS_IFACE_SYNC_NAME,
                         in_signature='d', out_signature='b',
                         async_callbacks=('reply_handler', 'error_handler'))
00371     def wait_for_nirvana(self, last_event_interval,
                         reply_handler=None, error_handler=None):
        """ call the reply handler when there are no more
        events or transfers.
        """
        d = self.dbus_iface.main.wait_for_nirvana(last_event_interval)
        d.addCallbacks(reply_handler, error_handler)
        return d

    @dbus.service.method(DBUS_IFACE_SYNC_NAME,
                         in_signature='s', out_signature='')
00382     def query_by_path(self, path):
        """  Request a query of the node identified by path. """
        mdobj = self.dbus_iface.fs_manager.get_by_path(path.encode('utf-8'))
        items = [(mdobj.share_id, mdobj.node_id, "")]
        self.dbus_iface.action_queue.query(items)

    @dbus.service.method(DBUS_IFACE_SYNC_NAME,
                         in_signature='', out_signature='',
                         async_callbacks=('reply_handler', 'error_handler'))
00391     def quit(self, reply_handler=None, error_handler=None):
        """ shutdown the syncdaemon. """
        self.dbus_iface.log.debug('Quit requested')
        if reply_handler:
            reply_handler()
        self.dbus_iface.quit()

00398 class FileSystem(DBusExposedObject):
    """ A dbus interface to the FileSystem Manager. """

00401     def __init__(self, bus_name, fs_manager):
        """ Creates the instance. """
        self.fs_manager = fs_manager
        self.path = '/filesystem'
        DBusExposedObject.__init__(self, bus_name=bus_name,
                                   path=self.path)

    @dbus.service.method(DBUS_IFACE_FS_NAME,
                         in_signature='s', out_signature='a{ss}')
00410     def get_metadata(self, path):
        """ returns the dict with the attributes of the metadata
        for the specified path.
        """
        mdobj = self.fs_manager.get_by_path(path.encode('utf-8'))
        md_dict = {}
        for k, v in mdobj.__dict__.items():
            if k == 'info':
                continue
            md_dict[str(k)] = str(v)
        if mdobj.__dict__.get('info', None):
            for k, v in mdobj.info.__dict__.items():
                md_dict['info_'+str(k)] = str(v)
        return md_dict


00426 class Shares(DBusExposedObject):
    """ A dbus interface to interact wiht shares """

00429     def __init__(self, bus_name, fs_manager, volume_manager):
        """ Creates the instance. """
        self.fs_manager = fs_manager
        self.vm = volume_manager
        self.path = '/shares'
        DBusExposedObject.__init__(self, bus_name=bus_name,
                                   path=self.path)

    @dbus.service.method(DBUS_IFACE_SHARES_NAME,
                         in_signature='', out_signature='aa{ss}')
00439     def get_shares(self):
        """ returns a list of dicts, each dict represents a share """
        shares = []
        for share_id, share in self.vm.shares.items():
            if share_id == '':
                continue
            share_dict = self._get_share_dict(share)
            shares.append(share_dict)
        return shares

    @dbus.service.method(DBUS_IFACE_SHARES_NAME,
                         in_signature='s', out_signature='',
                         async_callbacks=('reply_handler', 'error_handler'))
00452     def accept_share(self, share_id, reply_handler=None, error_handler=None):
        """ Accepts a share. """
        if str(share_id) in self.vm.shares:
            d = self.vm.accept_share(str(share_id), True)
            d.addCallbacks(lambda _: reply_handler(), error_handler)
        else:
            error_handler(ValueError("The share with id: %s don't exists" % \
                                     str(share_id)))

    @dbus.service.method(DBUS_IFACE_SHARES_NAME,
                         in_signature='s', out_signature='',
                         async_callbacks=('reply_handler', 'error_handler'))
00464     def reject_share(self, share_id, reply_handler=None, error_handler=None):
        """ Rejects a share. """
        if str(share_id) in self.vm.shares:
            d = self.vm.accept_share(str(share_id), False)
            d.addCallbacks(lambda _: reply_handler(), error_handler)
        else:
            error_handler(ValueError("The share with id: %s don't exists" % \
                                     str(share_id)))

    @dbus.service.signal(DBUS_IFACE_SHARES_NAME,
                         signature='a{ss}')
00475     def ShareChanged(self, share_dict):
        """ A share changed, share_dict contains all the share attributes. """
        pass

    @dbus.service.signal(DBUS_IFACE_SHARES_NAME,
                         signature='a{ss}')
00481     def ShareDeleted(self, share_dict):
        """ A share was deleted, share_dict contains all available
        share attributes. """
        pass

00486     def emit_share_changed(self, message, share):
        """ emits ShareChanged or ShareDeleted signal for the share
        notification.
        """
        if message == 'deleted':
            self.ShareDeleted(self._get_share_dict(share))
        elif message == 'changed':
            share = self.vm.shares[share.share_id]
            self.ShareChanged(self._get_share_dict(share))

00496     def _get_share_dict(self, share):
        """ get a dict with all the attributes of: share. """
        share_dict = share.__dict__.copy()
        for k, v in share_dict.items():
            if v is None:
                share_dict[unicode(k)] = ''
            elif k == 'path':
                share_dict[unicode(k)] = v.decode('utf-8')
            else:
                share_dict[unicode(k)] = unicode(v)
        return share_dict

    @dbus.service.method(DBUS_IFACE_SHARES_NAME,
                         in_signature='ssss', out_signature='')
00510     def create_share(self, path, username, name, access_level):
        """ Share a subtree to the user identified by username.

        @param path: that path to share (the root of the subtree)
        @param username: the username to offer the share to
        @param name: the name of the share
        @param access_level: 'View' or 'Modify'
        """
        path = path.encode("utf8")
        username = unicode(username)
        name = unicode(name)
        access_level = str(access_level)
        try:
            self.fs_manager.get_by_path(path)
        except KeyError:
            raise ValueError("path '%r' does not exist" % path)
        self.vm.create_share(path, username, name, access_level)

    @dbus.service.signal(DBUS_IFACE_SHARES_NAME,
                         signature='a{ss}')
00530     def ShareCreated(self, share_info):
        """ The requested share was succesfully created. """
        pass

    @dbus.service.signal(DBUS_IFACE_SHARES_NAME,
                         signature='a{ss}s')
00536     def ShareCreateError(self, share_info, error):
        """ An error ocurred while creating the share. """
        pass

00540     def emit_share_created(self, share_info):
        """ emits ShareCreated signal """
        self.ShareCreated(share_info)

00544     def emit_share_create_error(self, share_info, error):
        """ emits ShareDeleted signal """
        self.ShareCreateError(share_info, error)

    @dbus.service.method(DBUS_IFACE_SHARES_NAME,
                         in_signature='', out_signature='')
00550     def refresh_shares(self):
        """ Refresh the share list, requesting it to the server. """
        self.vm.refresh_shares()

    @dbus.service.method(DBUS_IFACE_SHARES_NAME,
                         in_signature='', out_signature='aa{ss}')
00556     def get_shared(self):
        """ returns a list of dicts, each dict represents a shared share.
        A share might not have the path set, as we might be still fetching the
        nodes from the server. In this cases the path is ''
        """
        shares = []
        for share_id, share in self.vm.shared.items():
            if share_id == '':
                continue
            share_dict = self._get_share_dict(share)
            shares.append(share_dict)
        return shares


00570 class DBusInterface(object):
    """ Holder of all DBus exposed objects """
    test = False

00574     def __init__(self, bus, main, system_bus=None):
        """ Create the instance and add the exposed object to the
        specified bus.
        """
        self.log = logging.getLogger("ubuntuone.SyncDaemon.DBus")
        self.bus = bus
        self.main = main
        self.event_queue = main.event_q
        self.action_queue = main.action_q
        self.fs_manager = main.fs
        self.volume_manager = main.vm
        self.busName = dbus.service.BusName(DBUS_IFACE_NAME, bus=self.bus)
        self.status = Status(self.busName, self)
        self.events = Events(self.busName, self.event_queue)
        self.event_listener = EventListener(self)
        self.sync = SyncDaemon(self.busName, self)
        self.fs = FileSystem(self.busName, self.fs_manager)
        self.shares = Shares(self.busName, self.fs_manager,
                             self.volume_manager)
        if system_bus is None and not DBusInterface.test:
            self.log.debug('using the real system bus')
            self.system_bus = self.bus.get_system()
        elif system_bus is None and DBusInterface.test:
            # this is just for the case when test_sync instatiate Main for
            # running it's tests as pqm don't have a system bus running
            self.log.debug('using the session bus as system bus')
            self.system_bus = self.bus
        else:
            self.system_bus = system_bus
        if self.event_queue:
            self.event_queue.subscribe(self.event_listener)
            # on initialization, fake a SYS_NET_CONNECTED if appropriate
            if DBusInterface.test:
                # testing under sync; just do it
                self.log.debug('using the fake NetworkManager')
                self.connection_state_changed(NM_STATE_CONNECTED)
            else:
                def error_handler(error):
                    """
                    Handle errors from NM
                    """
                    self.log.error(
                        "Error while getting the NetworkManager state %s",
                        error)
                    # If we get an error back from NetworkManager, we should
                    # just try to connect anyway; it probably means that
                    # NetworkManager is down or broken or something.
                    self.connection_state_changed(NM_STATE_CONNECTED)
                try:
                    nm = self.system_bus.get_object(
                        'org.freedesktop.NetworkManager',
                        '/org/freedesktop/NetworkManager')
                except dbus.DBusException, e:
                    if e.get_dbus_name() == \
                        'org.freedesktop.DBus.Error.ServiceUnknown':
                        # NetworkManager isn't running.
                        self.log.warn("Unable to connect to NetworkManager. "
                                      "Assuming we have network.")
                        self.connection_state_changed(NM_STATE_CONNECTED)
                    else:
                        raise
                else:
                    nm.Get('org.freedesktop.NetworkManager', 'State',
                           reply_handler=self.connection_state_changed,
                           error_handler=error_handler,
                           dbus_interface='org.freedesktop.DBus.Properties')
        # register a handler to NM StateChanged signal
        self.system_bus.add_signal_receiver(self.connection_state_changed,
                               signal_name='StateChanged',
                               dbus_interface='org.freedesktop.NetworkManager',
                               path='/org/freedesktop/NetworkManager')


00647     def shutdown(self):
        """ remove the registered object from the bus and unsubscribe from the
        event queue.
        """
        self.log.debug('Shuttingdown DBusInterface!')
        self.status.remove_from_connection()
        self.events.remove_from_connection()
        self.sync.remove_from_connection()
        self.fs.remove_from_connection()
        self.shares.remove_from_connection()
        self.event_queue.unsubscribe(self.event_listener)
        # remove the NM's StateChanged signal receiver
        self.system_bus.remove_signal_receiver(self.connection_state_changed,
                               signal_name='StateChanged',
                               dbus_interface='org.freedesktop.NetworkManager',
                               path='/org/freedesktop/NetworkManager')
        self.busName.get_bus().release_name(self.busName.get_name())

00665     def connection_state_changed(self, state):
        """ Push a connection state changed event to the Event Queue. """
        event = NM_STATE_EVENTS.get(state, None)
        if event is not None:
            self.event_queue.push(event)

00671     def connect(self):
        """ Push the SYS_CONNECT event with the tokens in the keyring. """
        from ubuntuone.syncdaemon.main import NoAccessToken
        try:
            access_token = self.main.get_access_token()
            self.event_queue.push('SYS_CONNECT', access_token)
        except NoAccessToken, e:
            self.log.exception("Can't get the auth token")

00680     def disconnect(self):
        """ Push the SYS_DISCONNECT event. """
        self.event_queue.push('SYS_DISCONNECT')

00684     def quit(self):
        """ calls Main.quit. """
        self.log.debug('Calling Main.quit')
        self.main.quit()

Generated by  Doxygen 1.6.0   Back to index