Commit 57dc2da15fb9aac240cb46073a2ecb597b03eb6b

Authored by Alexis Koralewski
1 parent d83ed1cb
Exists in dev

Add fn context to channels in obsconfig class

CHANGELOG
  1 +01-09-2023 (AKo): V0.6.29.0
  2 + - Add fn context to channels in obsconfig class
  3 +
1 4 28-07-2023 (AKo): V0.6.28.0
2 5 - Add command in A_SCP_Manager to generate ephemeris files of sun & moon for a period
3 6 - Fix AgentSST start one agent
4 7 - Fix config_pyros paths
5 8 - Fix JS of agent_detail
  9 + - Add Scheduler models
6 10  
7 11 26-07-2023 (AKo): V0.6.27.0
8 12 - Remove private & privatedev folder
... ...
src/core/pyros_django/obs_config/obsconfig_class.py
... ... @@ -11,6 +11,8 @@ from datetime import datetime
11 11 from pykwalify.errors import PyKwalifyException, SchemaError
12 12 from pathlib import Path
13 13  
  14 +sys.path.append(os.environ.get("PROJECT_ROOT_PATH", os.path.join(os.getcwd(),"../../../../")))
  15 +from vendor.guitastro.src.guitastro import FileNames
14 16  
15 17 class OBSConfig:
16 18 # (AKo) : Config file path is checked on the settings file, if the file isn't valid (i.e not found) the error will be launched by the settings file when starting the application
... ... @@ -296,7 +298,22 @@ class OBSConfig:
296 298 except Exception as e:
297 299 print(e)
298 300 return None
299   -
  301 +
  302 +
  303 + def channel_fn_context(self, fn_context:dict):
  304 + fn = FileNames()
  305 + for context, values in fn_context.items():
  306 + fn.fcontext_create(context, values["description"])
  307 + fn.fcontext = context
  308 + if values.get("naming"):
  309 + fn.naming(values["naming"])
  310 + elif values.get("pathnaming"):
  311 + fn.pathnaming(values["pathnaming"])
  312 + root_project_path = os.environ.get("PROJECT_ROOT_PATH", os.path.join(os.getcwd(), "../../../../"))
  313 + fn.rootdir = os.path.join(root_project_path, values["root_dir"])
  314 + fn.extension = values["extension"]
  315 + return fn
  316 +
300 317 def read_generic_component_and_return_attributes(self, component_name: str) -> dict:
301 318 file_path = self.COMPONENT_PATH + component_name + ".yml"
302 319 try:
... ... @@ -611,8 +628,13 @@ class OBSConfig:
611 628 channels = {}
612 629  
613 630 for channel_id in range(len(unit["TOPOLOGY"]["CHANNELS"])):
  631 + channel_fcontext = unit["TOPOLOGY"]["CHANNELS"][channel_id]["CHANNEL"].get("fn_contexts")
  632 + if channel_fcontext is not None:
  633 + fn = self.channel_fn_context(channel_fcontext)
  634 + channel_fcontext = unit["TOPOLOGY"]["CHANNELS"][channel_id]["CHANNEL"]["fn_contexts"] = fn
614 635 channel = unit["TOPOLOGY"]["CHANNELS"][channel_id]["CHANNEL"]
615 636 channels[channel["name"]] = channel
  637 +
616 638 return channels
617 639  
618 640 def get_computers(self) -> dict:
... ... @@ -837,6 +859,7 @@ class OBSConfig:
837 859 else:
838 860 for channel in topology[element]:
839 861 for component_agent in topology[element][channel]["AGENTS"]:
  862 + print(component_agent)
840 863 component_name = list(component_agent.keys())[0]
841 864 components_agents[component_name] = component_agent[component_name]
842 865 return components_agents
... ... @@ -1359,6 +1382,21 @@ class OBSConfig:
1359 1382 return computer_agent_name
1360 1383 return agent_name
1361 1384  
  1385 + def get_channel_of_agent(self, agent_name:str)->dict:
  1386 + """
  1387 + Return channel element of associated agent
  1388 +
  1389 + Args:
  1390 + agent_name (str): name of agent
  1391 +
  1392 + Returns:
  1393 + dict: Channel element
  1394 + """
  1395 + channels = self.get_channels(self.unit_name)
  1396 + for channel in channels:
  1397 + if agent_name in channels[channel]["AGENTS"]:
  1398 + return channels[channel]
  1399 + return None
1362 1400  
1363 1401 class MissingMandatoryAgentException(Exception):
1364 1402 """
... ... @@ -1380,8 +1418,11 @@ def main():
1380 1418 # print(config.get_channel_groups(unit_name))
1381 1419 # print(config.getEditableAttributesOfCapability(config.getChannelCapabilities(unit_name,"OpticalChannel_up")[0]))
1382 1420 # print(config.getEditableChannelAttributes(unit_name,"OpticalChannel_up"))
1383   - config = OBSConfig("../../../../privatedev/config/tnc/observatory_tnc.yml")
  1421 + config = OBSConfig("../../../../../PYROS_OBSERVATORY/pyros_observatory_tnc/config/observatory_tnc.yml")
1384 1422 unit_name = config.get_units_name()[0]
  1423 + print(config.get_channel_of_agent("A_AgentImagesProcessor_up1_akz"))
  1424 + # print(config.get_channels(unit_name))
  1425 + # print(config.get_components_agents(unit_name))
1385 1426 # dc = config.getDeviceControllerNameForAgent(unit_name,"mount")[0]
1386 1427 # print(config.getDeviceConfigForDeviceController(dc))
1387 1428 # print(config.getCommParamsForAgentDevice(unit_name,"mount"))
... ... @@ -1390,11 +1431,11 @@ def main():
1390 1431 # print(config.getEditableAttributesOfCapability(config.getChannelCapabilities(unit_name,"OpticalChannel_down2")[0]))
1391 1432 # print(config.getEditableChannelAttributesnit_name,"OpticalChannel_down2"))
1392 1433 #print(config.getEditableMountAttributes(unit_name))
1393   - config.get_devices()
  1434 + # config.get_devices()
1394 1435  
1395 1436 #print(config.get_output_data_device("TAROT_meteo").get("CV7"))
1396   - print(config.get_device_for_agent(config.unit_name, "AgentDevicePLC_ako").get("device_config").F[0].get("output_data").get("Raspberry").keys())
1397   - print(config.get_monitoring_devices())
  1437 + # print(config.get_device_for_agent(config.unit_name, "AgentDevicePLC_ako").get("device_config").F[0].get("output_data").get("Raspberry").keys())
  1438 + # print(config.get_monitoring_devices())
1398 1439 #.get("/entities/devices/CV7/Error_code").keys())
1399 1440 #print(config.get_device_capabilities("TAROT_meteo"))
1400 1441 # print(config.get_devices()["FLI-Kepler4040"]["device_config"])
... ...