How to use the packit.utils.run_command function in packit

To help you get started, we’ve selected a few packit examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github packit-service / packit / tests / spellbook.py View on Github external
def build_srpm(path: Path):
    run_command(["rpmbuild", "--rebuild", str(path)], output=True)
github packit-service / packit / packit / upstream.py View on Github external
"""
        self._fix_spec_source(archive)
        self._fix_spec_prep(version)

        # we only care about the first number in the release
        # so that we can re-run `packit srpm`
        git_des_command = [
            "git",
            "describe",
            "--tags",
            "--long",
            "--match",
            "*",
        ]
        try:
            git_des_out = run_command(
                git_des_command, output=True, cwd=self.local_project.working_dir
            ).strip()
        except PackitCommandFailedError as ex:
            # probably no tags in the git repo
            logger.info(f"Exception while describing the repository: {ex!r}")
            git_desc_suffix = ""
        else:
            # git adds various info in the output separated by -
            # so let's just drop version and reuse everything else
            g_desc_raw = git_des_out.rsplit("-", 2)[1:]
            # release components are meant to be separated by ".", not "-"
            git_desc_suffix = "." + ".".join(g_desc_raw)
            # the leading dot is put here b/c git_desc_suffix can be empty
            # and we could have two subsequent dots - rpm errors in such a case
        current_branch = self.local_project.ref
        # rpm is picky about release: hates "/" - it's an error
github packit-service / packit / packit / config / aliases.py View on Github external
def get_all_koji_targets() -> List[str]:
    return run_command(["koji", "list-targets", "--quiet"], output=True).split()
github packit-service / packit / packit / patches.py View on Github external
)
        current_time = datetime.datetime.now().strftime(DATETIME_FORMAT)
        target_branch = f"packit-patches-{current_time}"
        logger.info(f"Switch branch to {target_branch!r}.")
        run_command(["git", "checkout", "-B", target_branch])
        target = f"{git_ref}..HEAD"
        logger.debug(f"Linearize history {target}.")
        # https://stackoverflow.com/a/17994534/909579
        # With this command we will rewrite git history of our newly created branch
        # by dropping the merge commits and setting parent commits to those from target branch
        # this means we will drop the reference from which we are merging
        # filter branch passes these to cut:
        #   ` -p 61f3e897f13101f29fb8027e8839498a469ad58e`
        #   ` -p b7cf4b4ef5d0336443f21809b1506bc4a8aa75a9 -p 257188f80ce1a083e3a88b679b898a7...`
        # so we will keep the first parent and drop all the others
        run_command(
            [
                "git",
                "filter-branch",
                "-f",
                "--parent-filter",
                'cut -f 2,3 -d " "',
                target,
            ],
            # git prints nasty warning when filter-branch is used that it's dangerous
            # this env var prevents it from prints
            env={"FILTER_BRANCH_SQUELCH_WARNING": "1"},
        )
github packit-service / packit / packit / upstream.py View on Github external
)

        last_tag = self.get_last_tag()
        msg = ""
        if last_tag:
            # let's print changes b/w the last tag and now;
            # ambiguous argument '0.1.0..HEAD': unknown revision or path not in the working tree.
            # Use '--' to separate paths from revisions, like this
            cmd = [
                "git",
                "log",
                "--pretty=format:- %s (%an)",
                f"{last_tag}..HEAD",
                "--",
            ]
            msg = run_command(
                cmd, output=True, cwd=self.local_project.working_dir
            ).strip()
        if not msg:
            # no describe, no tag - just a boilerplate message w/ commit hash
            # or, there were no changes b/w HEAD and last_tag, which implies last_tag == HEAD
            msg = f"- Development snapshot ({commit})"
        logger.debug(f"Setting Release in spec to {release!r}.")
        # instead of changing version, we change Release field
        # upstream projects should take care of versions
        self.specfile.set_spec_version(
            version=version, release=release, changelog_entry=msg,
        )
github packit-service / packit / packit / upstream.py View on Github external
def get_last_tag(self) -> Optional[str]:
        """ get last git-tag from the repo """
        try:
            last_tag = run_command(
                ["git", "describe", "--tags", "--abbrev=0"],
                output=True,
                cwd=self.local_project.working_dir,
            ).strip()
        except PackitCommandFailedError as ex:
            logger.debug(f"{ex!r}")
            logger.info("Can't describe this repository, are there any git tags?")
            # no tags in the git repo
            return None
        return last_tag
github packit-service / packit / packit / command_runner.py View on Github external
def run_command(self, command: List[str]):
        """
        Executes command in current working directory
        :param command: command to execute
        This is not valid for this use case
        :return: Output of command
        """
        return utils.run_command(cmd=command, cwd=self.cwd, output=self.output)
github packit-service / packit / packit / transformator.py View on Github external
:param upstream: str -- git branch or tag
        :return: [(patch_name, msg)] list of created patches (tuple of the file name and commit msg)
        """

        upstream = upstream or self.version_from_specfile
        commits = self.get_commits_to_upstream(upstream, add_usptream_head_commit=True)
        patch_list = []
        for i, commit in enumerate(commits[1:]):
            parent = commits[i]

            patch_name = f"{i + 1:04d}-{commit.hexsha}.patch"
            patch_path = os.path.join(self.distgit.working_dir, patch_name)
            patch_msg = f"{commit.summary}\nAuthor: {commit.author.name} <{commit.author.email}>"

            logger.debug(f"PATCH: {patch_name}\n{patch_msg}")
            diff = run_command(
                cmd=[
                    "git",
                    "diff",
                    "--patch",
                    parent.hexsha,
                    commit.hexsha,
                    "--",
                    ".",
                    '":(exclude)redhat"',
                ],
                cwd=self.sourcegit.working_dir,
                output=True,
            )

            with open(patch_path, mode="w") as patch_file:
                patch_file.write(diff)