Commit 912ecc8facd9bfd520ad8a34f9439e927da7678a

Authored by Alexis Koralewski
1 parent ec3652a1
Exists in dev

Change location of pyros config file

  1 +23-11-2022 (AKo): v0.6.8.0
  2 + - Change column order for agents commands views, add color for pending commands, fix width of table
  3 + - Change location of pyros config file
  4 +
1 07-11-2022 (AKo): v0.6.7.0 5 07-11-2022 (AKo): v0.6.7.0
2 - Improve agents commands view (add status filter) 6 - Improve agents commands view (add status filter)
3 - Add port configuration for phpmyadmin in docker-compose.yml 7 - Add port configuration for phpmyadmin in docker-compose.yml
privatedev/config/pyros/__init__.py 0 → 100644
privatedev/config/pyros/config_pyros.py 0 → 100644
@@ -0,0 +1,83 @@ @@ -0,0 +1,83 @@
  1 +import yaml
  2 +import os
  3 +import time
  4 +import pykwalify.core
  5 +from pykwalify.errors import SchemaError
  6 +
  7 +
  8 +class ConfigPyros:
  9 + def check_and_return_config(self, yaml_file: str, schema_file: str) -> dict:
  10 + """
  11 + Check if yaml_file is valid for the schema_file and return an dictionary of the config file
  12 +
  13 + Args:
  14 + yaml_file (str): Path to the config_file to be validated
  15 + schema_file (str): Path to the schema file
  16 +
  17 + Returns:
  18 + dict: dictionary of the config file (with values)
  19 + """
  20 + # disable pykwalify error to clean the output
  21 + # logging.disable(logging.ERROR)
  22 + try:
  23 + can_yaml_file_be_read = False
  24 + while can_yaml_file_be_read != True:
  25 + if os.access(yaml_file, os.R_OK):
  26 + can_yaml_file_be_read = True
  27 + else:
  28 + print(
  29 + f"{yaml_file} can't be accessed, waiting for availability")
  30 + time.sleep(0.5)
  31 +
  32 + c = pykwalify.core.Core(source_file=yaml_file, schema_files=[
  33 + self.config_path+"/"+schema_file])
  34 + return c.validate(raise_exception=True)
  35 + except SchemaError:
  36 + for error in c.errors:
  37 + print("Error :", str(error).split(". Path")[0])
  38 + print("Path to error :", error.path)
  39 + return None
  40 + except IOError:
  41 + print("Error when reading the observatory config file")
  42 +
  43 + def read_and_check_config_file(self, yaml_file: str) -> dict:
  44 + """
  45 + Read the schema key of the config file to retrieve schema name and proceed to the checking of that config file
  46 + Call check_and_return_config function and print its return.
  47 +
  48 + Args:
  49 + yaml_file (str): path to the config file
  50 + Returns:
  51 + dict: Dictionary of the config file (with values)
  52 + """
  53 + try:
  54 + can_config_file_be_read = False
  55 + while can_config_file_be_read != True:
  56 +
  57 + if os.access(yaml_file, os.R_OK):
  58 + can_config_file_be_read = True
  59 + else:
  60 + print(
  61 + f"{yaml_file} can't be accessed, waiting for availability")
  62 + time.sleep(0.5)
  63 + with open(yaml_file, 'r') as stream:
  64 + print(f"Reading {yaml_file}")
  65 + config_file = yaml.safe_load(stream)
  66 + result = self.check_and_return_config(
  67 + yaml_file, config_file["schema"])
  68 + if result == None:
  69 + print(
  70 + "Error when reading and validating config file, please check the errors right above")
  71 + exit(1)
  72 + return result
  73 +
  74 + except yaml.YAMLError as exc:
  75 + print(exc)
  76 + except Exception as e:
  77 + print(e)
  78 + return None
  79 +
  80 + def __init__(self, pyros_config_file):
  81 + self.config_path = os.path.abspath(os.path.join(
  82 + os.environ.get("DJANGO_PATH"), "../../../config/pyros//"))
  83 + self.pyros_config = self.read_and_check_config_file(pyros_config_file)
privatedev/config/pyros/config_pyros.yml 0 → 100644
@@ -0,0 +1,14 @@ @@ -0,0 +1,14 @@
  1 +schema: schema_pyros_config.yml
  2 +general:
  3 + logo: logo_pyros.png
  4 + color_theme: sienna
  5 + nb_element_per_page: 20
  6 +USR:
  7 + nb_element_per_page: 10
  8 +SCP: ~
  9 +OCF: ~
  10 +ENV:
  11 + time_history: 2
  12 + time_before_plot: 10
  13 +
  14 +
0 \ No newline at end of file 15 \ No newline at end of file
privatedev/config/pyros/schema_pyros_config.yml 0 → 100644
@@ -0,0 +1,31 @@ @@ -0,0 +1,31 @@
  1 +type: map
  2 +mapping:
  3 + schema:
  4 + type: str
  5 + required: True
  6 + general:
  7 + type: map
  8 + required: True
  9 + mapping:
  10 + logo:
  11 + type: str
  12 + required: True
  13 + color_theme:
  14 + type: str
  15 + required: True
  16 + nb_element_per_page:
  17 + type: int
  18 + required: True
  19 + USR:
  20 + type: any
  21 + SCP:
  22 + type: any
  23 + OCF:
  24 + type: any
  25 + ENV:
  26 + type: map
  27 + mapping:
  28 + time_history:
  29 + type: int
  30 + time_before_plot:
  31 + type: int
