From cebc77558d247fed359f7a00f06bb9c6a3e4a238 Mon Sep 17 00:00:00 2001 From: Dale Wahl Date: Tue, 16 Apr 2024 12:08:37 +0200 Subject: [PATCH] move writing of module_config.bin to bootstrap --- backend/bootstrap.py | 12 +++++++++++- common/config_manager.py | 8 +++----- common/lib/module_loader.py | 13 ------------- 3 files changed, 14 insertions(+), 19 deletions(-) diff --git a/backend/bootstrap.py b/backend/bootstrap.py index 4b7da388e..9302a369e 100644 --- a/backend/bootstrap.py +++ b/backend/bootstrap.py @@ -1,6 +1,7 @@ """ 4CAT Backend init - used to start the backend! """ +import pickle import shutil import os @@ -10,7 +11,6 @@ from common.lib.database import Database from backend.lib.manager import WorkerManager from common.lib.logger import Logger - from common.config_manager import config def run(as_daemon=True): @@ -66,6 +66,16 @@ def run(as_daemon=True): config.with_db(db) config.ensure_database() + # Load all modules and update config with module-specific settings + from backend import all_modules + module_config = {} + for worker in all_modules.workers.values(): + if hasattr(worker, "config") and type(worker.config) is dict: + module_config.update(worker.config) + with config.get("PATH_ROOT").joinpath("config/module_config.bin").open("wb") as outfile: + pickle.dump(module_config, outfile) + config.load_user_settings() + # make it happen # this is blocking until the back-end is shut down WorkerManager(logger=log, database=db, queue=queue, as_daemon=as_daemon) diff --git a/common/config_manager.py b/common/config_manager.py index 0d8988787..27c457c9c 100644 --- a/common/config_manager.py +++ b/common/config_manager.py @@ -2,17 +2,15 @@ import pickle import time import json - +import configparser +import os from pathlib import Path -from common.lib.database import Database +from common.lib.database import Database from common.lib.exceptions import ConfigException from common.lib.config_definition import config_definition from common.lib.user_input import UserInput -import configparser -import os - class ConfigManager: db = None diff --git a/common/lib/module_loader.py b/common/lib/module_loader.py index 84e5d951e..6a61979bf 100644 --- a/common/lib/module_loader.py +++ b/common/lib/module_loader.py @@ -4,7 +4,6 @@ from pathlib import Path import importlib import inspect -import pickle import sys import re @@ -52,18 +51,6 @@ def __init__(self): # datasources, e.g. whether they have an associated search worker self.expand_datasources() - # cache module-defined config options for use by the config manager - module_config = {} - for worker in self.workers.values(): - if hasattr(worker, "config") and type(worker.config) is dict: - module_config.update(worker.config) - - with config.get("PATH_ROOT").joinpath("config/module_config.bin").open("wb") as outfile: - pickle.dump(module_config, outfile) - - # load from cache - config.load_user_settings() - @staticmethod def is_4cat_class(object, only_processors=False): """