Ejemplo n.º 1
0
    def handle(self):
        import confuse
        from trakt_scrobbler import config

        view = config
        key = self.argument("key")
        values = self.argument("value")
        for name in key.split("."):
            view = view[name]

        try:
            orig_val = view.get()
            if isinstance(orig_val, dict):
                raise confuse.ConfigTypeError
        except confuse.ConfigTypeError:
            raise KeyError(f"{key} is not a valid parameter name.")
        except confuse.NotFoundError:
            value = values[0] if len(values) == 1 else values
            view.add(value)
        else:
            if not isinstance(orig_val, list):
                if len(values) > 1:
                    raise ValueError(
                        "Given parameter only accepts a single value")
                else:
                    value = orig_val.__class__(values[0])
            else:
                if self.option("add"):
                    value = list(set(orig_val).union(values))
                else:
                    value = values
            view.set(value)
        with open(config.user_config_path(), "w") as f:
            f.write(config.dump(full=False))
        self.line(f"User config updated with '{key} = {value}'")
        self.line(
            "Don't forget to restart the service for the changes to take effect."
        )
Ejemplo n.º 2
0
 def save_config(config):
     with open(config.user_config_path(), "w") as f:
         f.write(config.dump(full=False))