Beispiel #1
0
    def __init__(self, resource_root_dir: types_path_like):
        """Create a ``QualityStandard`` instance.

        Parameters
        ----------
        resource_root_dir :
            The path to the resource root directory of the standard

        """
        from fs.osfs import OSFS

        self._name = None
        self._max_version = None
        self._versions = {}

        if isinstance(resource_root_dir, Path):
            resource_root_dir = resource_root_dir.as_posix()

        if isinstance(resource_root_dir, str):
            self._filesystem = OSFS(resource_root_dir)
        else:
            self._filesystem = resource_root_dir

        manifest_dir = self._filesystem.opendir("manifests")
        manifest_files = [
            file.name for file in self._filesystem.filterdir(
                "manifests", ["*.yml", "*.yaml"])
        ]

        for filename in manifest_files:
            # stem of pyfilesystem cuts after first .
            qs_name, version = split_tag_version(
                filename[:filename.rindex(".")])

            if self._name is None:
                self._name = qs_name
                self._max_version = version
            else:
                if qs_name != self._name:
                    raise ValueError("Inconsistent naming of manifest files")
                if self._max_version < version:
                    self._max_version = version

            with manifest_dir.open(filename, "r") as stream:
                content = yaml.load(stream, Loader=yaml.SafeLoader)
                self._versions[version] = {
                    "manifest_file_mapping": {
                        content["id"]: filename
                    },
                    "schema_file_mapping": {
                        mapping["uri"]: (f"{mapping['file']}.yaml")
                        for mapping in content["tags"]
                    },
                }
Beispiel #2
0
def parse_schema_filename(filename):
    from asdf import versioning
    components = filename[filename.find('schemas') + 1:].split(os.path.sep)
    tag = 'tag:{}:{}'.format(components[1], '/'.join(components[2:]))
    name, version = versioning.split_tag_version(tag.replace('.yaml', ''))
    return name, version
Beispiel #3
0
def parse_schema_filename(filename):
    from asdf import versioning
    components = filename[filename.find('schemas') + 1:].split(os.path.sep)
    tag = 'tag:{}:{}'.format(components[1], '/'.join(components[2:]))
    name, version = versioning.split_tag_version(tag.replace('.yaml', ''))
    return name, version