From 1d6693bdca31ae9e14dfca3c379074ac08cdb19e Mon Sep 17 00:00:00 2001 From: Alexis Koralewski Date: Mon, 25 Sep 2023 16:49:52 +0200 Subject: [PATCH] Rework Fn context in obsconfig_class --- src/core/pyros_django/obs_config/obsconfig_class.py | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) diff --git a/src/core/pyros_django/obs_config/obsconfig_class.py b/src/core/pyros_django/obs_config/obsconfig_class.py index 89949c9..69e3ddf 100644 --- a/src/core/pyros_django/obs_config/obsconfig_class.py +++ b/src/core/pyros_django/obs_config/obsconfig_class.py @@ -277,7 +277,7 @@ class OBSConfig: config_file = yaml.safe_load(stream) self.DJANGO_PATH = os.environ.get( - "DJANGO_PATH", os.path.abspath(os.path.dirname(yaml_file))) + "DJANGO_PATH", "..") self.SCHEMA_PATH = os.path.join( self.DJANGO_PATH, "../../../config/pyros_observatory/general/schemas/") self.CONFIG_PATH = self.obs_config_path @@ -301,19 +301,19 @@ class OBSConfig: def channel_fn_context(self, fn_context:dict): - fn = FileNames() for context, values in fn_context.items(): - fn.fcontext_create(context, values["description"]) - fn.fcontext = context + self.fn.fcontext_create(context, values["description"]) + self.fn.fcontext = context if values.get("naming"): - fn.naming(values["naming"]) + self.fn.naming(values["naming"]) elif values.get("pathnaming"): - fn.pathnaming(values["pathnaming"]) + self.fn.pathnaming(values["pathnaming"]) root_project_path = os.environ.get("PROJECT_ROOT_PATH", os.path.join(os.getcwd(), "../../../../")) - fn.rootdir = os.path.join(root_project_path, values["root_dir"]) - os.makedirs(fn.rootdir, exist_ok=True) - fn.extension = values["extension"] - return fn + data_path = os.path.join(root_project_path, "..", "..", "DATA") + self.fn.rootdir = os.path.join(data_path, values["root_dir"]) + os.makedirs(self.fn.rootdir, exist_ok=True) + self.fn.extension = values["extension"] + def read_generic_component_and_return_attributes(self, component_name: str) -> dict: file_path = self.COMPONENT_PATH + component_name + ".yml" @@ -615,11 +615,13 @@ class OBSConfig: fn.naming(values["naming"]) elif values.get("pathnaming"): fn.pathnaming(values["pathnaming"]) - root_project_path = os.environ.get("PROJECT_ROOT_PATH") - data_path = os.path.join(root_project_path, "..", "DATA") + root_project_path = os.environ.get("PROJECT_ROOT_PATH",os.path.join(os.getcwd(), "../../../../")) + data_path = os.path.join(root_project_path, "..", "..", "DATA") fn.rootdir = os.path.join(data_path, values["root_dir"]) fn.extension = values["extension"] self.fn = fn + # call get_channels to add their filenames to the global filenames of obsconfig + self.get_channels(self.unit_name) def get_obs_name(self) -> str: @@ -646,8 +648,7 @@ class OBSConfig: for channel_id in range(len(unit["TOPOLOGY"]["CHANNELS"])): channel_fcontext = unit["TOPOLOGY"]["CHANNELS"][channel_id]["CHANNEL"].get("fn_contexts") if channel_fcontext is not None: - fn = self.channel_fn_context(channel_fcontext) - channel_fcontext = unit["TOPOLOGY"]["CHANNELS"][channel_id]["CHANNEL"]["fn_contexts"] = fn + self.channel_fn_context(channel_fcontext) channel = unit["TOPOLOGY"]["CHANNELS"][channel_id]["CHANNEL"] channels[channel["name"]] = channel @@ -1449,9 +1450,13 @@ def main(): # print(config.get_channel_groups(unit_name)) # print(config.getEditableAttributesOfCapability(config.getChannelCapabilities(unit_name,"OpticalChannel_up")[0])) # print(config.getEditableChannelAttributes(unit_name,"OpticalChannel_up")) - config = OBSConfig("../../../../../PYROS_OBSERVATORY/pyros_observatory_tnc/config/observatory_tnc.yml") + config = OBSConfig("../../../../../PYROS_OBSERVATORY/pyros_observatory_tnc/observatory.yml") unit_name = config.get_units_name()[0] - print(config.get_channel_of_agent("A_AgentImagesProcessor_up1_akz")) + print(config.fn.fcontexts) + config.fn.fcontext = "pyros_seq" + print(config.fn) + print(config.fn.naming_keys()) + #print(config.get_channel_of_agent("A_ImagesProcessor_up1_akz")) # print(config.get_channels(unit_name)) # print(config.get_components_agents(unit_name)) # dc = config.getDeviceControllerNameForAgent(unit_name,"mount")[0] -- libgit2 0.21.2