コード例 #1
0
ファイル: plugin_deluge.py プロジェクト: Anaerin/Flexget
        def connect(self, task, config):
            """Connects to the deluge daemon and runs on_connect_success """

            if config['host'] in ['localhost', '127.0.0.1'] and not config.get('user'):
                # If an user is not specified, we have to do a lookup for the localclient username/password
                auth = get_localhost_auth()
                if auth[0]:
                    config['user'], config['pass'] = auth
                else:
                    raise PluginError('Unable to get local authentication info for Deluge. '
                                      'You may need to specify an username and password from your Deluge auth file.')

            client.set_disconnect_callback(self.on_disconnect)

            d = client.connect(
                host=config['host'],
                port=config['port'],
                username=config['user'],
                password=config['pass'])

            d.addCallback(self.on_connect_success, task, config).addErrback(self.on_connect_fail)
            result = reactor.run()
            if isinstance(result, Exception):
                raise result
            return result
コード例 #2
0
ファイル: deluge.py プロジェクト: cash2one/flexget
    def connect(self, task, config):
        """Connects to the deluge daemon and runs on_connect_success """

        if config['host'] in ['localhost', '127.0.0.1'
                              ] and not config.get('username'):
            # If an username is not specified, we have to do a lookup for the localclient username/password
            auth = get_localhost_auth()
            if auth[0]:
                config['username'], config['password'] = auth
            else:
                raise plugin.PluginError(
                    'Unable to get local authentication info for Deluge. You may need to '
                    'specify an username and password from your Deluge auth file.'
                )

        client.set_disconnect_callback(self.on_disconnect)

        d = client.connect(host=config['host'],
                           port=config['port'],
                           username=config['username'],
                           password=config['password'])

        d.addCallback(self.on_connect_success, task,
                      config).addErrback(self.on_connect_fail)
        result = reactor.run()
        if isinstance(result, Exception):
            raise result
        return result
コード例 #3
0
 def __migrate_config_1_to_2(self, config):
     localclient_username, localclient_password = get_localhost_auth()
     if not localclient_username:
         # Nothing to do here, there's no auth file
         return
     for idx, (_, host, _, username, _) in enumerate(config["hosts"][:]):
         if host in ("127.0.0.1", "localhost"):
             if not username:
                 config["hosts"][idx][3] = localclient_username
                 config["hosts"][idx][4] = localclient_password
     return config
コード例 #4
0
    def __load_config(self):
        auth_file = deluge.configmanager.get_config_dir("auth")
        if not os.path.exists(auth_file):
            from deluge.common import create_localclient_account
            create_localclient_account()

        localclient_username, localclient_password = get_localhost_auth()
        DEFAULT_CONFIG = {
            "hosts":
            [(hashlib.sha1(str(time.time())).hexdigest(), DEFAULT_HOST,
              DEFAULT_PORT, localclient_username, localclient_password)]
        }
        config = ConfigManager("hostlist.conf.1.2", DEFAULT_CONFIG)
        config.run_converter((0, 1), 2, self.__migrate_config_1_to_2)
        return config
コード例 #5
0
    def on_button_startdaemon_clicked(self, widget):
        log.debug("on_button_startdaemon_clicked")
        if self.liststore.iter_n_children(None) < 1:
            # There is nothing in the list, so lets create a localhost entry
            self.add_host(DEFAULT_HOST, DEFAULT_PORT, *get_localhost_auth())
            # ..and start the daemon.
            self.start_daemon(DEFAULT_PORT,
                              deluge.configmanager.get_config_dir())
            return

        paths = self.hostlist.get_selection().get_selected_rows()[1]
        if len(paths) < 1:
            return

        status = self.liststore[paths[0]][HOSTLIST_COL_STATUS]
        host = self.liststore[paths[0]][HOSTLIST_COL_HOST]
        port = self.liststore[paths[0]][HOSTLIST_COL_PORT]
        user = self.liststore[paths[0]][HOSTLIST_COL_USER]
        password = self.liststore[paths[0]][HOSTLIST_COL_PASS]

        if host not in ("127.0.0.1", "localhost"):
            return

        if status in ("Online", "Connected"):
            # We need to stop this daemon
            # Call the shutdown method on the daemon
            def on_daemon_shutdown(d):
                # Update display to show change
                self.__update_list()

            if client.connected() and client.connection_info() == (host, port,
                                                                   user):
                client.daemon.shutdown().addCallback(on_daemon_shutdown)
            elif user and password:
                # Create a new client instance
                c = deluge.ui.client.Client()

                def on_connect(d, c):
                    log.debug("on_connect")
                    c.daemon.shutdown().addCallback(on_daemon_shutdown)

                c.connect(host, port, user,
                          password).addCallback(on_connect, c)

        elif status == "Offline":
            self.start_daemon(port, deluge.configmanager.get_config_dir())
            reactor.callLater(2.0, self.__update_list)
