Example #1
0
def show_package_env(package, version,
                     branch, patches_branch, local_patches_branch,
                     release=None, dist=None, 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 = 'upstream remote/branch not found'
    else:
        upstream_version = guess.upstream_version(branch=upstream_branch)
        if not upstream_version:
            upstream_version = 'no version tag 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()
    nvr = spec.get_nvr()
    patches_apply_method = spec.patches_apply_method()
    print
    _putv('Package:  ', package)
    _putv('NVR:      ', nvr)
    _putv('Version:  ', version)
    _putv('Upstream: ', upstream_version)
    _putv('Tag style:', version_tag_style or 'X.Y.Z')
    print
    _putv('Patches style:         ', patches_style)
    _putv('Dist-git branch:       ', branch)
    _putv('Local patches branch:  ', local_patches_branch)
    _putv('Remote patches branch: ', patches_branch)
    _putv('Remote upstream branch:', upstream_branch or 'not found')
    if patches_style == 'review':
        _putv('Patches chain:         ', gerrit_review_url)
    print
    _putv('OS dist:               ', osdist)
    _putv('Patches apply method:  ', patches_apply_method)
    if osdist == 'RDO':
        rlsdist = '%s/%s' % (release or 'unknown', dist or 'unknown')
        _putv('RDO release/dist guess:', rlsdist)
        print
Example #2
0
def get_package_env(version=None,
                    release=None,
                    dist=None,
                    branch=None,
                    patches_branch=None,
                    local_patches_branch=None,
                    patches_style=None,
                    gerrit_patches_chain=None,
                    release_bump_index=None):
    if not branch:
        branch = git.current_branch()
    if branch.endswith('-patches'):
        branch = branch[:-8]
        if git.branch_exists(branch):
            log.info(
                "This looks like -patches branch. Assuming distgit branch: "
                "%s" % branch)
            git.checkout(branch)
        else:
            raise exception.InvalidUsage(
                why="This action must be run on a distgit branch.")
    args = {
        'package': guess.package(),
        'branch': branch,
    }
    osdist = guess.osdist()
    if osdist.startswith('RH'):
        log.info("RH package detected.")
        args['fedpkg'] = ['rhpkg']
    if not patches_branch:
        patches_branch = guess.patches_branch(branch,
                                              pkg=args['package'],
                                              osdist=osdist)
    if not patches_style:
        patches_style = guess.patches_style(gerrit_patches_chain)
    args['patches_style'] = patches_style
    args['patches_branch'] = patches_branch
    if release_bump_index is None:
        args['release_bump_index'] = guess.release_bump_index()
    if not local_patches_branch:
        args['local_patches_branch'] = patches_branch.partition('/')[2]
    if not version:
        base_ref = guess.patches_base_ref()
        version, _ = guess.tag2version(base_ref)
        args['version'] = version
    args['version_tag_style'] = guess.version_tag_style(version=version)

    return args
Example #3
0
def get_package_env(version=None, release=None, dist=None, branch=None,
                    patches_branch=None, local_patches_branch=None,
                    patches_style=None, gerrit_patches_chain=None):
    if not branch:
        branch = git.current_branch()
    if branch.endswith('-patches'):
        branch = branch[:-8]
        if git.branch_exists(branch):
            log.info(
                "This looks like -patches branch. Assuming distgit branch: "
                "%s" % branch)
            git.checkout(branch)
        else:
            raise exception.InvalidUsage(
                why="This action must be run on a distgit branch.")
    args = {
        'package': guess.package(),
        'branch': branch,
    }
    if not release or not dist:
        _release, _dist = guess.osreleasedist(branch, default=(None, None))
        if not release and _release:
            args['release'] = _release
        if not dist and _dist:
            args['dist'] = _dist
    osdist = guess.osdist()
    if osdist == 'RHOS':
        log.info("RHOS package detected.")
        args['fedpkg'] = ['rhpkg']
    if not patches_branch:
        patches_branch = guess.patches_branch(branch, pkg=args['package'],
                                              osdist=osdist)
    if not patches_style:
        patches_style = guess.patches_style(gerrit_patches_chain)
    args['patches_style'] = patches_style
    args['patches_branch'] = patches_branch
    if not local_patches_branch:
        args['local_patches_branch'] = patches_branch.partition('/')[2]
    if not version:
        version = guess.current_version()
        args['version'] = version
    args['version_tag_style'] = guess.version_tag_style(version=version)

    return args
Example #4
0
def get_package_env(version=None, release=None, dist=None, branch=None,
                    patches_branch=None, local_patches_branch=None,
                    patches_style=None, gerrit_patches_chain=None,
                    release_bump_index=None):
    if not branch:
        branch = git.current_branch()
    if branch.endswith('-patches'):
        branch = branch[:-8]
        if git.branch_exists(branch):
            log.info(
                "This looks like -patches branch. Assuming distgit branch: "
                "%s" % branch)
            git.checkout(branch)
        else:
            raise exception.InvalidUsage(
                why="This action must be run on a distgit branch.")
    args = {
        'package': guess.package(),
        'branch': branch,
    }
    osdist = guess.osdist()
    if osdist.startswith('RH'):
        log.info("RH package detected.")
        args['fedpkg'] = ['rhpkg']
    if not patches_branch:
        patches_branch = guess.patches_branch(branch, pkg=args['package'],
                                              osdist=osdist)
    if not patches_style:
        patches_style = guess.patches_style(gerrit_patches_chain)
    args['patches_style'] = patches_style
    args['patches_branch'] = patches_branch
    if release_bump_index is None:
        args['release_bump_index'] = guess.release_bump_index()
    if not local_patches_branch:
        args['local_patches_branch'] = patches_branch.partition('/')[2]
    if not version:
        base_ref = guess.patches_base_ref()
        version, _ = guess.tag2version(base_ref)
        args['version'] = version
    args['version_tag_style'] = guess.version_tag_style(version=version)

    return args
Example #5
0
def copr_check(release=None, dist=None):
    osdist = guess.osdist()
    if osdist == 'RHOS':
        helpers.confirm("Look like you're trying to build RHOS package in "
                        "public copr.\nProceed anyway?")
    if not release:
        raise exception.CantGuess(what='release',
                                  why="Specify with -r/--release")

    if not dist:
        builds = guess.builds(release=release)
        for dist_, src in builds:
            if src.startswith('copr/jruzicka'):
                dist = dist_
                log.info("Autodetected dist: %s" % dist)
                break
        if not dist:
            raise exception.CantGuess(what='dist',
                                      why="Specify with -d/--dist")
        return {'dist': dist}
Example #6
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)
Example #7
0
def main():
    parser = argparse.ArgumentParser(
        formatter_class=argparse.RawDescriptionHelpFormatter,
    )
    parser.add_argument(
        '--patches-branch',
        help='Specify another local "patches" branch, like "ceph-5.0-rhel-patches-bz12345"',
    )
    args = parser.parse_args()
    spec = specfile.Spec()

    name = spec.get_tag('Name', expand_macros=True)  # "ceph"
    version = spec.get_tag('Version', expand_macros=True)  # "12.2.8"
    orig_commit = spec.get_macro('commit')  # "9e20ef1b14ac70dea53123"

    branch = git.current_branch()  # "ceph-3.2-rhel-7"
    tag_style = guess.version_tag_style(version=version)  # "vX.Y.Z"
    base_tag = guess.version2tag(version, tag_style)  # "v12.2.8"
    osdist = guess.osdist()

    # "ceph-3.2-rhel-patches"
    if args.patches_branch:
        patches_branch = args.patches_branch
    else:
        remote_patches_branch = guess.patches_branch(branch, pkg=name,
                                                     osdist=osdist)
        patches_branch = remote_patches_branch.partition('/')[2]

    patches_sha = git('rev-parse', patches_branch)  # "9e20ef1b14ac70dea53123"

    archive_basename = '%s-%s' % (name, version)  # "ceph-12.2.8"
    patches_base, patches_base_commits = spec.get_patches_base()
    if patches_base_commits != 0:
        # We don't yet support the "+n_commits" syntax for patches_base.
        raise NotImplementedError('use a plain ref in patches_base')
    if patches_base is None:
        patches_base = base_tag
    filenames = diff_filenames(patches_base, patches_branch)
    if not filenames:
        # todo: make this a silent no-op eventually
        log.warning('%s identical to %s' % (patches_branch, patches_base))
        raise RuntimeError(patches_base)

    tarball = archive_files(archive_basename, patches_sha, filenames)
    log.info('wrote %s' % tarball)

    # Ensure our spec file will reference this tarball.
    spec.set_macro('commit', patches_sha)
    set_source1(spec)
    spec.save()

    # Find the changelog entries from the Git -patches branch.
    changes = check_new_commits(patches_base, orig_commit, patches_sha)

    if not changes:
        log.info('no changes. exiting')
        raise SystemExit(1)

    # Bump the release and add the %changelog entries.

    # Insert %changelog.
    rdopkg.actions.distgit.actions.update_spec(branch=branch, changes=changes)

    # add + upload this new tarball.
    if guess.new_sources():
        fedpkg = 'fedpkg'
        if osdist.startswith('RH'):
            fedpkg = 'rhpkg'
        clear_old_changes_sources()
        run(fedpkg, 'upload', tarball, direct=True)

    # Commit everything to dist-git
    rdopkg.actions.distgit.actions.commit_distgit_update(branch=branch,
                                                         local_patches_branch=patches_branch)
    # Show the final commit
    rdopkg.actions.distgit.actions.final_spec_diff(branch=branch)
Example #8
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)