Пример #1
0
    def handle(self):
        import confuse
        from trakt_scrobbler import config

        key = self.argument("key")
        *parts, name = key.split(".")
        sources = [s for s in config.sources if not s.default]
        temp_root = confuse.RootView(sources)
        view = temp_root
        for part in parts:
            view = view[part]
        view = view[name]
        try:
            view.get()
        except confuse.NotFoundError:
            self.line(f"<info>{key}</> not found in user config.", "error")
            self.line(f"Run <question>{CMD_NAME} config list</> to see all user-defined values.")
            return 1

        for src in temp_root.sources:
            for part in parts:
                src = src[part]
            if name in src:
                del src[name]

        ConfigCommand.save_config(config)

        self.line(f"Successfully unset <info>{key}</>")
Пример #2
0
    def handle(self):
        import confuse
        from trakt_scrobbler import config

        if self.option("all"):
            self._print_cfg(config.flatten())
        else:
            sources = [s for s in config.sources if not s.default]
            temp_root = confuse.RootView(sources)
            self._print_cfg(temp_root.flatten())
Пример #3
0
    def test_number_keywords_template(self):
        data = confuse.ConfigSource.of({1: ["test"], 2: 'test'})
        view = confuse.RootView([data])
        view.set(data)
        r = view.get(NumberKeywordsTemplate())

        self.assertDictEqual(r, {1: ["test"], 2: ["test"]})

        self.assertEqual(str(NumberKeywordsTemplate()),
                         'NumberKeywordsTemplate()')

        view.set(confuse.ConfigSource.of({'not_int': ["test"], 2: 'test'}))
        with self.assertRaises(confuse.ConfigTypeError):
            r = view.get(NumberKeywordsTemplate())
Пример #4
0
        def run_with_except_hook(*args2, **kwargs2):
            try:
                run_original(*args2, **kwargs2)
            except Exception:
                sys.excepthook(*sys.exc_info())
                return

        self.run = run_with_except_hook

    threading.Thread.__init__ = init


logging.config.dictConfig(LOGGING_CONF)
logger = logging.getLogger("trakt_scrobbler")

register_exception_handler()

confuse.OrderedDict = dict
config = confuse.Configuration("trakt-scrobbler", "trakt_scrobbler")

# copy version from default config to user config if not present
temp_root = confuse.RootView(s for s in config.sources if not s.default)
if "version" not in temp_root:
    temp_root["version"] = config["version"].get()
    with open(config.user_config_path(), "w") as f:
        yaml.dump(temp_root.flatten(), f)
elif temp_root["version"].get() != config.sources[-1]["version"]:
    logger.warning(
        "Config version mismatch! Check configs at "
        f"{config.sources[-1].filename} and {config.user_config_path()}")