Exemplo n.º 1
0
def get_metadata(metadata_dir):
    metadata_filename = "component_metadata.yml"
    filepath = os.path.join(metadata_dir, metadata_filename)
    try:
        metadata = c_lib.load_data(filepath)
    except FileNotFoundError:
        metadata = {"artifacts": [], "dependencies": []}
    return s_lib.component_metadata_schema.validate(metadata)
Exemplo n.º 2
0
def dependency(components_dir, **kwargs):
    dependency_dir = kwargs.pop("dependency_dir")
    metadata_filename = "component_metadata.yml"
    filepath = os.path.join(dependency_dir, metadata_filename)
    new_metadata = {"dependencies": []}
    try:
        metadata = c_lib.load_data(filepath)
    except FileNotFoundError:
        metadata = deepcopy(new_metadata)
    metadata = s_lib.component_metadata_schema.validate(metadata)

    subparser = kwargs.pop("dependency_subparser")
    if subparser == "set-dependency":
        data = c_lib.set_dependency(metadata, **kwargs)
        if data != metadata or data == new_metadata:
            c_lib.save_data(
                filepath,
                s_lib.component_metadata_schema.validate(data)
            )
            msg = "Set component dependency {name}".format(
                name=kwargs["name"],
            )

            c_lib.commit_changes(dependency_dir, metadata_filename, msg)
    elif subparser == "update-requirements":
        existing_requirements = c_lib.load_requirements(dependency_dir)
        requirements = c_lib.update_requirements(metadata, components_dir)
        if existing_requirements != requirements:
            c_lib.save_requirements(requirements, dependency_dir)
            msg = "Update component dependency requirements"
            c_lib.commit_changes(
                dependency_dir, c_lib.REQUIREMENTS_FILENAME, msg
            )
    elif subparser == "download-requirements":
        requirements = c_lib.load_requirements(dependency_dir)
        c_lib.download_requirements(
            requirements["dependencies"], kwargs["download_dir"]
        )
    else:
        raise c_lib.ComponentError(
            "The dependency subparser '{sp}' is not recognised.".format(
                sp=subparser,
            )
        )
Exemplo n.º 3
0
def metadata(components_dir, **kwargs):
    metadata_dir = kwargs.pop("metadata_dir")
    metadata_filename = "component_metadata.yml"
    filepath = os.path.join(metadata_dir, metadata_filename)
    new_metadata = {"artifacts": [], "dependencies": []}
    try:
        metadata = c_lib.load_data(filepath)
    except FileNotFoundError:
        metadata = deepcopy(new_metadata)

    subparser = kwargs.pop("metadata_subparser")
    if subparser == "get":
        return s_lib.component_metadata_schema.validate(metadata)
    else:
        raise c_lib.ComponentError(
            "The metadata subparser '{sp}' is not recognised.".format(
                sp=subparser,
            )
        )