Ejemplo n.º 1
0
 def pull_branch(self, branch):
     """
     Pull from origin/master to local master branch.
     :param branch: branch to pull
     :return:
     """
     run_command(self.repo_path, f'git pull --rebase origin {branch}',
                 'Unable to pull from remote repository', True)
Ejemplo n.º 2
0
 def pull(self):
     """
     Pull from origin/master to local master branch.
     """
     run_command(
         self.repo_path,
         'git pull --rebase origin master',
         'Unable to pull from remote repository', True)
Ejemplo n.º 3
0
    def fake_clone_func(self, directory, name):
        directory = Path(directory)
        if not directory.is_dir():
            raise ReleaseException(
                f"Cannot clone into non-existent directory {directory}:")

        run_command(directory, f"fedpkg clone {name!r} --anonymous",
                    "Cloning fedora repository failed:")
        return str(directory / name)
Ejemplo n.º 4
0
 def set_credentials(self, name, email):
     """
     Sets credentials fo git repo to keep git from resisting to commit
     :param name: committer name
     :param email: committer email
     :return: True on success False on fail
     """
     email = run_command(self.repo_path, f'git config user.email "{email}"', '', fail=False)
     name = run_command(self.repo_path, f'git config user.name "{name}"', '', fail=False)
     return email and name
Ejemplo n.º 5
0
    def build_sdist(project_root):
        """
        Builds source distribution out of setup.py

        :param project_root: location of setup.py
        """
        if os.path.isfile(os.path.join(project_root, 'setup.py')):
            run_command(project_root, "python setup.py sdist", "Cannot build sdist:")
        else:
            raise ReleaseException("Cannot find setup.py:")
Ejemplo n.º 6
0
    def build_wheel(project_root):
        """
        Builds wheel for specified version of python

        :param project_root: location of setup.py
        """
        if not os.path.isfile(os.path.join(project_root, 'setup.py')):
            raise ReleaseException("Cannot find setup.py:")

        run_command(project_root, "python3 setup.py bdist_wheel",
                    "Cannot build wheel:")
Ejemplo n.º 7
0
 def pull_branch(self, branch: str):
     """
     Pull (with rebase) from branch.
     :param branch: branch to pull, default's to
     :return:
     """
     run_command(
         self.repo_path,
         f"git pull --rebase origin {branch}",
         "Unable to pull from remote repository",
         True,
     )
Ejemplo n.º 8
0
    def fedpkg_new_sources(directory, branch, sources="", fail=True):
        if not os.path.isdir(directory):
            raise ReleaseException("Cannot access fedpkg repository:")

        return run_command(directory, f"fedpkg new-sources {sources}",
                           f"Adding new sources on branch {branch} failed:",
                           fail)
Ejemplo n.º 9
0
    def checkout(self, target: str):
        """
        checkout the target

        :param target: str (branch, tag, file)
        """
        return run_command(self.repo_path, f'git checkout "{target}"', "", fail=True)
Ejemplo n.º 10
0
    def fedpkg_sources(directory, branch, fail=True):
        if not os.path.isdir(directory):
            raise ReleaseException("Cannot access fedpkg repository:")

        return run_command(directory, "fedpkg sources",
                           f"Retrieving sources for branch {branch} failed:",
                           fail)
Ejemplo n.º 11
0
    def upload(self, project_root):
        """
        Uploads the package distribution to PyPi

        :param project_root: directory with dist/ folder
        """
        if os.path.isdir(os.path.join(project_root, 'dist')):
            spec_files = glob(os.path.join(project_root, "dist/*"))
            files = ""
            for file in spec_files:
                files += f"{file} "
            self.logger.debug(f"Uploading {files} to PyPi")
            run_command(project_root, f"twine upload {files}",
                        "Cannot upload python distribution:")
        else:
            raise ReleaseException("dist/ folder cannot be found:")
Ejemplo n.º 12
0
 def checkout_new_branch(self, branch):
     """
     Creates a new local branch
     :param branch: branch name
     :return: True on success False on fail
     """
     return run_command(self.repo_path, f'git checkout -b "{branch}"', '', fail=False)
Ejemplo n.º 13
0
    def fedpkg_merge(directory, branch, ff_only=True, fail=True):
        if not os.path.isdir(directory):
            raise ReleaseException("Cannot access fedpkg repository:")

        return run_command(
            directory, f"git merge master {'--ff-only' if ff_only else ''}",
            f"Merging master to branch {branch!r} failed:", fail)
Ejemplo n.º 14
0
    def fedpkg_push(directory, branch, fail=True):
        if not os.path.isdir(directory):
            raise ReleaseException("Cannot access fedpkg repository:")

        return run_command(directory, "fedpkg push",
                           f"Pushing branch {branch!r} to Fedora failed:",
                           fail)
Ejemplo n.º 15
0
 def fetch_tags(self):
     """
     Fetch all tags from origin
     """
     return run_command(self.repo_path,
                        'git fetch --tags',
                        'Unable to fetch tags from remote server',
                        fail=True)
Ejemplo n.º 16
0
 def push(self, branch):
     """
     Executes git push
     :param branch: branch to push
     :return:
     """
     success = run_command(self.repo_path, f'git push origin {branch}', '', False)
     if not success:
         raise GitException(f"Can't push branch {branch} to origin!")