コード例 #6
0
    def on_button_startdaemon_clicked(self, widget):
        log.debug("on_button_startdaemon_clicked")
        if self.liststore.iter_n_children(None) < 1:
            # There is nothing in the list, so lets create a localhost entry
            self.add_host(DEFAULT_HOST, DEFAULT_PORT, *get_localhost_auth())
            # ..and start the daemon.
            self.start_daemon(
                DEFAULT_PORT, deluge.configmanager.get_config_dir()
            )
            return

        paths = self.hostlist.get_selection().get_selected_rows()[1]
        if len(paths) < 1:
            return

        status = self.liststore[paths[0]][HOSTLIST_COL_STATUS]
        host = self.liststore[paths[0]][HOSTLIST_COL_HOST]
        port = self.liststore[paths[0]][HOSTLIST_COL_PORT]
        user = self.liststore[paths[0]][HOSTLIST_COL_USER]
        password = self.liststore[paths[0]][HOSTLIST_COL_PASS]

        if host not in ("127.0.0.1", "localhost"):
            return

        if status in (_("Online"), _("Connected")):
            # We need to stop this daemon
            # Call the shutdown method on the daemon
            def on_daemon_shutdown(d):
                # Update display to show change
                self.__update_list()

            if client.connected() and client.connection_info() == (host, port, user):
                client.daemon.shutdown().addCallback(on_daemon_shutdown)
            elif user and password:
                # Create a new client instance
                c = deluge.ui.client.Client()
                def on_connect(d, c):
                    log.debug("on_connect")
                    c.daemon.shutdown().addCallback(on_daemon_shutdown)

                c.connect(host, port, user, password).addCallback(on_connect, c)

        elif status == _("Offline"):
            self.start_daemon(port, deluge.configmanager.get_config_dir())
            reactor.callLater(2.0, self.__update_list)
コード例 #7
0
    def __load_config(self):
        auth_file = deluge.configmanager.get_config_dir("auth")
        if not os.path.exists(auth_file):
            from deluge.common import create_localclient_account
            create_localclient_account()

        localclient_username, localclient_password = get_localhost_auth()
        DEFAULT_CONFIG = {
            "hosts": [(
                hashlib.sha1(str(time.time())).hexdigest(),
                 DEFAULT_HOST,
                 DEFAULT_PORT,
                 localclient_username,
                 localclient_password
            )]
        }
        config = ConfigManager("hostlist.conf.1.2", DEFAULT_CONFIG)
        config.run_converter((0, 1), 2, self.__migrate_config_1_to_2)
        return config
コード例 #8
0
    def exec_args(self, args, host, port, username, password):
        def on_connect(result):
            def on_started(result):
                def on_started(result):
                    deferreds = []
                    # If we have args, lets process them and quit
                    # allow multiple commands split by ";"
                    for arg in args.split(";"):
                        deferreds.append(
                            defer.maybeDeferred(self.do_command, arg.strip()))

                    def on_complete(result):
                        self.do_command("quit")

                    dl = defer.DeferredList(deferreds).addCallback(on_complete)

                # We need to wait for the rpcs in start() to finish before processing
                # any of the commands.
                self.console.started_deferred.addCallback(on_started)

            component.start().addCallback(on_started)

        def on_connect_fail(reason):
            if reason.check(DelugeError):
                rm = reason.value.message
            else:
                rm = reason.getErrorMessage()
            print "Could not connect to: %s:%d\n %s" % (host, port, rm)
            self.do_command("quit")

        if not username and host in ("127.0.0.1", "localhost"):
            # No username was provided and it's the localhost, so we can try
            # to grab the credentials from the auth file.
            from deluge.ui.common import get_localhost_auth
            username, password = get_localhost_auth()
        if host:
            d = client.connect(host, port, username, password)
        else:
            d = client.connect()
        d.addCallback(on_connect)
        d.addErrback(on_connect_fail)