How to use the castero.helpers function in castero

To help you get started, we’ve selected a few castero examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github xgi / castero / tests / test_helpers.py View on Github external
def test_sanitize_path_blank():
    path = ""
    result = helpers.sanitize_path(path)
    assert result == ""
github xgi / castero / tests / test_helpers.py View on Github external
def test_third_zero():
    result = helpers.third(0)
    assert result == 0
github xgi / castero / castero / perspectives / queueperspective.py View on Github external
self._queue_window.addstr(0, 0, " " * self._queue_window.getmaxyx()[1])

        # add window headers
        self._queue_window.addstr(0, 0, self._queue_menu.title,
                                  curses.color_pair(7) | curses.A_BOLD)
        self._metadata_window.addstr(0, 0, "Metadata",
                                     curses.color_pair(7) | curses.A_BOLD)

        # add window borders
        self._queue_window.hline(1, 0,
                                 0, self._queue_window.getmaxyx()[1],
                                 curses.ACS_HLINE | curses.color_pair(8))
        self._metadata_window.hline(1, 0,
                                    0, self._metadata_window.getmaxyx()[1] - 1,
                                    curses.ACS_HLINE | curses.color_pair(8))
        if not helpers.is_true(Config["disable_vertical_borders"]):
            self._queue_window.vline(0, self._queue_window.getmaxyx()[1] - 1,
                                     0, self._queue_window.getmaxyx()[0] - 2,
                                     curses.ACS_VLINE | curses.color_pair(8))

        # display menu content
        self._queue_menu.display()

        # draw metadata
        if not self._metadata_updated:
            self._draw_metadata(self._metadata_window)
github xgi / castero / castero / episode.py View on Github external
def _feed_directory(self) -> str:
        """Gets the path to the downloaded episode's feed directory.

        This method does not ensure whether the directory exists -- it simply
        acts as a single definition of where it _should_ be.

        Returns:
            str: a path to the feed directory
        """
        feed_dirname = helpers.sanitize_path(str(self._feed))
        if Config is None or Config["custom_download_dir"] == "":
            path = DataFile.DEFAULT_DOWNLOADED_DIR
        else:
            path = \
                os.path.expandvars(
                    os.path.expanduser(
                        Config["custom_download_dir"]))
            if not path.startswith('/'):
                path = "/%s" % path
        return os.path.join(path, feed_dirname)
github xgi / castero / castero / feed.py View on Github external
def metadata(self) -> str:
        """str: the user-displayed metadata of the feed"""
        description = helpers.html_to_plain(self.description) if \
            helpers.is_true(Config["clean_html_descriptions"]) else \
            self.description
        description = description.replace('\n', '')

        return \
            "!cb{title}\n" \
            "{last_build_date}\n\n" \
            "{link}\n\n" \
            "!cbCopyright:\n" \
            "{copyright}\n\n" \
            "!cbDescription:\n" \
            "{description}\n".format(
                title=self.title,
                last_build_date=self.last_build_date,
                link=self.link,
                copyright=self.copyright,
github xgi / castero / castero / __main__.py View on Github external
)
    remaining_brace_fields = re.compile('\\{.*?\\}').findall(castero.__help__)
    for field in remaining_brace_fields:
        adjusted = field.replace("{", "").replace("}", "").ljust(9)
        castero.__help__ = \
            castero.__help__.replace(field, adjusted)

    # instantiate display
    temp_file = redirect_stderr()
    stdscr = curses.initscr()
    display = Display(stdscr, database)
    display.clear()
    display.update_parent_dimensions()

    # check if we need to start reloading
    if helpers.is_true(Config['reload_on_start']):
        reload_thread = threading.Thread(
            target=database.reload,
            args=[display]
        )
        reload_thread.start()

    # run initial display operations
    display.display()
    display.update()
    display.refresh()

    # core loop for the client
    running = True
    while running:
        display.display()
        display.update()
