From b6793f726865587f9bc3230b94fe9a1ef3ea4c98 Mon Sep 17 00:00:00 2001 From: Andrew Resch Date: Mon, 6 Jul 2009 20:00:41 +0000 Subject: [PATCH] Fix client.connect() not firing the errback when a login attempt result is 0 (meaning no authorization) Fix console connect command --- deluge/ui/client.py | 5 +++++ deluge/ui/console/commands/connect.py | 32 ++++++++++++++++++--------- deluge/ui/console/main.py | 8 ++++++- 3 files changed, 34 insertions(+), 11 deletions(-) diff --git a/deluge/ui/client.py b/deluge/ui/client.py index 8223a6a9c..e5a086ee9 100644 --- a/deluge/ui/client.py +++ b/deluge/ui/client.py @@ -384,6 +384,11 @@ class DaemonSSLProxy(DaemonProxy): self.login_deferred.callback(False) def __on_login(self, result, username): + if not result: + # We received a 0 auth level from the server which means it failed + self.login_deferred.errback(result) + return + self.username = username # We need to tell the daemon what events we're interested in receiving if self.__factory.event_handlers: diff --git a/deluge/ui/console/commands/connect.py b/deluge/ui/console/commands/connect.py index 287dc039a..0e9583e99 100644 --- a/deluge/ui/console/commands/connect.py +++ b/deluge/ui/console/commands/connect.py @@ -40,17 +40,29 @@ import deluge.component as component class Command(BaseCommand): """Connect to a new deluge server.""" - def handle(self, host="", port="58846", username="", password="", **options): + + usage = "Usage: connect " + + def handle(self, host="127.0.0.1:58846", username="", password="", **options): self.console = component.get("ConsoleUI") + try: + host, port = host.split(":") + except ValueError: + port = 58846 + else: + port = int(port) - port = int(port) - d = client.connect(host, port, username, password) - def on_connect(result): - self.console.write("{!success!}Connected to %s:%s!" % (host, port)) + def on_disconnect(result): + d = client.connect(host, port, username, password) + def on_connect(result): + self.console.write("{!success!}Connected to %s:%s!" % (host, port)) + component.start() - def on_connect_fail(result): - self.console.write("{!error!}Failed to connect to %s:%s!" % (host, port)) + def on_connect_fail(result): + self.console.write("{!error!}Failed to connect to %s:%s!" % (host, port)) - d.addCallback(on_connect) - d.addErrback(on_connect_fail) - return d + d.addCallback(on_connect) + d.addErrback(on_connect_fail) + return d + + client.disconnect().addCallback(on_disconnect) diff --git a/deluge/ui/console/main.py b/deluge/ui/console/main.py index 1d54d18e0..7c8acd046 100644 --- a/deluge/ui/console/main.py +++ b/deluge/ui/console/main.py @@ -140,6 +140,8 @@ class ConsoleUI(component.Component): # Load all the commands self._commands = load_commands(os.path.join(UI_PATH, 'commands')) + client.set_disconnect_callback(self.on_client_disconnect) + # Set the interactive flag to indicate where we should print the output self.interactive = True if args: @@ -166,7 +168,8 @@ class ConsoleUI(component.Component): # any of the commands. self.started_deferred.addCallback(on_started) - client.connect().addCallback(on_connect) + d = client.connect() + d.addCallback(on_connect) self.coreconfig = CoreConfig() if self.interactive: @@ -397,3 +400,6 @@ class ConsoleUI(component.Component): for index, (tid, name) in enumerate(self.torrents): if torrent_id == tid: del self.torrents[index] + + def on_client_disconnect(self): + component.stop()