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 }
def reqcheck_spec(ref=None, reqs_txt=None): if (ref and reqs_txt) or (not ref and not reqs_txt): raise exception.InvalidUsage( why="reqcheck_spec needs either ref (git ref) or reqs_txt (path)") if ref: reqs_txt = get_reqs_from_ref(ref) else: reqs_txt = get_reqs_from_path(reqs_txt) map_reqs2pkgs(reqs_txt, 'epel') spec_reqs = get_reqs_from_spec() return reqcheck(reqs_txt, spec_reqs)
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
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
def clone( package, force_fetch=False, use_master_distgit=False, gerrit_remotes=False, review_user=None): inforepo = rdoinfo.get_default_inforepo() inforepo.init(force_fetch=force_fetch) pkg = inforepo.get_package(package) if not pkg: raise exception.InvalidRDOPackage(package=package) if use_master_distgit: try: distgit = pkg['master-distgit'] distgit_str = 'master-distgit' except KeyError: raise exception.InvalidUsage( msg="-m/--use-master-distgit used but 'master-distgit' " "missing in rdoinfo for package: %s" % package) else: distgit = pkg['distgit'] distgit_str = 'distgit' log.info("Cloning {dg} into ./{t.bold}{pkg}{t.normal}/".format( t=log.term, dg=distgit_str, pkg=package)) patches = pkg.get('patches') upstream = pkg.get('upstream') review_patches = pkg.get('review-patches') review_origin = pkg.get('review-origin') git('clone', distgit, package) with helpers.cdir(package): if gerrit_remotes: log.info('Adding gerrit-origin remote...') git('remote', 'add', 'gerrit-origin', distgit) if patches: log.info('Adding patches remote...') git('remote', 'add', 'patches', patches) if gerrit_remotes: log.info('Adding gerrit-patches remote...') git('remote', 'add', 'gerrit-patches', patches) else: log.warn("'patches' remote information not available in rdoinfo.") if upstream: log.info('Adding upstream remote...') git('remote', 'add', 'upstream', upstream) else: log.warn("'upstream' remote information not available in rdoinfo.") if patches or upstream: git('fetch', '--all') if not review_user: # USERNAME is an env var used by gerrit review_user = os.environ.get('USERNAME') or os.environ.get('USER') msg_user = ('Using {t.bold}{u}{t.normal} as gerrit username, ' 'you can change it with ' '{t.cmd}git remote set-url {r} ...{t.normal}') if review_patches: log.info('Adding gerrit remote for patch chains reviews...') r = tidy_ssh_user(review_patches, review_user) log.info(msg_user.format(u=review_user, r='review-patches', t=log.term)) git('remote', 'add', 'review-patches', r) else: log.warn("'review-patches' remote information not available" " in rdoinfo.") if review_origin: log.info('Adding gerrit remote for reviews...') r = tidy_ssh_user(review_origin, review_user) log.info(msg_user.format(u=review_user, r='review-origin', t=log.term)) git('remote', 'add', 'review-origin', r) else: log.warn("'review-origin' remote information not available" " in rdoinfo.") git('remote', '-v', direct=True)
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): 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) 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: helpers.confirm( msg="It seems the package is already at version %s\n\n" "Run new-version anyway?" % version, default_yes=False) args['changes'] = ['Update to %s' % new_version] 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: 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
def reqquery(reqs_file=None, reqs_ref=None, spec=False, filter=None, dump=None, dump_file=None, load=None, load_file=None, verbose=False): if not (reqs_ref or reqs_file or spec or load or load_file): reqs_ref = guess.patches_base_ref() if not (bool(reqs_ref) ^ bool(reqs_file) ^ bool(spec) ^ bool(load) ^ bool(load_file)): raise exception.InvalidUsage( why="Only one requirements source (-r/-R/-s/-l/-L) can be " "selected.") if dump and dump_file: raise exception.InvalidUsage( why="Only one dump method (-d/-D) can be selected.") if dump: dump_file = 'requirements.yml' if load: load_file = 'requirements.yml' # get query results as requested if load_file: log.info("Loading query results from file: %s" % load_file) r = yaml.load(open(load_file)) else: release, dist = None, None if not filter: try: release, dist = guess.osreleasedist() log.info('Autodetected filter: %s/%s' % (release, dist)) except exception.CantGuess as ex: raise exception.CantGuess( msg='%s\n\nPlease select RELEASE(/DIST) filter to query.' % str(ex)) else: release, _, dist = filter.partition('/') module2pkg = True if reqs_file: log.info("Querying requirements file: %s" % reqs_file) reqs = _reqs.get_reqs_from_path(reqs_file) elif reqs_ref: log.info("Querying requirements file from git: " "%s -- requirements.txt" % reqs_ref) reqs = _reqs.get_reqs_from_ref(reqs_ref) else: log.info("Querying .spec file") module2pkg = False reqs = _reqs.get_reqs_from_spec(as_objects=True) log.info('') r = _reqs.reqquery(reqs, release=release, dist=dist, module2pkg=module2pkg, verbose=verbose) if dump_file: log.info("Saving query results to file: %s" % dump_file) yaml.dump(r, open(dump_file, 'w')) _reqs.print_reqquery(r)
def check_new_patches(version, local_patches_branch, patches_style=None, local_patches=False, patches_branch=None, changes=None, version_tag_style=None, changelog=None, no_bump=False): if no_bump: return if not changes: changes = [] if changelog: changelog = changelog.lower() else: # default changelog format changelog = 'detect' if changelog == 'detect' or changelog == 'count': if local_patches or patches_style == 'review': head = local_patches_branch else: if not patches_branch: raise exception.RequiredActionArgumentNotAvailable( action='check_new_patches', arg='patches_branch') head = patches_branch version_tag = guess.version2tag(version, version_tag_style) patches = git.get_commit_bzs(version_tag, head) old_patches = specfile.get_patches_from_files() spec = specfile.Spec() n_git_patches = len(patches) n_ignore_patches = 0 ignore_regex = spec.get_patches_ignore_regex() if ignore_regex: patches = (flatten(_partition_patches(patches, ignore_regex))) n_ignore_patches = n_git_patches - len(patches) n_skip_patches = spec.get_n_excluded_patches() if n_skip_patches > 0: patches = patches[0:-n_skip_patches] log.debug("Total patches in git:%d skip:%d ignore:%d" % (n_git_patches, n_skip_patches, n_ignore_patches)) if changelog == 'detect': # detect new/old patches by hash/subject def _patch_filter(c): hash, subj, bzs = c for _, old_hash, old_subj in old_patches: if helpers.is_same_hash(hash, old_hash): return False if helpers.is_same_subject(subj, old_subj): # maybe more relaxed match on subjects? return False return True patches = filter(_patch_filter, patches) elif changelog == 'count': # assume no removed patches, include new ones in changelog n_base_patches = n_skip_patches + spec.get_n_patches() if n_base_patches > 0: patches = patches[0:-n_base_patches] for _, subj, bzs in patches: bzstr = ' '.join(map(lambda x: 'rhbz#%s' % x, bzs)) if bzstr: subj += ' (%s)' % bzstr changes.append(subj) elif changelog == 'plain': # just leave a generic message without inspecting commits (see below) pass else: raise exception.InvalidUsage(why="Not a valid changelog format: %s" % changelog) if not changes: changes.append('Update patches') return {'changes': changes}