@@ -82,6 +82,7 @@ AGENTS = { @@ -82,6 +82,7 @@ AGENTS = {
82 "AgentImagesProcessor_tnc_up1": "../../../privatedev/plugin/agent", 82 "AgentImagesProcessor_tnc_up1": "../../../privatedev/plugin/agent",
83 "agentBasic": "agent", 83 "agentBasic": "agent",
84 "AgentTriton": "agent", 84 "AgentTriton": "agent",
  85 + "AgentMCO":"agent",
85 } 86 }
86 # AGENTS = ["agentX", "webserver", "monitoring", "majordome", "scheduler", "alert_manager"] 87 # AGENTS = ["agentX", "webserver", "monitoring", "majordome", "scheduler", "alert_manager"]
87 # AGENTS = ["all", "webserver", "monitoring", "majordome", "scheduler", "alert"] 88 # AGENTS = ["all", "webserver", "monitoring", "majordome", "scheduler", "alert"]
@@ -828,12 +829,16 @@ def start(agent: str, configfile: str, observatory: str, unit: str, computer_hos @@ -828,12 +829,16 @@ def start(agent: str, configfile: str, observatory: str, unit: str, computer_hos
828 "pykwalify package (required for obsconfig class) installation failed") 829 "pykwalify package (required for obsconfig class) installation failed")
829 if configfile: 830 if configfile:
830 log.debug("With config file" + configfile) 831 log.debug("With config file" + configfile)
  832 + # os.environ["pyros_config_file"] = os.path.join(os.path.abspath(
  833 + # PYROS_DJANGO_BASE_DIR), "../../../config/pyros/", configfile)
831 os.environ["pyros_config_file"] = os.path.join(os.path.abspath( 834 os.environ["pyros_config_file"] = os.path.join(os.path.abspath(
832 - PYROS_DJANGO_BASE_DIR), "../../../config/pyros/", configfile) 835 + PYROS_DJANGO_BASE_DIR), "../../../private/config/pyros/", configfile)
833 else: 836 else:
834 configfile = 'config_pyros.yml' 837 configfile = 'config_pyros.yml'
  838 + # os.environ["pyros_config_file"] = os.path.join(os.path.abspath(
  839 + # PYROS_DJANGO_BASE_DIR), "../../../config/pyros/", configfile)
835 os.environ["pyros_config_file"] = os.path.join(os.path.abspath( 840 os.environ["pyros_config_file"] = os.path.join(os.path.abspath(
836 - PYROS_DJANGO_BASE_DIR), "../../../config/pyros/", configfile) 841 + PYROS_DJANGO_BASE_DIR), "../../../private/config/pyros/", configfile)
837 842
838 logo_name = ConfigPyros( 843 logo_name = ConfigPyros(
839 os.environ["pyros_config_file"]).pyros_config["general"]["logo"] 844 os.environ["pyros_config_file"]).pyros_config["general"]["logo"]
src/core/pyros_django/scientific_program/views.py
@@ -58,10 +58,10 @@ def index_scientific_program(request): @@ -58,10 +58,10 @@ def index_scientific_program(request):
58 # the date of today shift through the time line 58 # the date of today shift through the time line
59 if previous_period: 59 if previous_period:
60 temp = today - previous_period.start_date 60 temp = today - previous_period.start_date
61 - date_diff_today_end_of_property = temp.days / 12.5 61 + date_diff_today_end_of_property = temp.days * 0.85
62 else: 62 else:
63 temp = today - current_period.start_date 63 temp = today - current_period.start_date
64 - date_diff_today_end_of_property = temp.days / 12.5 + 15 64 + date_diff_today_end_of_property = (temp.days / 8) + 15
65 CAN_VALIDATE_SP = request.session.get("role") in ("Admin","Unit-PI","Unit-board") and sp_to_be_validated 65 CAN_VALIDATE_SP = request.session.get("role") in ("Admin","Unit-PI","Unit-board") and sp_to_be_validated
66 CAN_EVALUATE_SP = request.session.get("role") in ("Admin","TAC") and sp_to_be_evaluated 66 CAN_EVALUATE_SP = request.session.get("role") in ("Admin","TAC") and sp_to_be_evaluated
67 CAN_SUBMIT_SP = request.session.get("role") in ("Admin","Observer") and does_next_period_exist 67 CAN_SUBMIT_SP = request.session.get("role") in ("Admin","Observer") and does_next_period_exist
@@ -842,7 +842,9 @@ def create_period(request): @@ -842,7 +842,9 @@ def create_period(request):
842 842
843 past_periods = [] 843 past_periods = []
844 active_period = Period.objects.exploitation_period() 844 active_period = Period.objects.exploitation_period()
845 - periods = Period.objects.all().order_by("-start_date").exclude(id=active_period.id) 845 + periods = Period.objects.all().order_by("-start_date")
  846 + if active_period:
  847 + periods.exclude(id=active_period.id)
846 for period in periods: 848 for period in periods:
847 if active_period != None: 849 if active_period != None:
848 past_periods.append(period) 850 past_periods.append(period)