Exemplo n.º 1
0
    def connected(self):
        """
        The current connection state.

        :returns: True if the client is connected
        :rtype: booleon
        """
        return client.connected()
Exemplo n.º 2
0
    def connected(self):
        """
        The current connection state.

        :returns: True if the client is connected
        :rtype: booleon
        """
        return client.connected()
Exemplo n.º 3
0
    def update_ui(self, keys, filter_dict):
        """
        Gather the information required for updating the web interface.

        :param keys: the information about the torrents to gather
        :type keys: list
        :param filter_dict: the filters to apply when selecting torrents.
        :type filter_dict: dictionary
        :returns: The torrent and ui information.
        :rtype: dictionary
        """
        d = Deferred()
        ui_info = {
            "connected": client.connected(),
            "torrents": None,
            "filters": None,
            "stats": {
                "max_download": self.core_config.get("max_download_speed"),
                "max_upload": self.core_config.get("max_upload_speed"),
                "max_num_connections": self.core_config.get("max_connections_global")
            }
        }

        if not client.connected():
            d.callback(ui_info)
            return d

        def got_connections(connections):
            ui_info["stats"]["num_connections"] = connections

        def got_stats(stats):
            ui_info["stats"]["upload_rate"] = stats["payload_upload_rate"]
            ui_info["stats"]["download_rate"] = stats["payload_download_rate"]
            ui_info["stats"]["download_protocol_rate"] = stats["download_rate"] - stats["payload_download_rate"]
            ui_info["stats"]["upload_protocol_rate"] = stats["upload_rate"] - stats["payload_upload_rate"]
            ui_info["stats"]["dht_nodes"] = stats["dht_nodes"]
            ui_info["stats"]["has_incoming_connections"] = stats["has_incoming_connections"]

        def got_filters(filters):
            ui_info["filters"] = filters

        def got_free_space(free_space):
            ui_info["stats"]["free_space"] = free_space

        def got_torrents(torrents):
            ui_info["torrents"] = torrents

        def on_complete(result):
            d.callback(ui_info)

        d1 = component.get("SessionProxy").get_torrents_status(filter_dict, keys)
        d1.addCallback(got_torrents)

        d2 = client.core.get_filter_tree()
        d2.addCallback(got_filters)

        d3 = client.core.get_session_status([
            "payload_download_rate",
            "payload_upload_rate",
            "download_rate",
            "upload_rate",
            "dht_nodes",
            "has_incoming_connections"
        ])
        d3.addCallback(got_stats)

        d4 = client.core.get_num_connections()
        d4.addCallback(got_connections)

        d5 = client.core.get_free_space(self.core_config.get("download_location"))
        d5.addCallback(got_free_space)

        dl = DeferredList([d1, d2, d3, d4, d5], consumeErrors=True)
        dl.addCallback(on_complete)
        return d
Exemplo n.º 4
0
            def on_info_fail(reason, c):
                c.disconnect()
                return response(_("Offline"))

            if not connected:
                return response(_("Offline"))

            return c.daemon.info(
                ).addCallback(on_info, c
                ).addErrback(on_info_fail, c)

        def on_connect_failed(reason, host_id):
            return response(_("Offline"))

        if client.connected() and (host, port, "localclient" if not
                                   user and host in ("127.0.0.1", "localhost") else
                                   user)  == client.connection_info():
            def on_info(info):
                return response(_("Connected"), info)

            return client.daemon.info().addCallback(on_info)
        else:
            c = Client()
            return c.connect(host, port, user, password
                ).addCallback(on_connect, c, host_id
                ).addErrback(on_connect_failed, host_id)

    @export(AUTH_LEVEL_ADMIN)
    def start_daemon(self, port):
        """
Exemplo n.º 5
0
    def update_ui(self, keys, filter_dict):
        """
        Gather the information required for updating the web interface.

        :param keys: the information about the torrents to gather
        :type keys: list
        :param filter_dict: the filters to apply when selecting torrents.
        :type filter_dict: dictionary
        :returns: The torrent and ui information.
        :rtype: dictionary
        """
        d = Deferred()
        ui_info = {
            "connected": client.connected(),
            "torrents": None,
            "filters": None,
            "stats": {
                "max_download":
                self.core_config.get("max_download_speed"),
                "max_upload":
                self.core_config.get("max_upload_speed"),
                "max_num_connections":
                self.core_config.get("max_connections_global")
            }
        }

        if not client.connected():
            d.callback(ui_info)
            return d

        def got_connections(connections):
            ui_info["stats"]["num_connections"] = connections

        def got_stats(stats):
            ui_info["stats"]["upload_rate"] = stats["payload_upload_rate"]
            ui_info["stats"]["download_rate"] = stats["payload_download_rate"]
            ui_info["stats"]["download_protocol_rate"] = stats[
                "download_rate"] - stats["payload_download_rate"]
            ui_info["stats"]["upload_protocol_rate"] = stats[
                "upload_rate"] - stats["payload_upload_rate"]
            ui_info["stats"]["dht_nodes"] = stats["dht_nodes"]
            ui_info["stats"]["has_incoming_connections"] = stats[
                "has_incoming_connections"]

        def got_filters(filters):
            ui_info["filters"] = filters

        def got_free_space(free_space):
            ui_info["stats"]["free_space"] = free_space

        def got_torrents(torrents):
            ui_info["torrents"] = torrents

        def on_complete(result):
            d.callback(ui_info)

        d1 = component.get("SessionProxy").get_torrents_status(
            filter_dict, keys)
        d1.addCallback(got_torrents)

        d2 = client.core.get_filter_tree()
        d2.addCallback(got_filters)

        d3 = client.core.get_session_status([
            "payload_download_rate", "payload_upload_rate", "download_rate",
            "upload_rate", "dht_nodes", "has_incoming_connections"
        ])
        d3.addCallback(got_stats)

        d4 = client.core.get_num_connections()
        d4.addCallback(got_connections)

        d5 = client.core.get_free_space(
            self.core_config.get("download_location"))
        d5.addCallback(got_free_space)

        dl = DeferredList([d1, d2, d3, d4, d5], consumeErrors=True)
        dl.addCallback(on_complete)
        return d
Exemplo n.º 6
0
                return response(_("Online"), info)

            def on_info_fail(reason, c):
                c.disconnect()
                return response(_("Offline"))

            if not connected:
                return response(_("Offline"))

            return c.daemon.info().addCallback(on_info,
                                               c).addErrback(on_info_fail, c)

        def on_connect_failed(reason, host_id):
            return response(_("Offline"))

        if client.connected() and (host, port, "localclient" if not user
                                   and host in ("127.0.0.1", "localhost") else
                                   user) == client.connection_info():

            def on_info(info):
                return response(_("Connected"), info)

            return client.daemon.info().addCallback(on_info)
        else:
            c = Client()
            return c.connect(host, port, user, password).addCallback(
                on_connect, c, host_id).addErrback(on_connect_failed, host_id)

    @export
    def start_daemon(self, port):
        """