From cf26d7aa22ad98314e65e5e267056131da087626 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Diot?= Date: Wed, 10 May 2023 09:45:54 -0400 Subject: [PATCH 1/4] Fix database saving default values to global_values when multisite was set to "no" --- src/common/db/Database.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/common/db/Database.py b/src/common/db/Database.py index 3b4c4cf86..947b66193 100644 --- a/src/common/db/Database.py +++ b/src/common/db/Database.py @@ -569,6 +569,11 @@ class Database: ) if global_value is None: + if value == setting.default or ( + not value.strip() and setting.default is None + ): + continue + to_put.append( Global_values( setting_id=key, From 8a308b1a885085265a9e4af75bb07dbaf4f370bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Diot?= Date: Wed, 10 May 2023 13:10:47 -0400 Subject: [PATCH 2/4] Fix database not providing the right SERVER_NAME setting value --- src/common/db/Database.py | 31 +++++++++++++------------------ 1 file changed, 13 insertions(+), 18 deletions(-) diff --git a/src/common/db/Database.py b/src/common/db/Database.py index 947b66193..01d1a7a19 100644 --- a/src/common/db/Database.py +++ b/src/common/db/Database.py @@ -366,7 +366,10 @@ class Database: .all() ) db_ids = [service.id for service in db_services] - services = config.get("SERVER_NAME", "").split(" ") + services = config.pop("SERVER_NAME", []) + + if isinstance(services, str): + services = services.split(" ") if db_services: missing_ids = [ @@ -376,13 +379,14 @@ class Database: ] if missing_ids: - # Remove plugins that are no longer in the list + # Remove services that are no longer in the list session.query(Services).filter( Services.id.in_(missing_ids) ).delete() for key, value in deepcopy(config).items(): suffix = 0 + original_key = deepcopy(key) if self.suffix_rx.search(key): suffix = int(key.split("_")[-1]) key = key[: -len(str(suffix)) - 1] @@ -475,8 +479,8 @@ class Database: Services_settings.method: method, } ) - elif f"{key}_{suffix}" not in global_values: - global_values.append(f"{key}_{suffix}") + elif setting and original_key not in global_values: + global_values.append(original_key) global_value = ( session.query(Global_values) .with_entities( @@ -489,9 +493,6 @@ class Database: .first() ) - if not setting: - continue - if global_value is None: if value == setting.default or ( not value.strip() and setting.default is None @@ -569,11 +570,6 @@ class Database: ) if global_value is None: - if value == setting.default or ( - not value.strip() and setting.default is None - ): - continue - to_put.append( Global_values( setting_id=key, @@ -627,12 +623,6 @@ class Database: to_put = [] endl = "\n" for custom_config in custom_configs: - # config = { - # "data": custom_config["value"].replace("\\\n", "\n").encode("utf-8") - # if isinstance(custom_config["value"], str) - # else custom_config["value"].replace(b"\\\n", b"\n"), - # "method": method, - # } config = { "data": custom_config["value"].encode("utf-8") if isinstance(custom_config["value"], str) @@ -806,6 +796,11 @@ class Database: } ) + servers = " ".join(service.id for service in session.query(Services).all()) + config["SERVER_NAME"] = ( + servers if methods is False else {"value": servers, "method": "default"} + ) + return config def get_custom_configs(self) -> List[Dict[str, Any]]: From 905946463dec59b6de58813e5f7ccbb62a397439 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Diot?= Date: Wed, 10 May 2023 13:11:09 -0400 Subject: [PATCH 3/4] Fix scheduler restarting for no reason when having an external database --- src/scheduler/main.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/scheduler/main.py b/src/scheduler/main.py index dc373fd09..2e1ae23b3 100644 --- a/src/scheduler/main.py +++ b/src/scheduler/main.py @@ -511,6 +511,9 @@ if __name__ == "__main__": # check if the config have changed since last time tmp_env = db.get_config() + tmp_env["DATABASE_URI"] = environ.get( + "DATABASE_URI", tmp_env["DATABASE_URI"] + ) if env != tmp_env: logger.info("Config changed, generating ...") logger.debug(f"{tmp_env=}") From ca8c56aaa03e640e20d41b78f726b944fa160063 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Diot?= Date: Wed, 10 May 2023 13:11:34 -0400 Subject: [PATCH 4/4] Remove unused function in UI src.Config --- src/ui/src/Config.py | 26 -------------------------- 1 file changed, 26 deletions(-) diff --git a/src/ui/src/Config.py b/src/ui/src/Config.py index 4eea61142..1782f5afd 100644 --- a/src/ui/src/Config.py +++ b/src/ui/src/Config.py @@ -21,32 +21,6 @@ class Config: self.__db = db - def __env_to_dict(self, filename: str) -> dict: - """Converts the content of an env file into a dict - - Parameters - ---------- - filename : str - the path to the file to convert to dict - - Returns - ------- - dict - The values of the file converted to dict - """ - if not Path(filename).is_file(): - return {} - - data = {} - for line in Path(filename).read_text().split("\n"): - if not "=" in line: - continue - var = line.split("=")[0] - val = line.replace(f"{var}=", "", 1) - data[var] = val - - return data - def __dict_to_env(self, filename: str, variables: dict) -> None: """Converts the content of a dict into an env file