github xgi / castero / castero / episode.py View on Github external
def metadata(self) -> str:
        """str: the user-displayed metadata of the episode"""
        description = helpers.html_to_plain(self.description) if \
            helpers.is_true(Config["clean_html_descriptions"]) else \
            self.description
        description = description.replace('\n', '')
        downloaded = "Episode downloaded and available for offline playback." \
            if self.downloaded else "Episode not downloaded."

        return \
            "!cb{title}\n" \
            "{pubdate}\n\n" \
            "{link}\n\n" \
            "!cbCopyright:\n" \
            "{copyright}\n\n" \
            "!cbDownloaded:\n" \
            "{downloaded}\n\n" \
            "!cbDescription:\n" \
            "{description}\n".format(
github xgi / castero / castero / perspectives / queueperspective.py View on Github external
def create_windows(self) -> None:
        """Create and set basic parameters for the windows.

        Overrides method from Perspective; see documentation in that class.
        """
        # delete old windows if they exist
        if self._queue_window is not None:
            del self._queue_window
            self._queue_window = None
        if self._metadata_window is not None:
            del self._metadata_window
            self._metadata_window = None

        parent_x = self._display.parent_x
        parent_y = self._display.parent_y
        third_x = helpers.third(parent_x)
        self._queue_window = curses.newwin(parent_y - 2, third_x * 2,
                                           2, 0)
        metadata_width = parent_x - ((third_x * 2) - 1)
        self._metadata_window = curses.newwin(parent_y - 3, metadata_width,
                                              2, 2 * third_x)

        # update menus if necessary
        if self._queue_menu is not None:
            self._queue_menu.window = self._queue_window
github xgi / castero / castero / perspectives / primaryperspective.py View on Github external
Overrides method from Perspective; see documentation in that class.
        """
        # delete old windows if they exist
        if self._feed_window is not None:
            del self._feed_window
            self._feed_window = None
        if self._episode_window is not None:
            del self._episode_window
            self._episode_window = None
        if self._metadata_window is not None:
            del self._metadata_window
            self._metadata_window = None

        parent_x = self._display.parent_x
        parent_y = self._display.parent_y
        third_x = helpers.third(parent_x)
        self._feed_window = curses.newwin(parent_y - 2, third_x,
                                          2, 0)
        self._episode_window = curses.newwin(parent_y - 2, third_x,
                                             2, third_x)
        metadata_width = parent_x - ((third_x * 2) - 1)
        self._metadata_window = curses.newwin(parent_y - 3, metadata_width,
                                              2, 2 * third_x)

        # update menus if necessary
        if self._feed_menu is not None:
            self._feed_menu.window = self._feed_window
        if self._episode_menu is not None:
            self._episode_menu.window = self._episode_window
github xgi / castero / castero / display.py View on Github external
if helpers.is_true(Config["right_align_time"]):
                playing_str += ("[%s]" % self._queue.first.time_str).rjust(
                    self._header_window.getmaxyx()[1] - len(playing_str))
            else:
                playing_str += " [%s]" % self._queue.first.time_str

        self._header_window.addstr(0, 0,
                                   " " * self._header_window.getmaxyx()[1])
        self._header_window.addstr(0, 0, playing_str,
                                   curses.color_pair(6) | curses.A_BOLD)

        # add footer
        footer_str = ""
        if self._status == "" and not \
                helpers.is_true(Config["disable_default_status"]):
            feeds = self.database.feeds()
            if len(feeds) > 0:
                total_feeds = len(feeds)
                lengths_of_feeds = \
                    [len(self.database.episodes(feed)) for feed in feeds]
                total_episodes = sum(lengths_of_feeds)
                median_episodes = helpers.median(lengths_of_feeds)

                footer_str += "Found %d feeds with %d total episodes (avg." \
                              " %d episodes, med. %d)" % (
                                  total_feeds,
                                  total_episodes,
                                  total_episodes / total_feeds,
                                  median_episodes
                              )
            else: