Пример #1
0
def version_tag_style(version=None):
    if not version:
        version = patches_base_ref()
    if git.ref_exists('refs/tags/' + version):
        return None
    elif git.ref_exists('refs/tags/v' + version):
        return 'vX.Y.Z'
    elif git.ref_exists('refs/tags/V' + version):
        return 'VX.Y.Z'
    return None
Пример #2
0
def version_tag_style(version=None):
    if not version:
        version = patches_base_ref()
    if git.ref_exists('refs/tags/' + version):
        return None
    elif git.ref_exists('refs/tags/v' + version):
        return 'vX.Y.Z'
    elif git.ref_exists('refs/tags/V' + version):
        return 'VX.Y.Z'
    return None
Пример #3
0
def get_diff_range(diff_range=None, patches_branch=None, branch=None):
    vtag_from, vtag_to = None, None
    if diff_range:
        n = len(diff_range)
        if n > 2:
            raise exception.InvalidUsage(why="diff only supports one or two "
                                         "positional parameters.")
        if n == 2:
            vtag_from, vtag_to = diff_range
        else:
            vtag_to = diff_range[0]
    if not vtag_from:
        if not patches_branch:
            if not branch:
                branch = guess.current_branch()
            patches_branch = guess.patches_branch(branch)
        if not git.ref_exists('refs/remotes/%s' % patches_branch):
            msg = ("Patches branch not found: %s\n"
                   "Can't guess current version.\n\n"
                   "a) provide git tags/refs yourself a la:\n"
                   "   $ rdopkg reqdiff 1.1.1 2.2.2\n\n"
                   "b) add git remote with expected patches branch" %
                   patches_branch)
            raise exception.CantGuess(msg=msg)
        vtag_from = git.get_latest_tag(branch=patches_branch)
    if not vtag_to:
        upstream_branch = guess.upstream_branch()
        vtag_to = git.get_latest_tag(branch=upstream_branch)
    return {'version_tag_from': vtag_from, 'version_tag_to': vtag_to}
Пример #4
0
def get_diff_range(diff_range=None, patches_branch=None, branch=None):
    vtag_from, vtag_to = None, None
    if diff_range:
        n = len(diff_range)
        if n > 2:
            raise exception.InvalidUsage(why="diff only supports one or two "
                                             "positional parameters.")
        if n == 2:
            vtag_from, vtag_to = diff_range
        else:
            vtag_to = diff_range[0]
    if not vtag_from:
        if not patches_branch:
            if not branch:
                branch = guess.current_branch()
            patches_branch = guess.patches_branch(branch)
        if not git.ref_exists('refs/remotes/%s' % patches_branch):
            msg = ("Patches branch not found: %s\n"
                   "Can't guess current version.\n\n"
                   "a) provide git tags/refs yourself a la:\n"
                   "   $ rdopkg reqdiff 1.1.1 2.2.2\n\n"
                   "b) add git remote with expected patches branch"
                   % patches_branch)
            raise exception.CantGuess(msg=msg)
        vtag_from = git.get_latest_tag(branch=patches_branch)
    if not vtag_to:
        upstream_branch = guess.upstream_branch()
        vtag_to = git.get_latest_tag(branch=upstream_branch)
    return {
        'version_tag_from': vtag_from,
        'version_tag_to': vtag_to
    }
Пример #5
0
def upstream_branch():
    remotes = ['upstream', 'openstack']

    for remote in remotes:
        ub = '%s/master' % remote
        if git.ref_exists('refs/remotes/%s' % ub):
            return ub

    return '%s/master' % remotes[0]
