Exemplo n.º 1
0
def release(releases_dir, components_dir, **kwargs):
    component_name = kwargs.pop("component_name")
    subparser = kwargs.pop("release_subparser")
    component = c_lib.Component.from_file(
        component_name, components_dir
    )
    if subparser == "get":
        release = component.get_release(kwargs["version"], kwargs["pred"])
    elif subparser == "add":
        release = component.create_release(
            version=kwargs["version"],
            sha=kwargs["sha"],
            series=kwargs["series_name"]
        )

        if component._is_changed:
            component.to_file()
            msg = "Add component {name} release {version}".format(
                name=component.name,
                version=release.version,
            )
            c_lib.commit_changes(releases_dir, components_dir, msg)
    else:
        raise c_lib.ComponentError(
            "The release subparser '{sp}' is not recognised.".format(
                sp=subparser,
            )
        )

    return release
Exemplo n.º 2
0
def component(releases_dir, components_dir, subparser, **kwargs):
    os.makedirs(components_dir, exist_ok=True)
    component_name = kwargs.pop("component_name")

    if subparser == "get":
        component = c_lib.Component.from_file(
            component_name, components_dir
        )
    elif subparser == "add":
        try:
            component = c_lib.Component.from_file(
                component_name, components_dir
            )
        except c_lib.ComponentError:
            component = c_lib.Component(
                name=component_name, directory=components_dir, **kwargs
            )
        else:
            raise c_lib.ComponentError(
                "Component '{name}' already exists.".format(
                    name=component_name,
                )
            )

        try:
            with TemporaryDirectory() as tmp_dir:
                git.Repo.clone_from(
                    c_lib.git_http_to_ssh(component.repo_url), tmp_dir
                )
        except FileNotFoundError as e:
            raise c_lib.ComponentError(
                "The repo_url provided is inaccessible, please check."
            )
    elif subparser == "update":
        component = c_lib.Component.from_file(
            component_name, components_dir
        )
        if kwargs["new_name"]:
            component.name = kwargs["new_name"]
        if kwargs["repo_url"]:
            component.repo_url = kwargs["repo_url"]
        if "is_product" in kwargs:
            component.is_product = kwargs["is_product"]
    else:
        raise c_lib.ComponentError(
            "The component subparser '{sp}' is not recognised.".format(
                sp=subparser,
            )
        )

    if component._is_changed:
        component.to_file()
        msg = "{change} component {name}".format(
            change=subparser.capitalize(),
            name=component.name,
        )

        c_lib.commit_changes(releases_dir, components_dir, msg)

    return component
Exemplo n.º 3
0
def artifact_store(releases_dir, components_dir, **kwargs):
    component_name = kwargs.pop("component_name")
    commit_changes = kwargs.pop("commit_changes")
    subparser = kwargs.pop("artifact_store_subparser")
    component = c_lib.Component.from_file(component_name, components_dir)
    if subparser == "get":
        store = component.get_artifact_store(kwargs["name"])
    elif subparser == "add":
        store = component.add_artifact_store(
            name=kwargs["name"],
            store_type=kwargs["type"],
            public_url=kwargs["public_url"],
            description=kwargs["description"],
        )

        component.to_file()
        if commit_changes and component._is_changed:
            msg = "Add component {name} artifact store {store_name}".format(
                name=component.name,
                store_name=store["name"],
            )
            c_lib.commit_changes(releases_dir, components_dir, msg)
    else:
        raise c_lib.ComponentError(
            "The artifact-store subparser '{sp}' is not recognised.".format(
                sp=subparser, ))

    return store
Exemplo n.º 4
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.º 5
0
def component(releases_dir, components_dir, subparser, **kwargs):
    os.makedirs(components_dir, exist_ok=True)
    component_name = kwargs.pop("component_name")

    if subparser == "get":
        component = c_lib.Component.from_file(
            component_name, components_dir
        )
    elif subparser == "add":
        import_releases = kwargs.pop("import_releases", [])
        try:
            component = c_lib.Component.from_file(
                component_name, components_dir
            )
        except c_lib.ComponentError:
            pass
        else:
            raise c_lib.ComponentError(
                "Component '{name}' already exists.".format(
                    name=component_name,
                )
            )

        ssh_url = c_lib.git_http_to_ssh(kwargs["repo_url"])
        with TemporaryDirectory() as tmp_dir:
            try:
                repo = git.Repo.clone_from(ssh_url, tmp_dir)
            except FileNotFoundError as e:
                raise c_lib.ComponentError(
                    "The repo_url provided is inaccessible, please check."
                )
            else:
                repo.remotes.origin.fetch()
                releases = []
                for each in import_releases:
                    series, tag_regex = each.split(":", 1)
                    for tag in repo.tags:
                        if re.search(tag_regex, tag.name):
                            releases.append(
                                {
                                    "version": tag.name,
                                    "sha": str(tag.commit),
                                    "series": series,
                                }
                            )
        component = c_lib.Component(
            name=component_name, directory=components_dir,
            releases=releases, **kwargs
        )
    elif subparser == "update":
        component = c_lib.Component.from_file(
            component_name, components_dir
        )
        if kwargs["new_name"]:
            component.name = kwargs["new_name"]
        if kwargs["repo_url"]:
            component.repo_url = kwargs["repo_url"]
        if "is_product" in kwargs:
            component.is_product = kwargs["is_product"]
    else:
        raise c_lib.ComponentError(
            "The component subparser '{sp}' is not recognised.".format(
                sp=subparser,
            )
        )

    if component._is_changed:
        component.to_file()
        msg = "{change} component {name}".format(
            change=subparser.capitalize(),
            name=component.name,
        )

        c_lib.commit_changes(releases_dir, components_dir, msg)

    return component