# -*- 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}:")