def load_data(filename): schema = MapPattern( Regex(u'[A-Za-z. ]+'), MapPattern( Regex(u'[A-Za-z\\-. ]+'), Map({ 'Description': Regex('.+'), 'Free': Bool(), 'Link': Url(), }, Regex(u'.+')))) with open(filename) as f: return strictyaml.load(f.read(), schema).data
def get_robot_part_schema(): """ Getter for robot schema :return: schema that is used to verify the robot yaml """ return Map({ 'name': Str(), 'type': Str(), 'brick': Int(), 'x_offset': Float(), 'y_offset': Float(), Optional('port'): Regex('ev3-ports:(in[1-4]|out[A-D])'), Optional('side'): Regex('left|right|rear'), Optional('direction'): Regex('bottom|front'), })
return version_string raise YAMLSerializationError( "expected string or sequence," f" got '{data}' of type '{type(data).__name__}'") # TODO: allow author in COG_KEYS and merge them with repo/shared fields lists REPO_KEYS = { "name": Str(), # Downloader doesn't use this but I can set friendlier name "short": Str(), "description": Str(), "install_msg": Str(), "author": Seq(Str()), } COMMON_KEYS = { Optional("min_bot_version"): Regex(VersionInfo._VERSION_STR_PATTERN), Optional("max_bot_version"): Regex(VersionInfo._VERSION_STR_PATTERN), Optional("min_python_version"): PythonVersion(), Optional("hidden", False): Bool(), Optional("disabled", False): Bool(), Optional("type", "COG"): Enum(["COG", "SHARED_LIBRARY"]), } SHARED_FIELDS_KEYS = { "install_msg": Str(), "author": Seq(Str()), **COMMON_KEYS, } COG_KEYS = { "name": Str(), # Downloader doesn't use this but I can set friendlier name "short": Str(), "description": Str(),
def RedVersion() -> Regex: return Regex(VersionInfo._VERSION_STR_PATTERN.pattern)
from strictyaml import Any, Enum, Int, Map, MapPattern, Optional, Regex, Seq, Str limits_schema = Map( { "time": Int(), Optional("memory", default=8192): Int(), Optional("output"): Int(), Optional("cores"): Int(), } ) module_schema = Regex(r"\.?\w+(\.\w+)*") plugin_schema = Map( {"module": module_schema, Optional("config"): MapPattern(Str(), Any())} ) task_sources = Enum(["local", "url"]) schema = Map( { "title": Str(), Optional("description"): Str(), "limits": limits_schema, "steps": Map( {"run": Seq(plugin_schema), Optional("analysis"): Seq(plugin_schema)} ), "observers": Seq(plugin_schema), "tasks": MapPattern(Str(), MapPattern(Str(), Any())), "tools": MapPattern( Str(),
from typing import Dict, Any, cast from strictyaml import as_document, Map, Bool, Regex from strictyaml import load as yaml_load _WORD = Regex(r'^[\w]+$') _PATH = Regex(r'[^<>]+') CONFIG_FILE = 'config.yaml' __CONFIG_VERSION = 1 __CONFIG_SCHEMA = Map({ 'version': Regex(f'{__CONFIG_VERSION}'), 'twitch': Map({'client_id': _WORD}), 'main': Map({ 'channel': _WORD, 'quality': Regex(r'^[\w]*$'), 'temp_dir': _PATH }), 'storage': Map({ 'path': _PATH, 'vod_path': _PATH }), 'telegram': Map({ 'enabled': Bool(), 'api_token': Regex(r'^[\w:_\-]+$'), 'chat_id': _WORD