How to use the castero.config.Config 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_player.py View on Github external
def test_player_create_instance_success_indirect():
    Config.data = {'player': ''}
    Player.create_instance(available_players, "t", "p", episode)
    SomePlayer.check_dependencies.assert_called = 2
    SomePlayer.assert_called_with("t", "p", episode)
github xgi / castero / tests / test_perspective_primary.py View on Github external
def test_perspective_primary_input_keys(display):
    perspective = get_primary_perspective(display)

    display._footer_window.getch = mock.MagicMock(return_value=10)

    ret_val = perspective.handle_input(ord('q'))
    assert not ret_val
    display._stdscr.reset_mock()

    ret_val = perspective.handle_input(ord('h'))
    assert ret_val
    display._stdscr.timeout.assert_any_call(-1)
    display._stdscr.reset_mock()

    movement_keys = [
        display.KEY_MAPPING[Config['key_up']],
        display.KEY_MAPPING[Config['key_right']],
        display.KEY_MAPPING[Config['key_down']],
        display.KEY_MAPPING[Config['key_left']],
        display.KEY_MAPPING[Config['key_scroll_up']],
        display.KEY_MAPPING[Config['key_scroll_down']],
    ]
    for key in movement_keys:
        perspective._metadata_updated = True
        ret_val = perspective.handle_input(key)
        assert ret_val
        assert not perspective._metadata_updated

    operation_keys = [
        display.KEY_MAPPING[Config['key_add_feed']],
        display.KEY_MAPPING[Config['key_delete']],
        display.KEY_MAPPING[Config['key_reload']],
github xgi / castero / tests / test_perspective_primary.py View on Github external
display.KEY_MAPPING[Config['key_scroll_down']],
    ]
    for key in movement_keys:
        perspective._metadata_updated = True
        ret_val = perspective.handle_input(key)
        assert ret_val
        assert not perspective._metadata_updated

    operation_keys = [
        display.KEY_MAPPING[Config['key_add_feed']],
        display.KEY_MAPPING[Config['key_delete']],
        display.KEY_MAPPING[Config['key_reload']],
        display.KEY_MAPPING[Config['key_save']],
        display.KEY_MAPPING[Config['key_play_selected']],
        display.KEY_MAPPING[Config['key_add_selected']],
        display.KEY_MAPPING[Config['key_clear']],
        display.KEY_MAPPING[Config['key_next']],
        display.KEY_MAPPING[Config['key_invert']],
        display.KEY_MAPPING[Config['key_pause_play']],
        display.KEY_MAPPING[Config['key_pause_play_alt']],
        display.KEY_MAPPING[Config['key_seek_forward']],
        display.KEY_MAPPING[Config['key_seek_forward_alt']],
        display.KEY_MAPPING[Config['key_seek_backward']],
        display.KEY_MAPPING[Config['key_seek_backward_alt']],
        display.KEY_MAPPING[Config['key_mark_played']],
    ]
    for key in operation_keys:
        display._active_window = 0
        assert perspective.handle_input(key)
        display._active_window = 1
        assert perspective.handle_input(key)
github xgi / castero / tests / test_config.py View on Github external
def test_migrate_stability():
    conf = configparser.ConfigParser()
    default_conf = configparser.ConfigParser()
    default_conf.read(config._Config.DEFAULT_PATH)
    conf.read(my_dir + "/datafiles/working_no_comments.conf")

    conf.read = mock.MagicMock()

    with patch("builtins.open", mock_open(read_data="test")) as mock_file:
        config.Config.migrate(conf, default_conf)
        mock_file.assert_called_with(config.Config.DEFAULT_PATH, 'w')
