def _validate(args, app_desc): if Core is None: raise Exception("Cannot validate file, pykwalify is not installed.") path = _find_config(args, app_desc) # Allow empty mapping (not allowed by pykwalify) raw_config = _order_load_path(path) if raw_config.get(app_desc.app_name) is None: raw_config[app_desc.app_name] = {} # Rewrite the file any way to merge any duplicate keys with tempfile.NamedTemporaryFile('w', delete=False, suffix=".yml") as config_p: ordered_dump(raw_config, config_p) def _clean(p, k, v): return k not in ['reloadable', 'path_resolves_to'] clean_schema = remap(app_desc.schema.raw_schema, _clean) with tempfile.NamedTemporaryFile('w', suffix=".yml") as fp: ordered_dump(clean_schema, fp) fp.flush() c = Core( source_file=config_p.name, schema_files=[fp.name], ) os.remove(config_p.name) c.validate()
def _validate(args, app_desc): path = _find_config(args, app_desc) # Allow empty mapping (not allowed by pykawlify) raw_config = _order_load_path(path) if raw_config.get(app_desc.app_name, None) is None: raw_config[app_desc.app_name] = {} config_p = tempfile.NamedTemporaryFile('w', delete=False, suffix=".yml") ordered_dump(raw_config, config_p) config_p.flush() path = config_p.name fp = tempfile.NamedTemporaryFile('w', delete=False, suffix=".yml") def _clean(p, k, v): return k != 'reloadable' clean_schema = remap(app_desc.schema.raw_schema, _clean) ordered_dump(clean_schema, fp) fp.flush() name = fp.name if Core is None: raise Exception("Cannot validate file, pykwalify is not installed.") c = Core( source_file=path, schema_files=[name], ) c.validate()
def _build_uwsgi_schema(args, app_desc): req = requests.get('https://raw.githubusercontent.com/unbit/uwsgi-docs/master/Options.rst') rst_options = req.text last_line = None current_opt = None options = {} option = None for line in rst_options.splitlines(): line = line.strip() dots = "*" * len(line) if line and (line == dots): current_opt = last_line option = { 'type': 'any', } options[current_opt] = option if line.startswith("``parser``"): parser = line.split(":", 1)[1].strip() if parser == "uwsgi_opt_set_int": option["type"] = "int" # TODO: disptch on parser... elif line.startswith("``help``"): option["desc"] = line.split(":", 1)[1] last_line = line schema = { "type": "map", "desc": "uwsgi definition, see https://uwsgi-docs.readthedocs.io/en/latest/Options.html", "mapping": options } path = os.path.join(args.galaxy_root, UWSGI_SCHEMA_PATH) contents = ordered_dump(schema) _write_to_file(args, contents, path)