Exemple #1
0
    def from_yaml(yaml_file, product_yaml=None):
        yaml_contents = ssgcommon.open_and_expand_yaml(yaml_file, product_yaml)
        if yaml_contents is None:
            return None

        basename, _ = os.path.splitext(os.path.basename(yaml_file))

        profile = Profile(basename)
        profile.title = required_yaml_key(yaml_contents, "title")
        profile.description = required_yaml_key(yaml_contents, "description")
        profile.extends = yaml_contents.get("extends", None)
        profile.selections = required_yaml_key(yaml_contents, "selections")
        return profile
Exemple #2
0
    def from_yaml(yaml_file, id_, product_yaml=None):
        yaml_contents = ssgcommon.open_and_expand_yaml(yaml_file, product_yaml)
        if yaml_contents is None:
            return None

        benchmark = Benchmark(id_)
        benchmark.title = required_yaml_key(yaml_contents, "title")
        benchmark.status = required_yaml_key(yaml_contents, "status")
        benchmark.description = required_yaml_key(yaml_contents, "description")
        notice_contents = required_yaml_key(yaml_contents, "notice")
        benchmark.notice_id = required_yaml_key(notice_contents, "id")
        benchmark.notice_description = required_yaml_key(
            notice_contents, "description")
        benchmark.front_matter = required_yaml_key(yaml_contents,
                                                   "front-matter")
        benchmark.rear_matter = required_yaml_key(yaml_contents, "rear-matter")
        benchmark.cpes = yaml_contents.get("cpes", [])
        benchmark.version = str(required_yaml_key(yaml_contents, "version"))
        return benchmark
Exemple #3
0
    def from_yaml(yaml_file, product_yaml=None):
        yaml_contents = ssgcommon.open_and_expand_yaml(yaml_file, product_yaml)
        if yaml_contents is None:
            return None

        value_id, _ = os.path.splitext(os.path.basename(yaml_file))
        value = Value(value_id)
        value.title = required_yaml_key(yaml_contents, "title")
        value.description = required_yaml_key(yaml_contents, "description")
        value.type = required_yaml_key(yaml_contents, "type")
        value.options = required_yaml_key(yaml_contents, "options")
        value.warnings = yaml_contents.get("warnings", [])

        for warning_list in value.warnings:
            if len(warning_list) != 1:
                raise ValueError(
                    "Only one key/value pair should exist for each dictionary")

        return value
Exemple #4
0
    def from_yaml(yaml_file, env_yaml=None):
        yaml_contents = ssgcommon.open_and_expand_yaml(yaml_file, env_yaml)
        if yaml_contents is None:
            return None

        value_id, _ = os.path.splitext(os.path.basename(yaml_file))
        value = Value(value_id)
        value.title = required_yaml_key(yaml_contents, "title")
        del yaml_contents["title"]
        value.description = required_yaml_key(yaml_contents, "description")
        del yaml_contents["description"]
        value.type_ = required_yaml_key(yaml_contents, "type")
        del yaml_contents["type"]
        value.operator = yaml_contents.pop("operator", "equals")
        possible_operators = ["equals", "not equal", "greater than",
                              "less than", "greater than or equal",
                              "less than or equal", "pattern match"]

        if value.operator not in possible_operators:
            raise ValueError(
                "Found an invalid operator value '%s' in '%s'. "
                "Expected one of: %s"
                % (value.operator, yaml_file, ", ".join(possible_operators))
            )

        value.interactive = \
            yaml_contents.pop("interactive", "false").lower() == "true"

        value.options = required_yaml_key(yaml_contents, "options")
        del yaml_contents["options"]
        value.warnings = yaml_contents.pop("warnings", [])

        for warning_list in value.warnings:
            if len(warning_list) != 1:
                raise ValueError("Only one key/value pair should exist for each dictionary")

        if yaml_contents:
            raise RuntimeError("Unparsed YAML data in '%s'.\n\n%s"
                               % (yaml_file, yaml_contents))

        return value
Exemple #5
0
    def from_yaml(yaml_file, env_yaml=None):
        yaml_contents = ssgcommon.open_and_expand_yaml(yaml_file, env_yaml)
        if yaml_contents is None:
            return None

        basename, _ = os.path.splitext(os.path.basename(yaml_file))

        profile = Profile(basename)
        profile.title = required_yaml_key(yaml_contents, "title")
        del yaml_contents["title"]
        profile.description = required_yaml_key(yaml_contents, "description")
        del yaml_contents["description"]
        profile.extends = yaml_contents.pop("extends", None)
        profile.selections = required_yaml_key(yaml_contents, "selections")
        del yaml_contents["selections"]

        if yaml_contents:
            raise RuntimeError("Unparsed YAML data in '%s'.\n\n%s"
                               % (yaml_file, yaml_contents))

        return profile
Exemple #6
0
    def from_yaml(yaml_file, id_, product_yaml=None):
        yaml_contents = ssgcommon.open_and_expand_yaml(yaml_file, product_yaml)
        if yaml_contents is None:
            return None

        benchmark = Benchmark(id_)
        benchmark.title = required_yaml_key(yaml_contents, "title")
        del yaml_contents["title"]
        benchmark.status = required_yaml_key(yaml_contents, "status")
        del yaml_contents["status"]
        benchmark.description = required_yaml_key(yaml_contents, "description")
        del yaml_contents["description"]
        notice_contents = required_yaml_key(yaml_contents, "notice")
        benchmark.notice_id = required_yaml_key(notice_contents, "id")
        del notice_contents["id"]
        benchmark.notice_description = required_yaml_key(notice_contents,
                                                         "description")
        del notice_contents["description"]
        if not notice_contents:
            del yaml_contents["notice"]

        benchmark.front_matter = required_yaml_key(yaml_contents,
                                                   "front-matter")
        del yaml_contents["front-matter"]
        benchmark.rear_matter = required_yaml_key(yaml_contents,
                                                  "rear-matter")
        del yaml_contents["rear-matter"]
        benchmark.cpes = yaml_contents.pop("cpes", [])
        benchmark.version = str(required_yaml_key(yaml_contents, "version"))
        del yaml_contents["version"]

        if yaml_contents:
            raise RuntimeError("Unparsed YAML data in '%s'.\n\n%s"
                               % (yaml_file, yaml_contents))

        return benchmark