class UbuntuOneClient(object): """Root object that provides access to all the remote objects.""" def __init__(self): """Create a new instance.""" self.status = None self.events = None self.sync_daemon = None self.file_system = None self.shares = None self.config = None self.folders = None self.public_files = None self.factory = None self.client = None @defer.inlineCallbacks def _request_remote_objects(self, root): """Request all the diff remote objects used for the communication.""" status = yield root.callRemote('get_status') self.status = StatusClient(status) events = yield root.callRemote('get_events') self.events = EventsClient(events) sync_daemon = yield root.callRemote('get_sync_daemon') self.sync_daemon = SyncDaemonClient(sync_daemon) file_system = yield root.callRemote('get_file_system') self.file_system = FileSystemClient(file_system) shares = yield root.callRemote('get_shares') self.shares = SharesClient(shares) config = yield root.callRemote('get_config') self.config = ConfigClient(config) folders = yield root.callRemote('get_folders') self.folders = FoldersClient(folders) public_files = yield root.callRemote('get_public_files') self.public_files = PublicFilesClient(public_files) defer.returnValue(self) @defer.inlineCallbacks def connect(self): """Connect to the syncdaemon service.""" # pylint: disable=W0702 try: # connect to the remote objects self.factory = PBClientFactory() self.client = yield ipc_client_connect(self.factory) root = yield self.factory.getRootObject() yield self._request_remote_objects(root) yield self.register_to_signals() defer.returnValue(self) except Exception, e: raise SyncDaemonClientConnectionError( 'Could not connect to the syncdaemon ipc.', e)
def run(self, *args, **kwargs): def connected(reference): self._reference = reference return super(Client, self).run(*args, **kwargs) client = PBClientFactory() d = client.getRootObject() d.addCallback(connected) self._reactor.connectTCP('127.0.0.1', self._port, client) return d
def _sendMessage(channel, message): """ Establish a connection to the bot and direct it to send the given message to the given channel. @type channel: C{str} @type message: C{str} """ messageFactory = PBClientFactory() reactor.connectTCP(BOT_HOST, BOT_PORT, messageFactory) def cbGotRoot(rootObj): return rootObj.callRemote('message', channel, message) rootDeferred = messageFactory.getRootObject() rootDeferred.addCallback(cbGotRoot) rootDeferred.addErrback(err) rootDeferred.addCallback(lambda ign: reactor.stop())
class UbuntuSSOClient(object): """Root client that provides access to the sso API.""" def __init__(self): self.sso_login = None self.cred_management = None self.factory = None self.client = None @defer.inlineCallbacks def _request_remote_objects(self, root): """Get the status remote object.""" sso_login = yield root.callRemote('get_sso_login') logger.debug('SSOLogin is %s', sso_login) self.sso_login = SSOLoginClient(sso_login) cred_management = yield root.callRemote('get_cred_manager') self.cred_management = CredentialsManagementClient(cred_management) defer.returnValue(self) @defer.inlineCallbacks def connect(self): """Connect to the sso service.""" ac = ActivationClient(get_activation_config()) port = yield ac.get_active_port() # got the port, lets try and connect to it and get the diff # remote objects for the wrappers self.factory = PBClientFactory() # the reactor does have a connectTCP method # pylint: disable=E1101 self.client = reactor.connectTCP(LOCALHOST, port, self.factory) # pylint: enable=E1101 root = yield self.factory.getRootObject() client = yield self._request_remote_objects(root) defer.returnValue(client) def disconnect(self): """Disconnect from the process.""" if self.client: self.client.disconnect()
class BaseClient(object): """Client that will connect to the service listening on the description. Inherit from this class and define service_name, service_description and service_cmdline so they return the proper values. The service_cmdline must be redefined so it returns the command line to execute to run the service, if it's not running. If 'connect' is called, 'disconnect' should be called when done. """ # a mapping of (client name, client class (an instance of RemoteClient)) clients = {} service_name = None service_description = None service_cmdline = None def __init__(self): self.factory = None self.client = None for client in self.clients: setattr(self, client, None) @defer.inlineCallbacks def _request_remote_objects(self, root): """Request all the diff remote objects used for the communication.""" logger.debug('Requesting remote objects (%r) for %s', self.clients.keys(), self.__class__.__name__) for name, client_class in self.clients.items(): remote = yield root.callRemote('get_%s' % name) setattr(self, name, client_class(self, remote)) @defer.inlineCallbacks def connect(self): """Connect to the remote service.""" self.factory = PBClientFactory() self.client = yield client_connect(self.factory, self.service_name, self.service_cmdline, self.service_description) root = yield self.factory.getRootObject() yield self._request_remote_objects(root) yield self.register_to_signals() @defer.inlineCallbacks def reconnect(self): """Reconnect with the server.""" self.factory = PBClientFactory() self.client = yield client_connect(self.factory, self.service_name, self.service_cmdline, self.service_description) root = yield self.factory.getRootObject() # loop over the already present remote clients and reset their remotes for name in self.clients: remote = yield root.callRemote('get_%s' % name) remote_client = getattr(self, name) remote_client.remote = remote yield self.register_to_signals() @defer.inlineCallbacks def register_to_signals(self): """Register all the clients to their signals.""" for name in self.clients: client = getattr(self, name) yield client.register_to_signals() @defer.inlineCallbacks def unregister_to_signals(self): """Unregister from the all the client's signals.""" for name in self.clients: client = getattr(self, name) yield client.unregister_to_signals() @defer.inlineCallbacks def disconnect(self): """Disconnect from the process.""" yield self.unregister_to_signals() if self.client: self.client.disconnect()
class UbuntuOneClient(object): """Root object that provides access to all the remote objects.""" connection_lock = defer.DeferredLock() def __init__(self): """Create a new instance.""" self.status = None self.events = None self.sync_daemon = None self.file_system = None self.shares = None self.config = None self.folders = None self.public_files = None self.factory = None self.client = None @defer.inlineCallbacks def _request_remote_objects(self, root): """Request all the diff remote objects used for the communication.""" status = yield root.callRemote('get_status') self.status = StatusClient(status) events = yield root.callRemote('get_events') self.events = EventsClient(events) sync_daemon = yield root.callRemote('get_sync_daemon') self.sync_daemon = SyncDaemonClient(sync_daemon) file_system = yield root.callRemote('get_file_system') self.file_system = FileSystemClient(file_system) shares = yield root.callRemote('get_shares') self.shares = SharesClient(shares) config = yield root.callRemote('get_config') self.config = ConfigClient(config) folders = yield root.callRemote('get_folders') self.folders = FoldersClient(folders) public_files = yield root.callRemote('get_public_files') self.public_files = PublicFilesClient(public_files) defer.returnValue(self) @defer.inlineCallbacks def connect(self): """Connect to the syncdaemon service.""" yield self.connection_lock.acquire() try: if self.client is None: # connect to the remote objects self.factory = PBClientFactory() self.client = yield ipc_client_connect(self.factory) root = yield self.factory.getRootObject() yield self._request_remote_objects(root) yield self.register_to_signals() defer.returnValue(self) except Exception as e: raise SyncDaemonClientConnectionError( 'Could not connect to the syncdaemon ipc.', e) finally: self.connection_lock.release() @defer.inlineCallbacks def reconnect(self): """Reconnect and get the new remote objects.""" try: root = yield self.factory.getRootObject() yield self._request_remote_objects(root) yield self.register_to_signals() defer.returnValue(self) except Exception as e: raise SyncDaemonClientConnectionError( 'Could not reconnect to the syncdaemon ipc.', e) def is_connected(self): """Return if the client is connected.""" return (self.client is not None) @defer.inlineCallbacks def register_to_signals(self): """Register the different clients to the signals.""" for client in [self.status, self.events, self.sync_daemon, self.shares, self.folders, self.public_files]: register = getattr(client, 'register_to_signals', None) if register is not None: yield register() defer.returnValue(self) @defer.inlineCallbacks def unregister_to_signals(self): """Unregister from the diff signals.""" for client in [self.status, self.events, self.sync_daemon, self.shares, self.folders, self.public_files]: unregister = getattr(client, 'unregister_to_signals', None) if unregister is not None: yield unregister() defer.returnValue(self) def disconnect(self): """Disconnect from the process.""" if self.client: self.client.transport.loseConnection()
class BaseClient(object): """Client that will connect to the service listening on service_port. Inherit from this class and define service_name, service_port and service_cmdline so they return the proper values. The service_cmdline must be redefined so it returns the command line to execute to run the service, if it's not running. If 'connect' is called, 'disconnect' should be called when done. """ # a mapping of (client name, client class (an instance of RemoteClient)) clients = {} service_name = None service_port = None service_cmdline = None def __init__(self): self.factory = None self.client = None for client in self.clients: setattr(self, client, None) @defer.inlineCallbacks def _request_remote_objects(self, root): """Request all the diff remote objects used for the communication.""" logger.debug('Requesting remote objects (%r) for %s', self.clients.keys(), self.__class__.__name__) for name, client_class in self.clients.iteritems(): remote = yield root.callRemote('get_%s' % name) setattr(self, name, client_class(remote)) @defer.inlineCallbacks def connect(self): """Connect to the remote service.""" self.factory = PBClientFactory() self.client = yield client_connect(self.factory, self.service_name, self.service_cmdline, self.service_port) root = yield self.factory.getRootObject() yield self._request_remote_objects(root) yield self.register_to_signals() @defer.inlineCallbacks def register_to_signals(self): """Register all the clients to their signals.""" for name in self.clients: client = getattr(self, name) yield client.register_to_signals() @defer.inlineCallbacks def unregister_to_signals(self): """Unregister from the all the client's signals.""" for name in self.clients: client = getattr(self, name) yield client.unregister_to_signals() @defer.inlineCallbacks def disconnect(self): """Disconnect from the process.""" yield self.unregister_to_signals() if self.client: self.client.disconnect()