예제 #1
0
파일: main.py 프로젝트: rdeville/git_mirror
def control_final_config():
    title = "FINAL CONFIGURATION ERROR"
    dial = Dialog(dialog="dialog", autowidgetsize=True)
    dial.set_background_title("FINAL CONFIGURATION ERROR")
    main_set = False
    with open(FINAL_CONFIG_CONTROL_TEMP_FILE, "w") as stream:
        try:
            yaml.dump({"remote": GIT_REMOTE["remote"]}, stream)
        except yaml.YAMLError as exc:
            eprint(Colors.FAIL + "[ERROR] Error when writing file " +
                   FINAL_CONFIG_CONTROL_TEMP_FILE + "\n" +
                   "[ERROR] Error are : " + exc + Colors.ENDC)
            sys.exit(1)

    check = pykwalify_core.Core(source_file=FINAL_CONFIG_CONTROL_TEMP_FILE,
                                schema_files=[FINAL_CONFIG_CONTROL_FILE])
    try:
        check.validate(raise_exception=True)
    except pykwalify.errors.SchemaError as exc:
        msg = "[ERROR] There are error when validating final configuration. \n"\
            + "[ERROR] Error are : \n"
        for i_msg in exc.args:
            msg += i_msg
        msg += "\nPlease select a main remote and/or configure it with the main menu"
        dial.msgbox(msg, title=title, width=DIAL_MAXSIZE["width"], height=20)
        os.remove(FINAL_CONFIG_CONTROL_TEMP_FILE)
        return False
    os.remove(FINAL_CONFIG_CONTROL_TEMP_FILE)
    return True
예제 #2
0
파일: files.py 프로젝트: ysleeson/tavern
def verify_generic(to_verify, schema):
    """Verify a generic file against a given schema

    Args:
        to_verify (str): Filename of source tests to check
        schema (dict): Schema to verify against

    Raises:
        BadSchemaError: Schema did not match
    """
    logger.debug("Verifying %s against %s", to_verify, schema)

    here = os.path.dirname(os.path.abspath(__file__))
    extension_module_filename = os.path.join(here, "extensions.py")

    verifier = core.Core(
        source_data=to_verify,
        schema_data=schema,
        extensions=[extension_module_filename],
    )

    try:
        verifier.validate()
    except pykwalify.errors.PyKwalifyException as e:
        logger.exception("Error validating %s", to_verify)
        raise_from(BadSchemaError(), e)
예제 #3
0
def validate_yaml(data, schema):
    """
    Validate Yaml
    """
    c = pykwalify_core.Core(source_data=data, schema_data=schema)
    try:
        c.validate(raise_exception=True)
    except pykwalify_errors.SchemaError as e:
        raise Exception('File does not conform to schema: %s' % e)
예제 #4
0
def validate_yaml(config, _logger):
    _logger.info("Validating the configuration file passed by the user")
    stream = open("lib/validate.yaml", 'r')
    schema = yaml.load(stream)
    check = pykwalify_core.Core(source_data=config, schema_data=schema)
    try:
        check.validate(raise_exception=True)
        _logger.info("Validation successful")
    except pykwalify_errors.SchemaError as e:
        _logger.error("Schema Validation failed")
        raise Exception('File does not conform to schema: {}'.format(e))
예제 #5
0
def _validate_yaml(schema, config):
    """Raises exception if config is invalid.

    :param schema: The schema to validate with (browbeat, perfkit, rally...)
    :param config: Loaded yaml to validate
    """
    check = pykwalify_core.Core(
        source_data=config, schema_files=["{}/{}.yml".format(conf_schema_path, schema)])
    try:
        check.validate(raise_exception=True)
    except pykwalify_errors.SchemaError as e:
        _logger.error("Schema validation failed")
        raise Exception("File does not conform to {} schema: {}".format(schema, e))
예제 #6
0
파일: main.py 프로젝트: rdeville/git_mirror
def check_yaml_file(source_file, schema_file):
    """
    Check if source_file is valid against schema_file
    :param source_file: String, path to the source file to check
    :param schema_file: String, path to the schema to use to check source_file
    :return: The content of the source_file if it is valid,
             else exit with an error
    """
    check = pykwalify_core.Core(source_file=source_file,
                                schema_files=schema_file)
    try:
        check.validate(raise_exception=True)
    except pykwalify.errors.SchemaError as exc:
        eprint(Colors.FAIL + "[ERROR] Error found in file: " + source_file +
               "\n" + "[ERROR] It does not respect schema files:")
        for i_schema in schema_file:
            eprint("[ERROR]   - " + i_schema)
        eprint("[ERROR] Error are : \n")
        for i_msg in exc.args:
            eprint(i_msg)
        eprint(Colors.ENDC)
        sys.exit(1)
    return check.source
예제 #7
0
#!/usr/bin/env python
#   Licensed under the Apache License, Version 2.0 (the "License");
#   you may not use this file except in compliance with the License.
#   You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
#   Unless required by applicable law or agreed to in writing, software
#   distributed under the License is distributed on an "AS IS" BASIS,
#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
#   See the License for the specific language governing permissions and
#   limitations under the License.

import yaml
import sys
from pykwalify import core as pykwalify_core
from pykwalify import errors as pykwalify_errors
stream = open(sys.argv[1], 'r')
schema = yaml.load(stream)
check = pykwalify_core.Core(sys.argv[2], schema_data=schema)
try:
    check.validate(raise_exception=True)
    print("Validation successful")
    exit(0)
except pykwalify_errors.SchemaError as e:
    print("Config " + sys.argv[2] + " is not valid!")
    raise Exception('File does not conform to schema: {}'.format(e))