From 2e2851dc13d73352530dd4495c7e05603b2e520d Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 10 Apr 2024 23:38:38 +0200 Subject: Adding upstream version 2.1.2~dev0+20240219. Signed-off-by: Daniel Baumann --- deluge/ui/console/cmdline/commands/connect.py | 78 +++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 deluge/ui/console/cmdline/commands/connect.py (limited to 'deluge/ui/console/cmdline/commands/connect.py') diff --git a/deluge/ui/console/cmdline/commands/connect.py b/deluge/ui/console/cmdline/commands/connect.py new file mode 100644 index 0000000..4c76de3 --- /dev/null +++ b/deluge/ui/console/cmdline/commands/connect.py @@ -0,0 +1,78 @@ +# +# Copyright (C) 2008-2009 Ido Abramovich +# Copyright (C) 2009 Andrew Resch +# +# This file is part of Deluge and is licensed under GNU General Public License 3.0, or later, with +# the additional special exception to link portions of this program with the OpenSSL library. +# See LICENSE for more details. +# + +import logging + +import deluge.component as component +from deluge.ui.client import client + +from . import BaseCommand + +log = logging.getLogger(__name__) + + +class Command(BaseCommand): + """Connect to a new deluge server""" + + usage = _('Usage: connect [] []') + + def add_arguments(self, parser): + parser.add_argument( + 'host', help=_('Daemon host and port'), metavar='' + ) + parser.add_argument( + 'username', help=_('Username'), metavar='', nargs='?', default='' + ) + parser.add_argument( + 'password', help=_('Password'), metavar='', nargs='?', default='' + ) + + def add_parser(self, subparsers): + parser = subparsers.add_parser( + self.name, help=self.__doc__, description=self.__doc__, prog='connect' + ) + self.add_arguments(parser) + + def handle(self, options): + self.console = component.get('ConsoleUI') + + host = options.host + try: + host, port = host.split(':') + port = int(port) + except ValueError: + port = 58846 + + def do_connect(): + d = client.connect(host, port, options.username, options.password) + + def on_connect(result): + if self.console.interactive: + self.console.write(f'{{!success!}}Connected to {host}:{port}!') + return component.start() + + def on_connect_fail(result): + self.console.write( + f'{{!error!}}Failed to connect to {host}:{port} with reason: {result.value.message}' + ) + return result + + d.addCallbacks(on_connect, on_connect_fail) + return d + + if client.connected(): + + def on_disconnect(result): + if self.console.statusbars: + self.console.statusbars.update_statusbars() + return do_connect() + + return client.disconnect().addCallback(on_disconnect) + else: + return do_connect() -- cgit v1.2.3