Пример #6
0
def find_patches_branch(distgit, remote):
    cfg_branch = git.config_get('rdopkg.%s.patches-branch' % distgit)

    if cfg_branch:
        # if there is an explicitly configured patches branch, use it.
        pb = '%s/%s' % (remote, cfg_branch)
    else:
        pb = '%s/%s-patches' % (remote, distgit)

    if git.ref_exists('refs/remotes/%s' % pb):
        return pb
    parts = distgit.split('-')[:-1]
    while parts:
        pb = '%s/%s-patches' % (remote, '-'.join(parts))
        if git.ref_exists('refs/remotes/%s' % pb):
            return pb
        parts.pop()
    return None
Пример #7
0
def upstream_branch():
    remotes = ['upstream', 'openstack']

    for remote in remotes:
        ub = '%s/master' % remote
        if git.ref_exists('refs/remotes/%s' % ub):
            return ub

    return '%s/master' % remotes[0]
Пример #8
0
def find_patches_branch(distgit, remote):
    cfg_branch = git.config_get('rdopkg.%s.patches-branch' % distgit)

    if cfg_branch:
        # if there is an explicitly configured patches branch, use it.
        pb = '%s/%s' % (remote, cfg_branch)
    else:
        pb = '%s/%s-patches' % (remote, distgit)

    if git.ref_exists('refs/remotes/%s' % pb):
        return pb
    parts = distgit.split('-')[:-1]
    while parts:
        pb = '%s/%s-patches' % (remote, '-'.join(parts))
        if git.ref_exists('refs/remotes/%s' % pb):
            return pb
        parts.pop()
    return None
Пример #9
0
def upstream_version(branch=None):
    if not branch:
        branch = upstream_branch()
    if git.ref_exists('refs/remotes/%s' % branch):
        vtag = git.get_latest_tag(branch)
        if not vtag:
            return None
        version, _ = tag2version(vtag)
        return version
    return None
Пример #10
0
def upstream_version(branch=None):
    if not branch:
        branch = upstream_branch()
    if git.ref_exists('refs/remotes/%s' % branch):
        vtag = git.get_latest_tag(branch)
        if not vtag:
            return None
        version, _ = tag2version(vtag)
        return version
    return None
Пример #11
0
def clone_distgit(package, release):
    os.chdir(repodir)
    if os.path.exists(package):
        shutil.rmtree(package)
    rdopkg('clone', package, '-u', user)
    os.chdir(package)
    stable_branch = "%s-rdo" % release
    exist_remote = git.ref_exists('refs/remotes/origin/%s' % stable_branch)
    if exist_remote:
        git.create_branch(stable_branch, "origin/%s" % stable_branch)
        git('checkout', stable_branch)
    else:
        raise NotBranchedPackage("Distgit for %s does not contain branch %s" %
                                 (package, stable_branch))
Пример #12
0
def clone_distgit(package, release):
    os.chdir(repodir)
    if os.path.exists(package):
        shutil.rmtree(package)
    rdopkg('clone', package, '-u', user)
    os.chdir(package)
    stable_branch = "%s-rdo" % release
    exist_remote = git.ref_exists('refs/remotes/origin/%s' % stable_branch)
    if exist_remote:
        git.create_branch(stable_branch, "origin/%s" % stable_branch)
        git('checkout', stable_branch)
    else:
        raise NotBranchedPackage("Distgit for %s does not contain branch %s" %
                                 (package, stable_branch))
Пример #13
0
def ensure_patches_branch(patches_branch=None, local_patches=False,
                          bump_only=False, patches_style=None):
    if local_patches or bump_only:
        return
    if not patches_branch:
        raise exception.CantGuess(
            what='remote patches branch',
            why="Specify with --patches-branch or use --local-patches")
    if not git.ref_exists('refs/remotes/%s' % patches_branch):
        raise exception.ConfigError(
            what=("remote patches branch '%s' not found. \n\n"
                  "Specify with -p/--patches-branch, use -l/--local-patches, "
                  "or skip patches branch operations with -b/--bump-only" %
                  patches_branch))
