From c4077e0176b8fcb19bb5651406727353da3f45c6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elan=20Ruusam=C3=A4e?= Date: Sun, 14 Jan 2024 17:06:45 +0200 Subject: [PATCH] Refactor: Add get_section to add common code for get section config --- plextraktsync/config/PlexServerConfig.py | 19 ++++++++----------- 1 file changed, 8 insertions(+), 11 deletions(-) diff --git a/plextraktsync/config/PlexServerConfig.py b/plextraktsync/config/PlexServerConfig.py index 56080dbee64..f76c4f2ca87 100644 --- a/plextraktsync/config/PlexServerConfig.py +++ b/plextraktsync/config/PlexServerConfig.py @@ -24,21 +24,18 @@ def asdict(self): @property def sync_config(self): - if self.config is None or "sync" not in self.config or self.config["sync"] is None: - return {} - - return self.config["sync"] + return self.get_section("sync", {}) @property def libraries(self): - if self.config is None or "libraries" not in self.config: - return None - - return self.config["libraries"] + return self.get_section("libraries") @property def excluded_libraries(self): - if self.config is None or "excluded-libraries" not in self.config: - return None + return self.get_section("excluded-libraries") + + def get_section(self, section: str, default=None): + if self.config is None: + return default - return self.config["excluded-libraries"] + return self.config.get(section, default)