info_observatory.py
1.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# -*- coding: utf-8 -*-
import pykwalify.core
from pykwalify.errors import SchemaError
import yaml
filename = "observatory_guitalens.yml"
with open(filename, 'r') as stream:
try:
config = yaml.safe_load(stream)
#print(config)
except yaml.YAMLError as exc:
print(exc)
t = config['OBSERVATORY']['_name']
print("="*20)
print(f"Configuration of the observatory : {t}")
ts = config['OBSERVATORY']['DEVICES']
nt = len(ts)
print("="*20)
print(f"There are {nt} available devices:")
print("-"*20)
for kd in range(nt):
texte = ""
t = config['OBSERVATORY']['DEVICES'][kd]['DEVICE']['_name']
texte += f"Device {t}: "
filename = config['OBSERVATORY']['DEVICES'][kd]['DEVICE']['_file']
with open(filename, 'r') as stream:
try:
subconfig = yaml.safe_load(stream)
#print(config)
except yaml.YAMLError as exc:
print(exc)
# --- list of keys
cs = subconfig['DEVICE']['CAPABILITIES']
nc = len(cs)
for kc in range(nc):
t = subconfig['DEVICE']['CAPABILITIES'][kc]['CAPABILITY']['component']
texte += f" {t} "
print(texte)
ts = config['OBSERVATORY']['UNITS']
nt = len(ts)
print("="*20)
print(f"There are {nt} units:")
ku = 0
ts = config['OBSERVATORY']['UNITS'][ku]['UNIT']['_name']
print(f"First unit is {ts}:")
print("-"*20)
ts = config['OBSERVATORY']['UNITS'][ku]['UNIT']['TOPOLOGY']['SECURITY']['_name']
print(f"Security is {ts}:")
ts = config['OBSERVATORY']['UNITS'][ku]['UNIT']['TOPOLOGY']['MOUNT']['_name']
print(f"Mount is {ts}:")