Пример #14
0
def ensure_patches_branch(patches_branch=None,
                          local_patches=False,
                          bump_only=False,
                          patches_style=None):
    if local_patches or bump_only:
        return
    if not patches_branch:
        raise exception.CantGuess(
            what='remote patches branch',
            why="Specify with --patches-branch or use --local-patches")
    if not git.ref_exists('refs/remotes/%s' % patches_branch):
        raise exception.ConfigError(
            what=("remote patches branch '%s' not found. \n\n"
                  "Specify with -p/--patches-branch, use -l/--local-patches, "
                  "or skip patches branch operations with -b/--bump-only" %
                  patches_branch))
Пример #15
0
def is_release_tag(package, version):
    os.chdir("%s/%s" % (repodir, package))
    is_tag = git.ref_exists('refs/tags/%s' % version)
    return is_tag
Пример #16
0
def show_package_env(package,
                     version,
                     branch,
                     patches_branch,
                     local_patches_branch,
                     release_bump_index,
                     version_tag_style=None,
                     patches_style=None,
                     gerrit_patches_chain=None):
    def _putv(title, val):
        print("{t.bold}{title}{t.normal} {val}".format(title=title,
                                                       val=val,
                                                       t=log.term))

    osdist = guess.osdist()

    upstream_branch = guess.upstream_branch()
    if not git.ref_exists('refs/remotes/%s' % upstream_branch):
        upstream_version = log.term.yellow('upstream remote/branch not found')
    else:
        upstream_version = guess.upstream_version(branch=upstream_branch)
        if not upstream_version:
            upstream_version = log.term.yellow('no version tag found')

    remote_hash = git.get_latest_commit_hash(patches_branch)
    local_hash = git.get_latest_commit_hash(local_patches_branch)
    upstream_hash = git.get_latest_commit_hash(upstream_branch)
    if remote_hash:
        remote_str = ("{t.green}{hash}{t.normal}".format(hash=remote_hash[:6],
                                                         t=log.term))
    else:
        remote_str = log.term.red("not found")
    if local_hash:
        color = 'yellow'
        if local_hash == remote_hash:
            color = 'green'
        local_str = (("{t.%s}{hash}{t.normal}" % color).format(
            hash=local_hash[:6], t=log.term))
    else:
        local_str = log.term.yellow("not found")
    if upstream_hash:
        upstream_str = ("{t.green}{hash}{t.normal}".format(
            hash=upstream_hash[:6], t=log.term))
    else:
        upstream_str = log.term.yellow("not found")

    if patches_style == 'review':
        if not gerrit_patches_chain:
            gerrit_patches_chain = guess.gerrit_patches_chain(verbose=False)
        gerrit_review_url = rpmfactory.review_url(gerrit_patches_chain) or \
            'unknown'

    spec = specfile.Spec()
    vr = spec.get_vr()
    spec_version = spec.get_tag('Version')
    patches_apply_method = spec.patches_apply_method()
    patches_base, pbn = spec.get_patches_base()
    patches_base_str = patches_base or ''
    if pbn:
        patches_base_str += "{t.magenta}+{n}{t.normal}".format(n=pbn,
                                                               t=log.term)
    if not patches_base_str:
        patches_base_str = "N/A"
    patches_base_tag = guess.version2tag(version, version_tag_style)
    patches_base_ref_str = patches_base_tag
    if git.ref_exists('refs/tags/' + patches_base_tag):
        pbref_exists = '{t.green}existing git tag{t.normal}'
    else:
        ot = git.object_type(patches_base_tag)
        if ot:
            pbref_exists = '{t.green}existing git %s{t.normal}' % ot
        else:
            pbref_exists = '{t.red}invalid git reference{t.normal}'
    patches_base_ref_str += ' : ' + pbref_exists.format(t=log.term)

    release = spec.get_tag('Release')
    release_style = guess.release_style()
    for name, i in specfile.RELEASE_PARTS_SEMVER.items():
        if release_bump_index == str(i):
            # show release part name as well if available (MAJOR/MINOR/PATCH)
            release_bump_index = '%s / %s' % (release_bump_index, name)
            break

    print('')
    _putv('Package:       ', package)
    _putv('VR:            ', vr)
    _putv('Version:       ', spec_version)
    _putv('Upstream:      ', upstream_version)
    _putv('Release:       ', release)
    _putv('Release style: ', release_style)
    _putv('Rls bump index:', release_bump_index)
    _putv('Tag style:     ', version_tag_style or 'X.Y.Z')
    print('')
    _putv('Dist-git branch:       ', branch)
    _putv('Patches style:         ', patches_style)
    _putv('Patches base:          ', patches_base_str)
    _putv('Patches base ref:      ', patches_base_ref_str)
    _putv('Local patches branch:  ',
          '%s : %s' % (local_patches_branch, local_str))
    _putv('Remote patches branch: ', '%s : %s' % (patches_branch, remote_str))
    _putv('Remote upstream branch:',
          '%s : %s' % (upstream_branch, upstream_str))
    if patches_style == 'review':
        _putv('Patches chain:         ', gerrit_review_url)
    print('')
    _putv('OS dist:               ', osdist)
    _putv('Patches apply method:  ', patches_apply_method)
