diff --git a/CHANGELOG b/CHANGELOG index 1c65804..c0943fb 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,12 @@ +01-09-2023 (AKo): V0.6.30.0 + - Add install-dependecies command + - Move obsconfig/config folder into obsconfig + 01-09-2023 (AKo): V0.6.29.0 - Add fn context to channels in obsconfig class - + - Add makedirs in fn_context definition + - Fix agent protocol path in A_SST + 28-07-2023 (AKo): V0.6.28.0 - Add command in A_SCP_Manager to generate ephemeris files of sun & moon for a period - Fix AgentSST start one agent diff --git a/pyros.py b/pyros.py index 6b10326..59f3bce 100755 --- a/pyros.py +++ b/pyros.py @@ -60,8 +60,8 @@ AGENTS = { "AgentM": "env_monitor", "AgentSP": "scientific_programs", "AgentScheduler": "scheduling", - "AgentImagesProcessor": "observation_manager", - "AgentImagesCalibrator": "observation_manager", + "AgentImagesProcessor": "img_process", + "AgentImagesCalibrator": "img_analysis", "A_SST": "majordome/agent", "Agent": "majordome/agent", "Agent2": "majordome/agent", @@ -815,6 +815,84 @@ def initdb(): return True + +@pyros_launcher.command(help="Install dependencies") +# @global_test_options +@click.option('--observatory', '-o', help='the observatory name to be used') +@click.option('--unit', '-u', help='the unit name to be used') +@click.option("--foreground","-fg", is_flag=True, help="Print stdout and error in terminal") +def install_dependencies(observatory: str, unit: str, foreground: bool): + if observatory == None or len(observatory) == 0: + observatory = "default" + default_obsconfig_folder = os.path.join( + os.path.abspath(PYROS_DJANGO_BASE_DIR), "../../../config/pyros_observatory/") + path_to_obs_config_folder = default_obsconfig_folder+"pyros_observatory_"+observatory+"/" + else: + observatories_configuration_folder = os.path.join( + os.path.abspath(PYROS_DJANGO_BASE_DIR), "../../../../PYROS_OBSERVATORY/") + if len(glob.glob(observatories_configuration_folder+"pyros_observatory_"+observatory+"/")) != 1: + # Observatory configuration folder not found + print( + f"Observatory configuration folder for observatory '{observatory}' not found in {observatories_configuration_folder}") + print("Available observatories configuration :") + for obs_conf_folder in os.listdir(observatories_configuration_folder): + print(obs_conf_folder) + exit(1) + + path_to_obs_config_folder = observatories_configuration_folder+"pyros_observatory_"+observatory + obs_config_file_name = "" + # Search for observatory config file + obs_config_file_name = glob.glob( + path_to_obs_config_folder+"/observatory*.yml")[0] + + obs_config_file_path = os.path.join( + path_to_obs_config_folder, obs_config_file_name) + os.environ["PATH_TO_OBSCONF_FILE"] = obs_config_file_path + os.environ["PATH_TO_OBSCONF_FOLDER"] = path_to_obs_config_folder + os.environ["unit_name"] = unit if unit else '' + + # add path to pyros_django folder as the config class is supposed to work within this folder + cmd_test_obs_config = f"-c \"from src.core.pyros_django.obs_config.obsconfig_class import OBSConfig\nOBSConfig('{obs_config_file_path}')\"" + if not execProcessFromVenv(cmd_test_obs_config,foreground=True): + # Observatory configuration has an issue + exit(1) + else: + from src.core.pyros_django.obs_config.obsconfig_class import OBSConfig + try: + from git import Repo, GitError + except: + pip = "pip" if IS_WINDOWS else "pip3" + if WITH_DOCKER: + process = subprocess.Popen( + pip + " install --user --upgrade GitPython", shell=True) + else: + process = subprocess.Popen( + pip + " install --upgrade GitPython", shell=True) + process.wait() + if process.returncode == 0: + # self.addExecuted(self.current_command, command) + from git import Repo, GitError + else: + log.error("GitPython package (required for obsconfig class) installation failed") + VENDOR_PATH = os.path.join(os.getcwd(), "./vendor/") + import socket + obsconfig = OBSConfig(obs_config_file_path) + computer_hostname = socket.gethostname() + dependencies = obsconfig.get_dependencies() + for computer_name in obsconfig.get_computers().keys(): + if computer_hostname == obsconfig.get_computers().get(computer_name).get("computer_config").get("hostname"): + computer = computer_name + os.chdir("vendor") + for dependency in dependencies: + if computer in dependency["computers"]: + for cmd in dependency["commands"]: + print(cmd) + process = subprocess.Popen(cmd, shell=True) + process.wait() + if process.returncode == 0: + continue + + @pyros_launcher.command(help="Launch an agent") # @global_test_options @click.argument('agent') @@ -881,7 +959,7 @@ def start(agent: str, configfile: str, observatory: str, unit: str, computer_hos print(obs_conf_folder) exit(1) - path_to_obs_config_folder = observatories_configuration_folder+"pyros_observatory_"+observatory+"/config/" + path_to_obs_config_folder = observatories_configuration_folder+"pyros_observatory_"+observatory obs_config_file_name = "" # Search for observatory config file obs_config_file_name = glob.glob( @@ -1096,7 +1174,7 @@ def new_start(configfile: str, observatory: str, unit: str, computer_hostname: s print(obs_conf_folder) exit(1) - path_to_obs_config_folder = observatories_configuration_folder+"pyros_observatory_"+observatory+"/config/" + path_to_obs_config_folder = observatories_configuration_folder+"pyros_observatory_"+observatory obs_config_file_name = "" # Search for observatory config file obs_config_file_name = glob.glob( diff --git a/src/core/pyros_django/obs_config/obsconfig_class.py b/src/core/pyros_django/obs_config/obsconfig_class.py index f017bfd..7bc7a61 100644 --- a/src/core/pyros_django/obs_config/obsconfig_class.py +++ b/src/core/pyros_django/obs_config/obsconfig_class.py @@ -901,11 +901,13 @@ class OBSConfig: agents = self.get_agents(self.unit_name) for agent in agents: computer_name = agents[agent]["computer"] - computer_hostname = self.get_computers().get(computer_name).get("computer_config").get("hostname") - if(computer_hostname not in agents_per_computer.keys()): - agents_per_computer[computer_hostname] = [agent] - else: - agents_per_computer[computer_hostname].append(agent) + # computer_name is a string so we have to check if it's different of string None + if computer_name != "None": + computer_hostname = self.get_computers().get(computer_name).get("computer_config").get("hostname") + if(computer_hostname not in agents_per_computer.keys()): + agents_per_computer[computer_hostname] = [agent] + else: + agents_per_computer[computer_hostname].append(agent) return agents_per_computer def get_agents_per_device(self, unit_name: str) -> dict: @@ -1319,22 +1321,26 @@ class OBSConfig: dependencies = self.get_unit_by_name(unit).get("DEPENDENCIES") dependencies_return = [] for dependency in dependencies: + dependency = dependency.get("DEPENDENCY") computers = dependency.get("computers") commands = [] for link in dependency.get("links"): + link = link.get("link") type = link.get("type") url = link.get("url") + name = link.get("name") cmd = "" if type == "git": - cmd += f"git clone {url}" + cmd += f"git clone {url}.git {name}" elif type == "wget": cmd += f"wget {url}" commands.append(cmd) path_projet_root = os.environ['PROJECT_ROOT_PATH'] install_section = link.get("install") - install_cmd = f"{install_section.get('shell')} {path_projet_root}{install_section.get('script')}" - cmd.append(install_cmd) - dependencies_return.append((computers,commands)) + #script_path = os.path.join(path_projet_root, "vendor", name, install_section.get('script')) + install_cmd = f"{install_section.get('shell')} {install_section.get('script')}" + commands.append(install_cmd) + dependencies_return.append({"computers":computers, "commands":commands}) return dependencies_return -- libgit2 0.21.2