コード例 #1
0
def update_spec(spec_path, new_release):
    """
    Update spec with new version and changelog for that version, change release to 1

    :param spec_path: Path to package .spec file
    :param new_release: an array containing info about new release, see main() for definition
    """
    if not os.path.isfile(spec_path):
        raise ReleaseException("No spec file found in dist-git repository!")

    # make changelog and get version
    locale.setlocale(locale.LC_TIME, "en_US.UTF-8")
    changelog = (
        f"* {datetime.datetime.now():%a %b %d %Y} {new_release['author_name']!s} "
        f"<{new_release['author_email']!s}> {new_release['version']}-1\n")
    # add entries
    if new_release.get('changelog'):
        for item in new_release['changelog']:
            changelog += f"- {item}\n"
    else:
        changelog += f"- {new_release['version']} release\n"
    # change the version and add changelog in spec file
    with open(spec_path, 'r+') as spec_file:
        spec = spec_file.read()
        # replace version
        spec = re.sub(r'(Version:\s*)([0-9]|[.])*',
                      r'\g<1>' + new_release['version'], spec)
        # make release 1
        spec = re.sub(r'(Release:\s*)([0-9]*)(.*)', r'\g<1>1\g<3>', spec)
        # insert changelog
        spec = re.sub(r'(%changelog\n)', r'\g<1>' + changelog + '\n', spec)
        # write and close
        spec_file.seek(0)
        spec_file.write(spec)
        spec_file.truncate()
        spec_file.close()
コード例 #2
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)
コード例 #3
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)
コード例 #4
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)
コード例 #5
0
 def detect_api_errors(response):
     """This function looks for errors in API response"""
     msg = '\n'.join((err['message'] for err in response.get('errors', [])))
     if msg:
         raise ReleaseException(msg)