Пример #17
0
def show_package_env(package, version,
                     branch, patches_branch, local_patches_branch,
                     release_bump_index,
                     version_tag_style=None, patches_style=None,
                     gerrit_patches_chain=None):
    def _putv(title, val):
        print("{t.bold}{title}{t.normal} {val}"
              .format(title=title, val=val, t=log.term))

    osdist = guess.osdist()

    upstream_branch = guess.upstream_branch()
    if not git.ref_exists('refs/remotes/%s' % upstream_branch):
        upstream_version = log.term.yellow('upstream remote/branch not found')
    else:
        upstream_version = guess.upstream_version(branch=upstream_branch)
        if not upstream_version:
            upstream_version = log.term.yellow('no version tag found')

    remote_hash = git.get_latest_commit_hash(patches_branch)
    local_hash = git.get_latest_commit_hash(local_patches_branch)
    upstream_hash = git.get_latest_commit_hash(upstream_branch)
    if remote_hash:
        remote_str = ("{t.green}{hash}{t.normal}"
                      .format(hash=remote_hash[:6], t=log.term))
    else:
        remote_str = log.term.red("not found")
    if local_hash:
        color = 'yellow'
        if local_hash == remote_hash:
            color = 'green'
        local_str = (("{t.%s}{hash}{t.normal}" % color)
                     .format(hash=local_hash[:6], t=log.term))
    else:
        local_str = log.term.yellow("not found")
    if upstream_hash:
        upstream_str = ("{t.green}{hash}{t.normal}"
                        .format(hash=upstream_hash[:6], t=log.term))
    else:
        upstream_str = log.term.yellow("not found")

    if patches_style == 'review':
        if not gerrit_patches_chain:
            gerrit_patches_chain = guess.gerrit_patches_chain(verbose=False)
        gerrit_review_url = rpmfactory.review_url(gerrit_patches_chain) or \
            'unknown'

    spec = specfile.Spec()
    vr = spec.get_vr()
    spec_version = spec.get_tag('Version')
    patches_apply_method = spec.patches_apply_method()
    patches_base, pbn = spec.get_patches_base()
    patches_base_str = patches_base or ''
    if pbn:
        patches_base_str += "{t.magenta}+{n}{t.normal}".format(
            n=pbn, t=log.term)
    if not patches_base_str:
        patches_base_str = "N/A"
    patches_base_tag = guess.version2tag(version, version_tag_style)
    patches_base_ref_str = patches_base_tag
    if git.ref_exists('refs/tags/' + patches_base_tag):
        pbref_exists = '{t.green}existing git tag{t.normal}'
    else:
        ot = git.object_type(patches_base_tag)
        if ot:
            pbref_exists = '{t.green}existing git %s{t.normal}' % ot
        else:
            pbref_exists = '{t.red}invalid git reference{t.normal}'
    patches_base_ref_str += ' : ' + pbref_exists.format(t=log.term)

    release = spec.get_tag('Release')
    release_style = guess.release_style()
    for name, i in specfile.RELEASE_PARTS_SEMVER.items():
        if release_bump_index == str(i):
            # show release part name as well if available (MAJOR/MINOR/PATCH)
            release_bump_index = '%s / %s' % (release_bump_index, name)
            break

    print('')
    _putv('Package:       ', package)
    _putv('VR:            ', vr)
    _putv('Version:       ', spec_version)
    _putv('Upstream:      ', upstream_version)
    _putv('Release:       ', release)
    _putv('Release style: ', release_style)
    _putv('Rls bump index:', release_bump_index)
    _putv('Tag style:     ', version_tag_style or 'X.Y.Z')
    print('')
    _putv('Dist-git branch:       ', branch)
    _putv('Patches style:         ', patches_style)
    _putv('Patches base:          ', patches_base_str)
    _putv('Patches base ref:      ', patches_base_ref_str)
    _putv('Local patches branch:  ',
          '%s : %s' % (local_patches_branch, local_str))
    _putv('Remote patches branch: ',
          '%s : %s' % (patches_branch, remote_str))
    _putv('Remote upstream branch:',
          '%s : %s' % (upstream_branch, upstream_str))
    if patches_style == 'review':
        _putv('Patches chain:         ', gerrit_review_url)
    print('')
    _putv('OS dist:               ', osdist)
    _putv('Patches apply method:  ', patches_apply_method)
