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}:") shell_command(directory, f"fedpkg clone {name!r} --anonymous", "Cloning fedora repository failed:") return str(directory / name)
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 = shell_command(self.repo_path, f'git config user.email "{email}"', '', fail=False) name = shell_command(self.repo_path, f'git config user.name "{name}"', '', fail=False) return email and name
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')): shell_command(project_root, "python setup.py sdist", "Cannot build sdist:") else: raise ReleaseException("Cannot find setup.py:")
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") shell_command(project_root, f"twine upload {files}", "Cannot upload python distribution:") else: raise ReleaseException("dist/ folder cannot be found:")
def fedpkg_new_sources(directory, branch, sources="", fail=True): if not os.path.isdir(directory): raise ReleaseException("Cannot access fedpkg repository:") return shell_command(directory, f"fedpkg new-sources {sources}", f"Adding new sources on branch {branch} failed:", fail)
def checkout_new_branch(self, branch): """ Creates a new local branch :param branch: branch name :return: True on success False on fail """ return shell_command(self.repo_path, f'git checkout -b "{branch}"', '', fail=False)
def fedpkg_sources(directory, branch, fail=True): if not os.path.isdir(directory): raise ReleaseException("Cannot access fedpkg repository:") return shell_command( directory, "fedpkg sources", f"Retrieving sources for branch {branch} failed:", fail)
def fedpkg_merge(directory, branch, ff_only=True, fail=True): if not os.path.isdir(directory): raise ReleaseException("Cannot access fedpkg repository:") return shell_command( directory, f"git merge master {'--ff-only' if ff_only else ''}", f"Merging master to branch {branch!r} failed:", fail)
def fedpkg_push(directory, branch, fail=True): if not os.path.isdir(directory): raise ReleaseException("Cannot access fedpkg repository:") return shell_command(directory, "fedpkg push", f"Pushing branch {branch!r} to Fedora failed:", fail)
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 shell_command(directory, f"spectool -g {spec_files}", f"Retrieving new sources for branch {branch} failed:", fail)
def push(self, branch): """ Executes git push :param branch: branch to push :return: """ success = shell_command(self.repo_path, f'git push origin {branch}', '', False) if not success: raise GitException(f"Can't push branch {branch} to origin!")
def fedpkg_clone_repository(directory, name): if not os.path.isdir(directory): raise ReleaseException("Cannot clone fedpkg repository into non-existent directory:") if shell_command(directory, f"fedpkg clone {name!r}", "Cloning fedora repository failed:"): return os.path.join(directory, name) else: return ''
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 shell_command(os.getcwd(), cmd, "Failed to init kerberos ticket:", False)
def add(self, files: list): """ Executes git add :param files: list of files to add :return: """ for file in files: success = shell_command(self.repo_path, f'git add {file}', '', False) if not success: raise GitException(f"Can't git add file {file}!")
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 = shell_command(self.repo_path, f'git commit {arg} -m \"{message}\"', '', False) if not success: raise GitException(f"Can't commit files!")
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:") shell_command(project_root, f"{interpreter} setup.py bdist_wheel", f"Cannot build wheel for python {python_version}")
def clone(url): """ Clones repository from url to temporary directory :param url: :return: TemporaryDirectory object """ temp_directory = TemporaryDirectory() if not shell_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
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 = shell_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
def fedpkg_commit(directory, branch, message, fail=True): if not os.path.isdir(directory): raise ReleaseException("Cannot access fedpkg repository:") return shell_command(directory, f"fedpkg commit -m '{message}'", f"Committing on branch {branch} failed:", fail)
def fedpkg_switch_branch(directory, branch, fail=True): if not os.path.isdir(directory): raise ReleaseException("Cannot access fedpkg repository:") return shell_command(directory, f"fedpkg switch-branch {branch}", f"Switching to {branch} failed:", fail)
def fedpkg_lint(directory, branch, fail=True): if not os.path.isdir(directory): raise ReleaseException("Cannot access fedpkg repository:") return shell_command(directory, "fedpkg lint", f"Spec lint on branch {branch} failed:", fail)