github xgi / castero / tests / test_perspective_simple.py View on Github external
display.KEY_MAPPING[Config['key_left']],
        display.KEY_MAPPING[Config['key_scroll_up']],
        display.KEY_MAPPING[Config['key_scroll_down']],
    ]
    for key in movement_keys:
        perspective._metadata_updated = True
        ret_val = perspective.handle_input(key)
        assert ret_val

    operation_keys = [
        display.KEY_MAPPING[Config['key_add_feed']],
        display.KEY_MAPPING[Config['key_delete']],
        display.KEY_MAPPING[Config['key_reload']],
        display.KEY_MAPPING[Config['key_save']],
        display.KEY_MAPPING[Config['key_play_selected']],
        display.KEY_MAPPING[Config['key_add_selected']],
        display.KEY_MAPPING[Config['key_clear']],
        display.KEY_MAPPING[Config['key_next']],
        display.KEY_MAPPING[Config['key_invert']],
        display.KEY_MAPPING[Config['key_pause_play']],
        display.KEY_MAPPING[Config['key_pause_play_alt']],
        display.KEY_MAPPING[Config['key_seek_forward']],
        display.KEY_MAPPING[Config['key_seek_forward_alt']],
        display.KEY_MAPPING[Config['key_seek_backward']],
        display.KEY_MAPPING[Config['key_seek_backward_alt']],
        display.KEY_MAPPING[Config['key_seek_backward_alt']],
        display.KEY_MAPPING[Config['key_mark_played']],
    ]
    for key in operation_keys:
        display._active_window = 0
        assert perspective.handle_input(key)
        display._active_window = 1
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 / database.py View on Github external
else:
                new_feed = Feed(file=feed.key)

            # keep user metadata for episodes intact
            new_episodes = new_feed.parse_episodes()
            old_episodes = self.episodes(feed)
            for new_ep in new_episodes:
                matching_olds = [
                    old_ep for old_ep in old_episodes if
                    str(old_ep) == str(new_ep)
                ]
                if len(matching_olds) == 1:
                    new_ep.replace_from(matching_olds[0])

            # limit number of episodes, if necessary
            max_episodes = int(Config["max_episodes"])
            if max_episodes != -1:
                new_episodes = new_episodes[:max_episodes]

            self.replace_feed(new_feed)
            self.replace_episodes(new_feed, new_episodes)

        if display is not None:
            display.change_status("Feeds successfully reloaded")
            display.menus_valid = False
github xgi / castero / castero / perspective.py View on Github external
queue.toggle()
        elif c == key_mapping[Config['key_next']]:
            queue.stop()
            queue.next()
            queue.play()
        elif c == key_mapping[Config['key_seek_forward']] or \
                c == key_mapping[Config['key_seek_forward_alt']]:
            queue.seek(1)
        elif c == key_mapping[Config['key_seek_backward']] or \
                c == key_mapping[Config['key_seek_backward_alt']]:
            queue.seek(-1)
        elif c == key_mapping[Config['key_rate_increase']]:
            queue.change_rate(1, display=self._display)
        elif c == key_mapping[Config['key_rate_decrease']]:
            queue.change_rate(-1, display=self._display)
        elif c == key_mapping[Config['key_add_feed']]:
            self._display.add_feed()
        elif c == key_mapping[Config['key_delete']]:
            if self._active_window == 0:
                self._display.delete_feed(self._feed_menu.item)
                self.update_menus()
        elif c == key_mapping[Config['key_reload']]:
            self._display.reload_feeds()
        elif c == key_mapping[Config['key_save']]:
            if self._active_window == 0 and self._feed_menu.item:
                self._display.save_episodes(feed=self._feed_menu.item)
            elif self._active_window == 1 and self._episode_menu.item:
                self._display.save_episodes(episode=self._episode_menu.item)
        elif c == key_mapping[Config['key_invert']]:
            self._invert_selected_menu()
        elif c == key_mapping[Config['key_filter']]:
            menu = self._get_active_menu()
github xgi / castero / castero / queue.py View on Github external
def play(self) -> None:
        """Plays the first player in the queue.
        """
        if self.first is not None:
            self.first.episode.played = True
            self._display.modified_episodes.append(self.first.episode)
            self.first.play()
            self.first.set_rate(float(Config["default_playback_speed"]))