Пример #18
0
def new_version_setup(patches_branch=None, local_patches=False,
                      version=None, new_version=None, version_tag_style=None,
                      new_sources=None, no_new_sources=None, unattended=False,
                      bug=None, bump_only=False):
    args = {}
    if new_version:
        # support both version and tag
        ver, _ = guess.tag2version(new_version)
        if ver != new_version:
            new_version = ver
            args['new_version'] = new_version
        new_version_tag = guess.version2tag(new_version, version_tag_style)
        if not bump_only and not git.object_type(new_version_tag):
            raise exception.InvalidGitRef(ref=new_version_tag)
    else:
        ub = guess.upstream_branch()
        if not git.ref_exists('refs/remotes/%s' % ub):
            msg = ("Upstream branch not found: %s\n"
                   "Can't guess latest version.\n\n"
                   "a) provide new version (git tag) yourself\n"
                   "   $ rdopkg new-version 1.2.3\n\n"
                   "b) add upstream git remote:\n"
                   "   $ git remote add -f upstream GIT_URL\n"
                   % ub)
            raise exception.CantGuess(msg=msg)
        new_version_tag = git.get_latest_tag(ub)
        new_version, _ = guess.tag2version(new_version_tag)
        args['new_version'] = new_version
        log.info("Latest version detected from %s: %s" % (ub, new_version))
    if version == new_version:
        if unattended:
            log.info("Package is already at version %s\n" % version)
            raise exception.UserAbort(exit_code=0)
        helpers.confirm(
            msg="It seems the package is already at version %s\n\n"
                "Run new-version anyway?" % version,
            default_yes=False)
    changelog = 'Update to %s' % new_version
    if bug:
        changelog += ' (%s)' % bug
    args['changes'] = [changelog]
    args['new_patches_base'] = new_version_tag
    spec = specfile.Spec()
    rpm_version = spec.get_tag('Version')
    rpm_milestone = spec.get_milestone()
    new_rpm_version, new_milestone = specfile.version_parts(new_version)
    args['new_rpm_version'] = new_rpm_version
    if new_milestone:
        args['new_milestone'] = new_milestone
    if (rpm_version != new_rpm_version
            or bool(new_milestone) != bool(rpm_milestone)):
        if new_milestone:
            args['new_release'] = '0.1'
        else:
            args['new_release'] = '1'
    if not local_patches and not bump_only:
        if not patches_branch or \
           not git.ref_exists('refs/remotes/' + patches_branch):
            log.warn("Patches branch '%s' not found. Running in --bump-only "
                     "mode." % patches_branch)
            args['bump_only'] = True
    if new_sources or no_new_sources:
        if new_sources and no_new_sources:
            raise exception.InvalidUsage(
                msg="DOES NOT COMPUTE: both -n and -N don't make sense.")
        # new_sources == not no_new_sources
    else:
        new_sources = guess.new_sources()
    args['new_sources'] = new_sources

    return args
