Esempio n. 1
0
    def run(self):
        while not self.stop_request.is_set():
            start_time = time()
            try:
                start_time = time()
                self.wake_up.clear()
                if self.reset.is_set():
                    self.reset.clear()
                    self.reset_daemon()
                self._one_loop()
                assert log_timing(logger, "One loop", self, "daemon loop",
                                  start_time)
            except ConnectorError:
                logger.info("Daemon %s could not connect to server",
                            self.__class__.__name__)
                connection_to_server_status.send(f"{self.name}", success=False)
            except Exception:
                logger.info("Daemon %s crashed", self.name, exc_info=True)
            finally:
                if self._loop_success:
                    connection_to_server_status.send(self.name, success=True)
                    self._loop_success = False
                # wait for next loop
                poll_time = time() - start_time
                if poll_time < self._loop_interval:
                    self.wake_up.wait(self._loop_interval - poll_time)

        logger.info("Daemon %s exiting", self.name)
Esempio n. 2
0
    def refresh(self, sender, server_state: dict = None):
        start_time = time()

        if server_state is None:
            server_state = dict()
        """ Right column => <dl rate>⯆ [<dl limit>] (<dl size>) <up rate>⯅ [<up limit>] (<up size>) """
        # note: have to use unicode codes to avoid chars with too many bytes...urwid doesn't handle those well
        # <dl rate>⯆
        dl_up_text = f"{natural_file_size(server_state.get('dl_info_speed', 0), gnu=True).rjust(6)}/s{DOWN_TRIANGLE}"
        # [<dl limit>]
        if server_state.get("dl_rate_limit", None):
            dl_up_text = f"{dl_up_text} [{natural_file_size(server_state.get('dl_rate_limit', 0),gnu=True)}/s]"
        # (<dl size>)
        dl_up_text = f"{dl_up_text} ({natural_file_size(server_state.get('dl_info_data', 0), gnu=True)})"
        # <up rate>⯅
        dl_up_text = f"{dl_up_text} {natural_file_size(server_state.get('up_info_speed', 0), gnu=True).rjust(6)}/s{UP_TRIANGLE}"
        # [<up limit>]
        if server_state.get("up_rate_limit", None):
            dl_up_text = f"{dl_up_text} [{natural_file_size(server_state.get('up_rate_limit', 0),gnu=True)}/s]"
        # (<up size>)
        dl_up_text = f"{dl_up_text} ({natural_file_size(server_state.get('up_info_data', 0), gnu=True)})"
        """ Left column => DHT: # Status: <status> """
        dht_and_status = ""
        if server_state.get("dht_nodes", None):
            dht_and_status = f"DHT: {server_state.get('dht_nodes', None)} "
        dht_and_status = f"{dht_and_status}Status: {server_state.get('connection_status', 'disconnected')}"

        self.left_column.base_widget.set_text(dht_and_status)
        self.right_column.base_widget.set_text(dl_up_text)

        assert log_timing(logger, "Updating", self, sender, start_time)
Esempio n. 3
0
    def refresh_torrent_list(self, sender):
        """
        Refreshes the torrent list using local torrent data.

        :param sender:
        :return:
        """
        start_time = time()

        # save off focused row so it can be re-focused after refresh
        torrent_hash_in_focus = self.torrent_list_w.get_torrent_hash_for_focused_row(
        )

        # dynamically resize torrent list based on window width
        self.torrent_list_w.resize()

        # put the relevant torrents in the walker
        self.torrent_list_w.apply_torrent_list_filter(
            status_filter=self.torrent_tabs_w.get_selected_tab_name())

        # re-focus same torrent if it still exists
        self.torrent_list_w.set_torrent_list_focus(
            "torrent list refresh", torrent_hash=torrent_hash_in_focus)

        assert log_timing(logger, "Refreshing", self, sender, start_time)
Esempio n. 4
0
    def update_torrent_list(self,
                            sender,
                            full_update=False,
                            torrents=None,
                            torrents_removed=None):
        """
        Update torrents with new data and refresh_torrent_list window.

        :param sender:
        :param full_update:
        :param torrents:
        :param torrents_removed:
        :return:
        """
        start_time = time()

        torrents = torrents or {}
        torrents_removed = torrents_removed or {}

        # this dictionary of torrents will only contain the data changed since last update...unless full update
        self.torrent_list_w.update(
            torrents=torrents,
            torrents_removed=torrents_removed,
            full_update=full_update,
        )

        assert log_timing(logger, "Updating", self, sender, start_time)

        self.refresh_torrent_list(sender)
Esempio n. 5
0
 def render(self, size, focus=False):
     # catch screen resize
     start_time = time()
     if self._width != size[0]:
         self._width = size[0]
         # call to refresh_torrent_list on screen re-sizes
         refresh_torrent_list_now.send("torrent list render")
     ret = super(TorrentListWindow, self).render(size, focus)
     assert log_timing(logger, "Rendering", self, "render", start_time)
     return ret
Esempio n. 6
0
class AppTitleBar(uw.Text):
    def __init__(self):
        """Application title bar."""
        super(AppTitleBar, self).__init__(markup=APPLICATION_NAME,
                                          align=uw.CENTER,
                                          wrap=uw.CLIP,
                                          layout=None)
        self.refresh("title bar init")
        server_details_changed.connect(receiver=self.refresh)

    def refresh(self, sender, details: dict = None):
        start_time = time()

        div_ch = " | "
        server_version_str = ""
        hostname_str = ""
        title = ""

        if details is None:
            details = {}

        if ver := details.get("server_version", ""):
            server_version_str = ver

        hostname = config.get("HOST")
        port = config.get("PORT")
        hostname_str = (
            f"{hostname if hostname else ''}{f':{port}' if hostname and port else ''}"
        )

        if server_version_str:
            title = server_version_str
        if APPLICATION_NAME:
            title = title + (div_ch if title else "") + APPLICATION_NAME
        if hostname_str:
            title = title + (div_ch if title else "") + hostname_str

        self.set_text(title)

        assert log_timing(logger, "Updating", self, sender, start_time)