Ejemplo n.º 17
0
    def fedpkg_spectool(directory, branch, fail=True):
        if not os.path.isdir(directory):
            raise ReleaseException("Cannot access fedpkg repository:")

        spec_files = glob(os.path.join(directory, "*spec"))
        spec_files = " ".join(spec_files)
        return run_command(
            directory, f"spectool -g {spec_files}",
            f"Retrieving new sources for branch {branch} failed:", fail)
Ejemplo n.º 18
0
 def init_ticket(keytab, fas_username):
     if not fas_username:
         return False
     if keytab and os.path.isfile(keytab):
         cmd = f"kinit {fas_username}@FEDORAPROJECT.ORG -k -t {keytab}"
     else:
         # there is no keytab, but user still migh have active ticket - try to renew it
         cmd = f"kinit -R {fas_username}@FEDORAPROJECT.ORG"
     return run_command(os.getcwd(), cmd, "Failed to init kerberos ticket:",
                        False)
Ejemplo n.º 19
0
    def fedpkg_clone_repository(directory, name):
        if not os.path.isdir(directory):
            raise ReleaseException(
                "Cannot clone fedpkg repository into non-existent directory:")

        if run_command(directory, f"fedpkg clone {name!r}",
                       "Cloning fedora repository failed:"):
            return os.path.join(directory, name)
        else:
            return ''
Ejemplo n.º 20
0
    def build_wheel(project_root, python_version):
        """
        Builds wheel for specified version of python

        :param project_root: location of setup.py
        :param python_version: python version to build wheel for
        """
        interpreter = "python2"
        if python_version == 3:
            interpreter = "python3"
        elif python_version != 2:
            # no other versions of python other than 2 and three are supported
            raise ReleaseException(f"Unsupported python version: {python_version}")

        if not os.path.isfile(os.path.join(project_root, 'setup.py')):
            raise ReleaseException("Cannot find setup.py:")

        run_command(project_root, f"{interpreter} setup.py bdist_wheel",
                    f"Cannot build wheel for python {python_version}")
Ejemplo n.º 21
0
 def commit(self, message='release commit', allow_empty=False):
     """
     Executes git commit
     :param message: commit message
     :return:
     """
     arg = '--allow-empty' if allow_empty else ''
     success = run_command(self.repo_path, f'git commit {arg} -m \"{message}\"', '', False)
     if not success:
         raise GitException(f"Can't commit files!")
Ejemplo n.º 22
0
 def add(self, files: list):
     """
     Executes git add
     :param files: list of files to add
     :return:
     """
     for file in files:
         success = run_command(self.repo_path, f'git add {file}', '', False)
         if not success:
             raise GitException(f"Can't git add file {file}!")
Ejemplo n.º 23
0
 def clone(url):
     """
     Clones repository from url to temporary directory
     :param url:
     :return: TemporaryDirectory object
     """
     temp_directory = TemporaryDirectory()
     if not run_command(temp_directory.name, f'git clone {url} .',
                        "Couldn't clone repository!", fail=False):
         raise GitException(f"Can't clone repository {url}")
     return temp_directory
Ejemplo n.º 24
0
 def commit(self, message="release commit", allow_empty=False):
     """
     Executes git commit
     :param message: commit message
     :return:
     """
     arg = "--allow-empty" if allow_empty else ""
     success = run_command(
         self.repo_path, f'git commit {arg} -m "{message}"', "", False
     )
     if not success:
         raise GitException("Can't commit files!")
Ejemplo n.º 25
0
    def fedpkg_build(self, directory, branch, scratch=False, fail=True):
        if not os.path.isdir(directory):
            raise ReleaseException("Cannot access fedpkg repository:")

        self.logger.debug(
            f"Building branch {branch!r} in Fedora. It can take a long time.")
        success = run_command(
            directory, f"fedpkg build {'--scratch' if scratch else ''}",
            f"Building branch {branch!r} in Fedora failed:", fail)
        if success:
            self.builds.append(f"{branch}")

        return success
Ejemplo n.º 26
0
 def clone(url):
     """
     Clones repository from url to temporary directory
     :param url:
     :return: TemporaryDirectory object
     """
     temp_directory = mkdtemp()
     if not run_command(
         temp_directory,
         f"git clone {url} .",
         "Couldn't clone repository!",
         fail=True,
     ):
         raise GitException(f"Can't clone repository {url}")
     return temp_directory
Ejemplo n.º 27
0
    def fedpkg_lint(directory, branch, fail=True):
        if not os.path.isdir(directory):
            raise ReleaseException("Cannot access fedpkg repository:")

        return run_command(directory, "fedpkg lint",
                           f"Spec lint on branch {branch} failed:", fail)
Ejemplo n.º 28
0
    def fedpkg_commit(directory, branch, message, fail=True):
        if not os.path.isdir(directory):
            raise ReleaseException("Cannot access fedpkg repository:")

        return run_command(directory, f"fedpkg commit -m '{message}'",
                           f"Committing on branch {branch} failed:", fail)
Ejemplo n.º 29
0
    def fedpkg_switch_branch(directory, branch, fail=True):
        if not os.path.isdir(directory):
            raise ReleaseException("Cannot access fedpkg repository:")

        return run_command(directory, f"fedpkg switch-branch {branch}",
                           f"Switching to {branch} failed:", fail)