Пример #19
0
def is_release_tag(package, version):
    os.chdir("%s/%s" % (repodir, package))
    is_tag = git.ref_exists('refs/tags/%s' % version)
    return is_tag
Пример #20
0
def new_version_setup(patches_branch=None,
                      local_patches=False,
                      version=None,
                      new_version=None,
                      version_tag_style=None,
                      new_sources=None,
                      no_new_sources=None,
                      unattended=False,
                      bug=None,
                      bump_only=False):
    args = {}
    if new_version:
        # support both version and tag
        ver, _ = guess.tag2version(new_version)
        if ver != new_version:
            new_version = ver
            args['new_version'] = new_version
        new_version_tag = guess.version2tag(new_version, version_tag_style)
        if not bump_only and not git.object_type(new_version_tag):
            raise exception.InvalidGitRef(ref=new_version_tag)
    else:
        ub = guess.upstream_branch()
        if not git.ref_exists('refs/remotes/%s' % ub):
            msg = ("Upstream branch not found: %s\n"
                   "Can't guess latest version.\n\n"
                   "a) provide new version (git tag) yourself\n"
                   "   $ rdopkg new-version 1.2.3\n\n"
                   "b) add upstream git remote:\n"
                   "   $ git remote add -f upstream GIT_URL\n" % ub)
            raise exception.CantGuess(msg=msg)
        new_version_tag = git.get_latest_tag(ub)
        new_version, _ = guess.tag2version(new_version_tag)
        args['new_version'] = new_version
        log.info("Latest version detected from %s: %s" % (ub, new_version))
    if version == new_version:
        if unattended:
            log.info("Package is already at version %s\n" % version)
            raise exception.UserAbort(exit_code=0)
        helpers.confirm(msg="It seems the package is already at version %s\n\n"
                        "Run new-version anyway?" % version,
                        default_yes=False)
    changelog = 'Update to %s' % new_version
    if bug:
        changelog += ' (%s)' % bug
    args['changes'] = [changelog]
    args['new_patches_base'] = new_version_tag
    spec = specfile.Spec()
    rpm_version = spec.get_tag('Version')
    rpm_milestone = spec.get_milestone()
    new_rpm_version, new_milestone = specfile.version_parts(new_version)
    args['new_rpm_version'] = new_rpm_version
    if new_milestone:
        args['new_milestone'] = new_milestone
    if (rpm_version != new_rpm_version
            or bool(new_milestone) != bool(rpm_milestone)):
        if new_milestone:
            args['new_release'] = '0.1'
        else:
            args['new_release'] = '1'
    if not local_patches and not bump_only:
        if not patches_branch or \
           not git.ref_exists('refs/remotes/' + patches_branch):
            log.warn("Patches branch '%s' not found. Running in --bump-only "
                     "mode." % patches_branch)
            args['bump_only'] = True
    if new_sources or no_new_sources:
        if new_sources and no_new_sources:
            raise exception.InvalidUsage(
                msg="DOES NOT COMPUTE: both -n and -N don't make sense.")
        # new_sources == not no_new_sources
    else:
        new_sources = guess.new_sources()
    args['new_sources'] = new_sources

    return args