Commit 046ed955 authored by Ben Couturier's avatar Ben Couturier
Browse files

Added validation with strictyaml

parent 7207905c
Pipeline #2339087 passed with stages
in 1 minute and 39 seconds
......@@ -13,23 +13,30 @@ import os
from collections import defaultdict
from pathlib import Path
import yaml
from strictyaml import Map, MapPattern, Optional, Seq, Str, load
#
# Set of tools to deal with the stack information in YAML,
# and comparing this ionformations with the releases
# TODO:
# - Check the expected types and investigate strictyaml
# we should ensure the info object has a minimum set of values
# - find a better way to implement the factory method
STACK_SCHEMA = Map(
{
"name": Str(),
"type": Str(),
"projects": MapPattern(Str(), Str()),
"toolchain": Map({"type": Str(), "version": Str()}),
"platforms": Seq(Str()),
"tags": Seq(Str()),
}
)
def load_stack_info(repository, name):
""" Load stack information by name from the specified repository """
filename = Path(repository) / f"{name}.yml"
with open(filename) as file:
info = yaml.load(file, Loader=yaml.FullLoader)
return info
info = load(file.read(), STACK_SCHEMA)
return info.data
def load_stack(repository, siteroot, name):
......@@ -178,11 +185,19 @@ class LHCbClassicStack(Stack):
return todo
PROJECTS_SCHEMA = Map(
{
"defaultSourceURI": Str(),
"projects": Seq(Map({"name": Str(), Optional("sourceuri"): Str()})),
}
)
def list_projects(projects_data):
""" Returns the list of known projects """
info = None
with open(projects_data) as file:
info = yaml.load(file, Loader=yaml.FullLoader)
info = load(file.read(), PROJECTS_SCHEMA).data
defaultSourceURI = info["defaultSourceURI"]
projects = info["projects"]
for p in projects:
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment