From 2b90f309a68d7b757fedda9f576bd27e954ccc12 Mon Sep 17 00:00:00 2001 From: Calum Lind Date: Fri, 16 Jun 2017 07:57:14 +0100 Subject: [PATCH] [WebUI] Refactor host connect methods --- deluge/ui/web/json_api.py | 44 +++++++++++++++++---------------------- 1 file changed, 19 insertions(+), 25 deletions(-) diff --git a/deluge/ui/web/json_api.py b/deluge/ui/web/json_api.py index 28b2bb1b8..1ab560d57 100644 --- a/deluge/ui/web/json_api.py +++ b/deluge/ui/web/json_api.py @@ -386,10 +386,21 @@ class WebApi(JSONComponent): client.set_disconnect_callback(self._on_client_disconnect) default_host_id = component.get('DelugeWeb').config['default_daemon'] if default_host_id: - return self._connect_daemon(default_host_id) + return self.connect(default_host_id) return defer.succeed(True) + def _on_client_connect(self, *args): + """Handles client successfully connecting to the daemon. + + Invokes retrieving the method names and starts webapi and plugins. + + """ + d_methods = self._json.get_remote_methods() + component.get('Web.PluginManager').start() + self.start() + return d_methods + def _on_client_disconnect(self, *args): component.get('Web.PluginManager').stop() return self.stop() @@ -403,34 +414,17 @@ class WebApi(JSONComponent): self.sessionproxy.stop() return defer.succeed(True) - def _connect_daemon(self, host_id): - """ - Connects the client to a daemon - """ - - def on_client_connected(connection_id): - """ - Handles the client successfully connecting to the daemon and - invokes retrieving the method names. - """ - d = self._json.get_remote_methods() - component.get('Web.PluginManager').start() - self.start() - return d - - return self.hostlist.connect_host(host_id).addCallback(on_client_connected) - @export def connect(self, host_id): - """ - Connect the client to a daemon + """Connect the web client to a daemon. - :param host_id: the id of the daemon in the host list - :type host_id: string - :returns: the methods the daemon supports - :rtype: list + Args: + host_id (str): The id of the daemon in the host list. + + Returns: + Deferred: List of methods the daemon supports. """ - return self._connect_daemon(host_id) + return self.hostlist.connect_host(host_id).addCallback(self._on_client_connect) @export def connected(self):