diff --git a/.gitignore b/.gitignore index 77d2100..dabd712 100644 --- a/.gitignore +++ b/.gitignore @@ -40,4 +40,8 @@ out.* client.log -docker/*.env \ No newline at end of file +docker/*.env + + +privatedev/config/*/history/ +privatedev/config/*/obsconfig.p diff --git a/docker/PYROS_DOCKER_RUN b/docker/PYROS_DOCKER_RUN index 6d9e4e0..8638850 100755 --- a/docker/PYROS_DOCKER_RUN +++ b/docker/PYROS_DOCKER_RUN @@ -6,5 +6,5 @@ then echo "db_pyros or pyros weren't running, starting them..." ./PYROS_DOCKER_START.bat fi -docker exec -it pyros python3 pyros.py start webserver +docker exec -it pyros python3 pyros.py start webserver $@ diff --git a/pyros.py b/pyros.py index f39989c..daa9737 100755 --- a/pyros.py +++ b/pyros.py @@ -12,7 +12,7 @@ import subprocess import sys import time import re - +import glob @@ -27,7 +27,6 @@ import re UPDATE = False PYROS_DJANGO_BASE_DIR = "src/core/pyros_django" - INIT_FIXTURE = "initial_fixture_TZ.json" _previous_dir = None @@ -512,6 +511,8 @@ def install_or_update(UPDATE:bool=False, packages_only:bool=False, database_only @pyros_launcher.command(help="Run some tests") def test(): print("Running tests") + os.environ["PATH_TO_OBSCONF_FOLDER"] = os.path.join(os.path.abspath(PYROS_DJANGO_BASE_DIR),"obsconfig/fixtures/") + #start_dir = os.getcwd() apps = ['obsconfig','common', 'scheduler', 'routine_manager', 'user_manager', 'alert_manager.tests.TestStrategyChange'] for app in apps: @@ -599,10 +600,11 @@ def initdb(): #@global_test_options @click.argument('agent') @click.option('--configfile', '-c', help='the configuration file to be used') +@click.option('--observatory', '-o', help='the observatory name to be used') #@click.option('--format', '-f', type=click.Choice(['html', 'xml', 'text']), default='html', show_default=True) #@click.option('--port', default=8000) #def start(agent:str, configfile:str, test, verbosity): -def start(agent:str, configfile:str): +def start(agent:str, configfile:str,observatory:str): printd("Running start command") if configfile: printd("With config file", configfile) @@ -610,8 +612,28 @@ def start(agent:str, configfile:str): configfile = '' #if test_mode(): print("in test mode") #if verbose_mode(): print("in verbose mode") + if observatory == None or len(observatory) == 0: + observatory = "default" + observatories_configuration_folder = os.path.join(os.path.abspath(PYROS_DJANGO_BASE_DIR),"../../../privatedev/config/") + if len(glob.glob(observatories_configuration_folder+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+"/"+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 # 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.obsconfig.configpyros import ConfigPyros\nConfigPyros('{os.path.join(PYROS_DJANGO_BASE_DIR,os.environ.get('PATH_TO_OBSCONF_FILE'))}')\"" + #cmd_test_obs_config = f"-c \"from src.core.pyros_django.obsconfig.configpyros import ConfigPyros\nConfigPyros('{os.path.join(PYROS_DJANGO_BASE_DIR,os.environ.get('PATH_TO_OBSCONF_FILE'))}')\"" + cmd_test_obs_config = f"-c \"from src.core.pyros_django.obsconfig.configpyros import ConfigPyros\nConfigPyros('{obs_config_file_path}')\"" if not execProcessFromVenv(cmd_test_obs_config): # Observatory configuration has an issue exit(1) diff --git a/src/core/pyros_django/obsconfig/configpyros.py b/src/core/pyros_django/obsconfig/configpyros.py index 2b60a3e..28baa6d 100644 --- a/src/core/pyros_django/obsconfig/configpyros.py +++ b/src/core/pyros_django/obsconfig/configpyros.py @@ -1,8 +1,9 @@ #!/usr/bin/env python3 import pykwalify.core import yaml,sys,logging,os, pickle, time +from datetime import datetime from pykwalify.errors import PyKwalifyException,SchemaError - +from pathlib import Path class ConfigPyros: # (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 devices_links = {} @@ -14,6 +15,7 @@ class ConfigPyros: devices = None computers = None agents = None + obs_config_path = os.environ["PATH_TO_OBSCONF_FOLDER"] def verify_if_pickle_needs_to_be_updated(self,observatory_config_file)->bool: """[summary] @@ -29,10 +31,17 @@ class ConfigPyros: else: pickle_file_mtime = os.path.getmtime(self.CONFIG_PATH+self.pickle_file) obs_config_mtime = os.path.getmtime(observatory_config_file) - if obs_config_mtime > pickle_file_mtime: - return True obs_config = self.read_and_check_config_file(observatory_config_file) + if obs_config_mtime > pickle_file_mtime: + # create obs file (yaml) from pickle["obsconfig"] with date of pickle within history folder-> nom ficher + année + mois + jour + datetime (avec secondes) -> YYYY/MM/DD H:m:s + pickle_datetime = datetime.fromtimestamp(pickle_file_mtime).strftime("%Y%m%d_%H%M%S") + # Create history folder if doesn't exist + Path(self.obs_config_path+"/history/").mkdir(parents=True, exist_ok=True) + file_name = f"{self.obs_config_path}/history/observatory_{pickle_datetime}.yml" + with open(file_name, 'w') as f: + data = yaml.dump(obs_config, f) + return True if obs_config == None: print(f"Error when trying to read config file (path of config file : {observatory_config_file}") return -1 @@ -374,7 +383,6 @@ class ConfigPyros: print(f"device name: '{device_name}', device filename: '{file_name}'") exit(1) # associate attached device to his 'parent' device (parent device is the currently read device) - print(self.devices_links) self.devices_links[attached_device_name] = parent_device_name for capability in capabilities_of_attached_device: # add capabilities of attached device to current device diff --git a/src/core/pyros_django/scientific_program/forms.py b/src/core/pyros_django/scientific_program/forms.py index 3f91b3e..9658de2 100644 --- a/src/core/pyros_django/scientific_program/forms.py +++ b/src/core/pyros_django/scientific_program/forms.py @@ -10,8 +10,6 @@ class ScientificProgramForm(forms.ModelForm): fields = ( "name", "desc", - "quota", - "priority", "institute" #"pyros_users", ) -- libgit2 0.21.2