Commit 4497eb3e3e357a2874a54712eb46fb2a5b2c31c7

Authored by Alexis Koralewski
1 parent 7753168f
Exists in dev

updating config, schema and python script to check config

config/config.yml
1 -OBSERVATORY_1: 1 +OBSERVATORY:
2 _name: TNC 2 _name: TNC
3 3
4 UNITS: 4 UNITS:
5 - UNIT_1: 5 + - UNIT:
6 _name: TNC-Telescope 6 _name: TNC-Telescope
7 # _Site: (home, ligne d'horizon) 7 # _Site: (home, ligne d'horizon)
8 8
@@ -13,25 +13,25 @@ OBSERVATORY_1: @@ -13,25 +13,25 @@ OBSERVATORY_1:
13 13
14 CHANNELS: 14 CHANNELS:
15 15
16 - CHANNEL_1: 16 + - CHANNEL:
17 _name: TNC-NW 17 _name: TNC-NW
18 _components: 18 _components:
19 - Camera_FLIKepler4040_sn123.yml 19 - Camera_FLIKepler4040_sn123.yml
20 - Focuser_Optec_sn341.yml 20 - Focuser_Optec_sn341.yml
21 - Optic_TakahashiED180_sn445.yml 21 - Optic_TakahashiED180_sn445.yml
22 22
23 - CHANNEL_2: 23 + - CHANNEL:
24 _name: TNC-NE 24 _name: TNC-NE
25 25
26 - CHANNEL_3: 26 + - CHANNEL:
27 _name: TNC-SW 27 _name: TNC-SW
28 28
29 - CHANNEL_4: 29 + - CHANNEL:
30 _name: TNC-SE 30 _name: TNC-SE
31 31
32 COMPUTERS: 32 COMPUTERS:
33 33
34 - COMPUTER_1: 34 + - COMPUTER:
35 _name: PyROS_bdd 35 _name: PyROS_bdd
36 _file: Computer_DELL_PowerEdge7000_sn599.yml 36 _file: Computer_DELL_PowerEdge7000_sn599.yml
37 _hostname: TNC_PC_DB 37 _hostname: TNC_PC_DB
@@ -39,7 +39,7 @@ OBSERVATORY_1: @@ -39,7 +39,7 @@ OBSERVATORY_1:
39 name: MySQL 39 name: MySQL
40 port: 3306 40 port: 3306
41 41
42 - COMPUTER_2: 42 + - COMPUTER:
43 _name: PyROS_principal 43 _name: PyROS_principal
44 _file: Computer_DELL_E6430_sn000.yml 44 _file: Computer_DELL_E6430_sn000.yml
45 _hostname: TNC_PC1 45 _hostname: TNC_PC1
@@ -48,7 +48,7 @@ OBSERVATORY_1: @@ -48,7 +48,7 @@ OBSERVATORY_1:
48 - Majordome: /home/pyros/private/majordome_perso 48 - Majordome: /home/pyros/private/majordome_perso
49 - Monitoring: ~ 49 - Monitoring: ~
50 50
51 - COMPUTER_3: 51 + - COMPUTER:
52 _name: PyROS_spare 52 _name: PyROS_spare
53 _file: Computer_DELL_E6430_sn001.yml 53 _file: Computer_DELL_E6430_sn001.yml
54 _hostname: TNC_PC2 54 _hostname: TNC_PC2
@@ -58,7 +58,7 @@ OBSERVATORY_1: @@ -58,7 +58,7 @@ OBSERVATORY_1:
58 - Majordome: ~ 58 - Majordome: ~
59 - Monitoring: ~ 59 - Monitoring: ~
60 60
61 - COMPUTER_4: 61 + - COMPUTER:
62 _name: PyROS_channel 62 _name: PyROS_channel
63 _file: Computer_DELL_MiniPC_s772.yml 63 _file: Computer_DELL_MiniPC_s772.yml
64 _hostname: TNC_MINIPC_SW 64 _hostname: TNC_MINIPC_SW
config/schema.yaml
@@ -68,43 +68,37 @@ schema;schema_COMPUTER: @@ -68,43 +68,37 @@ schema;schema_COMPUTER:
68 68
69 schema;schema_COMPUTERS: 69 schema;schema_COMPUTERS:
70 # TODO: can be improved if we switch to sequence -> we can have any number of computers 70 # TODO: can be improved if we switch to sequence -> we can have any number of computers
71 - type: map  
72 - mapping:  
73 - COMPUTER_1:  
74 - include: schema_COMPUTER  
75 - COMPUTER_2:  
76 - include: schema_COMPUTER  
77 - COMPUTER_3:  
78 - include: schema_COMPUTER  
79 - COMPUTER_4:  
80 - include: schema_COMPUTER  
81 - 71 + type: seq
  72 + sequence:
  73 + - type: map
  74 + mapping:
  75 + COMPUTER:
  76 + include: schema_COMPUTER
  77 +
