diff --git a/plextraktsync/cli.py b/plextraktsync/cli.py index d2e5177738..956df18c4f 100644 --- a/plextraktsync/cli.py +++ b/plextraktsync/cli.py @@ -324,6 +324,7 @@ def watched_shows(): @command() +@click.option("--urls-expire-after", is_flag=True, help="Print urls_expire_after configuration") def config(): """ Print user config for debugging and bug reports. diff --git a/plextraktsync/commands/config.py b/plextraktsync/commands/config.py index 0867b27370..a2c145419a 100644 --- a/plextraktsync/commands/config.py +++ b/plextraktsync/commands/config.py @@ -1,12 +1,27 @@ from plextraktsync.console import print -def config(print=print): +def dump(data, print=None): + """ + Print config serialized as yaml. + If print is None, return the produced string instead. + """ + from plextraktsync.config.ConfigLoader import ConfigLoader + + dump = ConfigLoader.dump_yaml(None, data) + if print is None: + return dump + print(dump) + + +def config(urls_expire_after: bool, print=print): from plextraktsync.factory import factory config = factory.config - print(f"# Config File: {config.config_yml}") - config.dump(print=print) + if urls_expire_after: + print("# HTTP Cache") + dump(config.http_cache.serialize(), print=print) + return - print("# HTTP Cache") - config.http_cache.dump(print=print) + print(f"# Config File: {config.config_yml}") + dump(config.serialize(), print=print) diff --git a/plextraktsync/config/Config.py b/plextraktsync/config/Config.py index 9e838fc1d6..21b4865bdc 100644 --- a/plextraktsync/config/Config.py +++ b/plextraktsync/config/Config.py @@ -130,7 +130,7 @@ def initialize(self): "$PTS_CACHE_DIR", cache_dir ) - def dump(self, print=None): + def serialize(self): """ Print config serialized as yaml. If print is None, return the produced string instead. @@ -138,6 +138,10 @@ def dump(self, print=None): data = dict(self) for key in self.env_keys: del data[key] + return data + + def dump(self, print=None): + data = self.serialize() dump = ConfigLoader.dump_yaml(None, data) if print is None: return dump diff --git a/plextraktsync/config/HttpCacheConfig.py b/plextraktsync/config/HttpCacheConfig.py index af23c83761..b68128a05f 100644 --- a/plextraktsync/config/HttpCacheConfig.py +++ b/plextraktsync/config/HttpCacheConfig.py @@ -105,17 +105,20 @@ def urls_expire_after(self) -> ExpirationPatterns: return policy + def serialize(self): + return { + "http_cache": { + "policy": self.urls_expire_after, + }, + } + def dump(self, print=None): """ Print config serialized as yaml. If print is None, return the produced string instead. """ from plextraktsync.config.ConfigLoader import ConfigLoader - data = { - "http_cache": { - "policy": self.urls_expire_after, - }, - } + data = self.serialize() dump = ConfigLoader.dump_yaml(None, data) if print is None: return dump