From 21ebde15604ebd5fd00490e78863b5f7f8b52b4e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Thu, 22 Dec 2022 15:56:59 +0200 Subject: [PATCH 1/6] Add generic dump to config command --- plextraktsync/commands/config.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/plextraktsync/commands/config.py b/plextraktsync/commands/config.py index 0867b27370..b8fd428ee3 100644 --- a/plextraktsync/commands/config.py +++ b/plextraktsync/commands/config.py @@ -1,6 +1,19 @@ from plextraktsync.console import 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(print=print): from plextraktsync.factory import factory config = factory.config From 2c7c09d7026b6f7fa8746f5f2cc635ea49035a7f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Thu, 22 Dec 2022 15:59:26 +0200 Subject: [PATCH 2/6] Add --urls-expires-after flag to config --- plextraktsync/cli.py | 1 + plextraktsync/commands/config.py | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) 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 b8fd428ee3..04fcc8213f 100644 --- a/plextraktsync/commands/config.py +++ b/plextraktsync/commands/config.py @@ -14,7 +14,7 @@ def dump(data, print=None): print(dump) -def config(print=print): +def config(urls_expire_after: bool, print=print): from plextraktsync.factory import factory config = factory.config From 214ab241b60a4d28eea6bea8486cba68f44880e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Thu, 22 Dec 2022 16:00:04 +0200 Subject: [PATCH 3/6] Print urls_expire_after only with a flag --- plextraktsync/commands/config.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/plextraktsync/commands/config.py b/plextraktsync/commands/config.py index 04fcc8213f..bd75d848ac 100644 --- a/plextraktsync/commands/config.py +++ b/plextraktsync/commands/config.py @@ -18,8 +18,10 @@ def config(urls_expire_after: bool, print=print): from plextraktsync.factory import factory config = factory.config + if urls_expire_after: + print("# HTTP Cache") + config.http_cache.dump(print=print) + return + print(f"# Config File: {config.config_yml}") config.dump(print=print) - - print("# HTTP Cache") - config.http_cache.dump(print=print) From ac4b428039bfdf262f4e6edb26e73f76c5e69e1c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Thu, 22 Dec 2022 16:05:28 +0200 Subject: [PATCH 4/6] Config: Extract serialize from dump --- plextraktsync/config/Config.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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 From 13a1fe1cc958b3c49e4cedf4acdb6c94dd12b53d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Thu, 22 Dec 2022 16:07:51 +0200 Subject: [PATCH 5/6] HttpCacheConfig: Extract serialize from dump --- plextraktsync/config/HttpCacheConfig.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) 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 From bdddd6a1f7b1b3fe112eeeec5955ff339552ae05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Thu, 22 Dec 2022 16:08:56 +0200 Subject: [PATCH 6/6] Use local dump in config command --- plextraktsync/commands/config.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/plextraktsync/commands/config.py b/plextraktsync/commands/config.py index bd75d848ac..a2c145419a 100644 --- a/plextraktsync/commands/config.py +++ b/plextraktsync/commands/config.py @@ -20,8 +20,8 @@ def config(urls_expire_after: bool, print=print): if urls_expire_after: print("# HTTP Cache") - config.http_cache.dump(print=print) + dump(config.http_cache.serialize(), print=print) return print(f"# Config File: {config.config_yml}") - config.dump(print=print) + dump(config.serialize(), print=print)