82 schema;schema_UNITS: 78 schema;schema_UNITS:
83 - type: map 79 + type: seq
84 required: True 80 required: True
85 - mapping:  
86 - UNIT_1:  
87 - include: schema_UNIT 81 + sequence:
  82 + - type: map
  83 + mapping :
  84 + UNIT:
  85 + include: schema_UNIT
88 86
89 87
90 88
91 schema;schema_CHANNELS: 89 schema;schema_CHANNELS:
92 - type: map 90 + type: seq
93 required: True 91 required: True
94 - mapping:  
95 - CHANNEL_1:  
96 - include: schema_CHANNEL  
97 - CHANNEL_2:  
98 - include: schema_CHANNEL  
99 - CHANNEL_3:  
100 - include: schema_CHANNEL  
101 - CHANNEL_4:  
102 - include: schema_CHANNEL  
103 - 92 + sequence:
  93 + - type : map
  94 + mapping:
  95 + CHANNEL:
  96 + include: schema_CHANNEL
  97 +
104 98
105 type: map 99 type: map
106 mapping: 100 mapping:
107 - OBSERVATORY_1: 101 + OBSERVATORY:
108 type: map 102 type: map
109 required: True 103 required: True
110 mapping: 104 mapping:
config/test_yaml.py
1 # -*- coding: utf-8 -*- 1 # -*- coding: utf-8 -*-
2 2
3 from pykwalify.core import Core 3 from pykwalify.core import Core
  4 +from pykwalify.errors import SchemaError
4 5
5 """ 6 """
6 Read yaml file : 7 Read yaml file :
@@ -17,6 +18,17 @@ with open('C:/srv/develop/pyros/config/config2.yml', 'w', encoding='utf8') as ou @@ -17,6 +18,17 @@ with open('C:/srv/develop/pyros/config/config2.yml', 'w', encoding='utf8') as ou
17 yaml.dump(a, outfile, default_flow_style=False, allow_unicode=True) 18 yaml.dump(a, outfile, default_flow_style=False, allow_unicode=True)
18 """ 19 """
19 20
  21 +"""
  22 +import yaml
  23 +with open("config.yml", 'r') as stream:
  24 + try:
  25 + a = yaml.safe_load(stream)
  26 + print(a)
  27 + except yaml.YAMLError as exc:
  28 + print(exc)
  29 +
  30 + """
  31 +
20 def check_and_return_config(yaml_file:str,schema_file:str)->dict: 32 def check_and_return_config(yaml_file:str,schema_file:str)->dict:
21 """ 33 """
22 Check if yaml_file is valid for the schema_file 34 Check if yaml_file is valid for the schema_file
@@ -28,7 +40,13 @@ def check_and_return_config(yaml_file:str,schema_file:str)->dict: @@ -28,7 +40,13 @@ def check_and_return_config(yaml_file:str,schema_file:str)->dict:
28 Returns: 40 Returns:
29 dict: Dictionnary of the config file (with values) 41 dict: Dictionnary of the config file (with values)
30 """ 42 """
31 - c = Core(source_file=yaml_file, schema_files=[schema_file])  
32 - return c.validate(raise_exception=True) 43 + try:
  44 +
  45 + c = Core(source_file=yaml_file, schema_files=[schema_file])
  46 + return c.validate(raise_exception=True)
  47 + except SchemaError as error:
  48 + #TODO : find a way to retrieve message with path to error
  49 + print(error.path)
  50 +
33 51
34 print(check_and_return_config("config.yml","schema.yaml")) 52 print(check_and_return_config("config.yml","schema.yaml"))
35 \ No newline at end of file 53 \ No newline at end of file