def main(argv): """Script main function""" options, args = parse_args(argv) if not options: return ExitCodes.parse_error try: init_tmpdir(options.tmp_dir, prefix='rpm-ch_') load_customizations(options.customization_file) editor_cmd = determine_editor(options) repo = RpmGitRepository('.') check_branch(repo, options) # Find and parse spec file spec = parse_spec_file(repo, options) # Find and parse changelog file ch_file = parse_changelog_file(repo, spec, options) since = get_start_commit(ch_file.changelog, repo, options) # Get range of commits from where to generate changes if args: gbp.log.info("Only looking for changes in '%s'" % ", ".join(args)) commits = repo.get_commits(since=since, until='HEAD', paths=args, options=options.git_log.split(" ")) commits.reverse() if not commits: gbp.log.info("No changes detected from %s to %s." % (since, 'HEAD')) # Do the actual update entries = entries_from_commits(ch_file.changelog, repo, commits, options) update_changelog(ch_file.changelog, entries, repo, spec, options) # Write to file ch_file.write() if editor_cmd: gbpc.Command(editor_cmd, [ch_file.path])() except (GbpError, GitRepositoryError, ChangelogError, NoSpecError) as err: if len(err.__str__()): gbp.log.err(err) return 1 except KeyboardInterrupt: gbp.log.err("Interrupted. Aborting.") return 1 finally: del_tmpdir() return 0
def main(argv): """Script main function""" options, args = parse_args(argv) if not options: return 1 try: load_customizations(options.customization_file) editor_cmd = determine_editor(options) repo = RpmGitRepository('.') check_repo_state(repo, options) # Find and parse spec file spec = parse_spec_file(repo, options) # Find and parse changelog file ch_file = parse_changelog_file(repo, spec, options) # Get new entries entries = generate_new_entries(ch_file.changelog, repo, options, args) # Do the actual update tag, author, committer = update_changelog(ch_file.changelog, entries, repo, spec, options) # Write to file ch_file.write() if editor_cmd and not options.message: gbpc.Command(editor_cmd, [ch_file.path])() if options.commit: edit = True if editor_cmd else False msg = create_commit_message(spec, options) commit_changelog(repo, ch_file, msg, author, committer, edit) if options.tag: if options.retag and repo.has_tag(tag): repo.delete_tag(tag) create_packaging_tag(repo, tag, 'HEAD', spec.version, options) except (GbpError, GitRepositoryError, ChangelogError, NoSpecError) as err: if len(err.__str__()): gbp.log.err(err) return 1 return 0
def debian_branch_merge(repo, tag, version, options): try: func = globals()["debian_branch_merge_by_%s" % options.merge_mode] except KeyError: raise GbpError("%s is not a valid merge mode" % options.merge_mode) func(repo, tag, version, options) if options.postimport: epoch = '' if os.access('debian/changelog', os.R_OK): # No need to check the changelog file from the # repository, since we're certain that we're on # the debian-branch cp = ChangeLog(filename='debian/changelog') if cp.has_epoch(): epoch = '%s:' % cp.epoch info = {'version': "%s%s-1" % (epoch, version)} env = {'GBP_BRANCH': options.debian_branch} gbpc.Command(format_str(options.postimport, info), extra_env=env, shell=True)()
def fetch_snapshots(pkg, downloaddir): "Fetch snapshots using debsnap von snapshots.debian.org" dscs = None gbp.log.info("Downloading snapshots of '%s' to '%s'..." % (pkg, downloaddir)) debsnap = gbpc.Command("debsnap", [ '--force', '--destdir=%s' % (downloaddir), pkg]) try: debsnap() except gbpc.CommandExecFailed: if debsnap.retcode == 2: gbp.log.warn("Some packages failed to download. Continuing.") pass else: raise dscs = glob.glob(os.path.join(downloaddir, '*.dsc')) if not dscs: raise GbpError('No package downloaded') return [os.path.join(downloaddir, dsc) for dsc in dscs]
def main(argv): ret = 0 tmpdir = '' pristine_orig = None linked = False (options, args) = parse_args(argv) if not options: return 1 try: source = find_source(options.uscan, args) if not source: return ret try: repo = DebianGitRepository('.') except GitRepositoryError: raise GbpError("%s is not a git repository" % (os.path.abspath('.'))) # an empty repo has now branches: initial_branch = repo.get_branch() is_empty = False if initial_branch else True if not repo.has_branch(options.upstream_branch) and not is_empty: raise GbpError(no_upstream_branch_msg % options.upstream_branch) (sourcepackage, version) = detect_name_and_version(repo, source, options) (clean, out) = repo.is_clean() if not clean and not is_empty: gbp.log.err("Repository has uncommitted changes, commit these first: ") raise GbpError(out) if repo.bare: set_bare_repo_options(options) if not source.is_dir(): tmpdir = tempfile.mkdtemp(dir='../') source.unpack(tmpdir, options.filters) gbp.log.debug("Unpacked '%s' to '%s'" % (source.path, source.unpacked)) if source.needs_repack(options): gbp.log.debug("Filter pristine-tar: repacking '%s' from '%s'" % (source.path, source.unpacked)) (source, tmpdir) = repack_source(source, sourcepackage, version, tmpdir, options.filters) (pristine_orig, linked) = prepare_pristine_tar(source.path, sourcepackage, version) # Don't mess up our repo with git metadata from an upstream tarball try: if os.path.isdir(os.path.join(source.unpacked, '.git/')): raise GbpError("The orig tarball contains .git metadata - giving up.") except OSError: pass try: upstream_branch = [ options.upstream_branch, 'master' ][is_empty] filter_msg = ["", " (filtering out %s)" % options.filters][len(options.filters) > 0] gbp.log.info("Importing '%s' to branch '%s'%s..." % (source.path, upstream_branch, filter_msg)) gbp.log.info("Source package is %s" % sourcepackage) gbp.log.info("Upstream version is %s" % version) import_branch = [ options.upstream_branch, None ][is_empty] msg = upstream_import_commit_msg(options, version) if options.vcs_tag: parents = [repo.rev_parse("%s^{}" % options.vcs_tag)] else: parents = None commit = repo.commit_dir(source.unpacked, msg=msg, branch=import_branch, other_parents=parents, ) if options.pristine_tar: if pristine_orig: repo.pristine_tar.commit(pristine_orig, upstream_branch) else: gbp.log.warn("'%s' not an archive, skipping pristine-tar" % source.path) tag = repo.version_to_tag(options.upstream_tag, version) repo.create_tag(name=tag, msg="Upstream version %s" % version, commit=commit, sign=options.sign_tags, keyid=options.keyid) if is_empty: repo.create_branch(options.upstream_branch, rev=commit) repo.force_head(options.upstream_branch, hard=True) elif options.merge: gbp.log.info("Merging to '%s'" % options.debian_branch) repo.set_branch(options.debian_branch) try: repo.merge(tag) except GitRepositoryError: raise GbpError("Merge failed, please resolve.") if options.postimport: epoch = '' if os.access('debian/changelog', os.R_OK): # No need to check the changelog file from the # repository, since we're certain that we're on # the debian-branch cp = ChangeLog(filename='debian/changelog') if cp.has_epoch(): epoch = '%s:' % cp.epoch info = { 'version': "%s%s-1" % (epoch, version) } env = { 'GBP_BRANCH': options.debian_branch } gbpc.Command(options.postimport % info, extra_env=env, shell=True)() # Update working copy and index if we've possibly updated the # checked out branch current_branch = repo.get_branch() if current_branch in [ options.upstream_branch, repo.pristine_tar_branch]: repo.force_head(current_branch, hard=True) except (gbpc.CommandExecFailed, GitRepositoryError) as err: msg = err.__str__() if len(err.__str__()) else '' raise GbpError("Import of %s failed: %s" % (source.path, msg)) except GbpError as err: if len(err.__str__()): gbp.log.err(err) ret = 1 if pristine_orig and linked and not options.symlink_orig: os.unlink(pristine_orig) if tmpdir: cleanup_tmp_tree(tmpdir) if not ret: gbp.log.info("Successfully imported version %s of %s" % (version, source.path)) return ret
def main(argv): ret = 0 changelog = 'debian/changelog' until = 'HEAD' found_snapshot_banner = False version_change = {} branch = None options, args, dch_options, editor_cmd = parse_args(argv) try: try: repo = DebianGitRepository('.') except GitRepositoryError: raise GbpError("%s is not a git repository" % (os.path.abspath('.'))) try: branch = repo.get_branch() except GitRepositoryError: # Not being on any branch is o.k. with --ignore-branch if not options.ignore_branch: raise if options.packaging_branch != branch and not options.ignore_branch: gbp.log.err("You are not on branch '%s' but on '%s'" % (options.packaging_branch, branch)) raise GbpError("Use --ignore-branch to ignore or --debian-branch " "to set the branch name.") source = DebianSource('.') cp = source.changelog if options.since: since = options.since else: since = '' if options.auto: since = guess_documented_commit(cp, repo, options.packaging_tag) if since: msg = "Continuing from commit '%s'" % since else: msg = "Starting from first commit" gbp.log.info(msg) found_snapshot_banner = has_snapshot_banner(cp) else: # Fallback: continue from last tag since = repo.find_version(options.packaging_tag, cp['Version']) if not since: raise GbpError("Version %s not found" % cp['Version']) if args: gbp.log.info("Only looking for changes on '%s'" % " ".join(args)) commits = repo.get_commits(since=since, until=until, paths=args, options=options.git_log.split(" ")) commits.reverse() # add a new changelog section if: if (options.new_version or options.bpo or options.nmu or options.qa or options.team or options.security): if options.bpo: version_change['increment'] = '--bpo' elif options.nmu: version_change['increment'] = '--nmu' elif options.qa: version_change['increment'] = '--qa' elif options.team: version_change['increment'] = '--team' elif options.security: version_change['increment'] = '--security' else: version_change['version'] = options.new_version # the user wants to force a new version add_section = True elif cp['Distribution'] != "UNRELEASED" and not found_snapshot_banner and commits: # the last version was a release and we have pending commits add_section = True elif options.snapshot and not found_snapshot_banner: # the user want to switch to snapshot mode add_section = True else: add_section = False if add_section and not version_change and not source.is_native(): # Get version from upstream if none provided v = guess_version_from_upstream(repo, options.upstream_tag, cp) if v: version_change['version'] = v i = 0 for c in commits: i += 1 parsed = parse_commit(repo, c, options, last_commit=i == len(commits)) commit_msg, (commit_author, commit_email) = parsed if not commit_msg: # Some commits can be ignored continue if add_section: # Add a section containing just this message (we can't # add an empty section with dch) cp.add_section(distribution="UNRELEASED", msg=commit_msg, version=version_change, author=commit_author, email=commit_email, dch_options=dch_options) # Adding a section only needs to happen once. add_section = False else: cp.add_entry(commit_msg, commit_author, commit_email, dch_options) # Show a message if there were no commits (not even ignored # commits). if not commits: gbp.log.info("No changes detected from %s to %s." % (since, until)) if add_section: # If we end up here, then there were no commits to include, # so we put a dummy message in the new section. cp.add_section(distribution="UNRELEASED", msg=["UNRELEASED"], version=version_change, dch_options=dch_options) fixup_section(repo, use_git_author=options.use_git_author, options=options, dch_options=dch_options) if options.release: do_release(changelog, repo, cp, use_git_author=options.use_git_author, dch_options=dch_options) elif options.snapshot: (snap, version) = do_snapshot(changelog, repo, options.snapshot_number) gbp.log.info("Changelog has been prepared for snapshot #%d at %s" % (snap, version)) if editor_cmd: gbpc.Command(editor_cmd, ["debian/changelog"])() if options.commit: # Get the version from the changelog file (since dch might # have incremented it, there's no way we can already know # the version). version = ChangeLog(filename=changelog).version # Commit the changes to the changelog file msg = changelog_commit_msg(options, version) repo.commit_files([changelog], msg) gbp.log.info("Changelog has been committed for version %s" % version) except (gbpc.CommandExecFailed, GbpError, GitRepositoryError, DebianSourceError, NoChangeLogError) as err: if len(err.__str__()): gbp.log.err(err) ret = 1 return ret
def main(argv): ret = 0 (options, args) = parse_args(argv) if not options: return 1 tmpdir = tempfile.mkdtemp(dir=options.tmp_dir, prefix='import-orig-rpm_') try: try: repo = RpmGitRepository('.') except GitRepositoryError: raise GbpError, "%s is not a git repository" % ( os.path.abspath('.')) spec = find_spec(repo, options) source = find_source(spec, options, args) # an empty repo has now branches: initial_branch = repo.get_branch() is_empty = False if initial_branch else True if not repo.has_branch(options.upstream_branch): if options.create_missing_branches: gbp.log.info("Will create missing branch '%s'" % options.upstream_branch) elif is_empty: options.create_missing_branches = True else: raise GbpError(no_upstream_branch_msg % options.upstream_branch) sourcepackage, version = detect_name_and_version( repo, source, spec, options) (clean, out) = repo.is_clean() if not clean and not is_empty: gbp.log.err( "Repository has uncommitted changes, commit these first: ") raise GbpError, out if repo.bare: set_bare_repo_options(options) # Prepare sources for importing if options.pristine_tar: prepare_pristine = pristine_tarball_name( source, sourcepackage, version, options.pristine_tarball_name) else: prepare_pristine = None unpacked_orig, pristine_orig = \ prepare_sources(source, sourcepackage, version, prepare_pristine, options.filters, options.filter_pristine_tar, options.orig_prefix, tmpdir) # Don't mess up our repo with git metadata from an upstream tarball if os.path.isdir(os.path.join(unpacked_orig, '.git/')): raise GbpError("The orig tarball contains .git metadata - " "giving up.") try: filter_msg = ["", " (filtering out %s)" % options.filters ][len(options.filters) > 0] gbp.log.info("Importing '%s' to branch '%s'%s..." % (source.path, options.upstream_branch, filter_msg)) gbp.log.info("Source package is %s" % sourcepackage) gbp.log.info("Upstream version is %s" % version) msg = upstream_import_commit_msg(options, version) if options.vcs_tag: parents = [repo.rev_parse("%s^{}" % options.vcs_tag)] else: parents = None commit = repo.commit_dir( unpacked_orig, msg=msg, branch=options.upstream_branch, other_parents=parents, create_missing_branch=options.create_missing_branches) if options.pristine_tar and pristine_orig: gbp.log.info("Pristine-tar: commiting %s" % pristine_orig) repo.pristine_tar.commit(pristine_orig, options.upstream_branch) tag_str_fields = dict(upstreamversion=version, vendor="Upstream") tag = repo.version_to_tag(options.upstream_tag, tag_str_fields) repo.create_tag(name=tag, msg="Upstream version %s" % version, commit=commit, sign=options.sign_tags, keyid=options.keyid) if options.merge: gbp.log.info("Merging to '%s'" % options.packaging_branch) if repo.has_branch(options.packaging_branch): repo.set_branch(options.packaging_branch) try: repo.merge(tag) except GitRepositoryError: raise GbpError, """Merge failed, please resolve.""" else: repo.create_branch(options.packaging_branch, rev=options.upstream_branch) if repo.get_branch() == options.packaging_branch: repo.force_head(options.packaging_branch, hard=True) if options.postimport: info = {'upstreamversion': version} env = {'GBP_BRANCH': options.packaging_branch} gbpc.Command(options.postimport % info, extra_env=env, shell=True)() # Update working copy and index if we've possibly updated the # checked out branch current_branch = repo.get_branch() if (current_branch == options.upstream_branch or current_branch == repo.pristine_tar_branch): repo.force_head(current_branch, hard=True) except (GitRepositoryError, gbpc.CommandExecFailed): raise GbpError, "Import of %s failed" % source.path except GbpError, err: if len(err.__str__()): gbp.log.err(err) ret = 1
def main(argv): ret = 0 changelog = 'debian/changelog' until = 'HEAD' found_snapshot_banner = False version_change = {} branch = None options, args, dch_options, editor_cmd = parse_args(argv) if not options: return ExitCodes.parse_error try: old_cwd = os.path.abspath(os.path.curdir) try: repo = DebianGitRepository('.', toplevel=False) os.chdir(repo.path) except GitRepositoryError: raise GbpError("%s is not a git repository" % (os.path.abspath('.'))) get_customizations(options.customization_file) try: branch = repo.get_branch() except GitRepositoryError: # Not being on any branch is o.k. with --ignore-branch if not options.ignore_branch: raise if options.debian_branch != branch and not options.ignore_branch: gbp.log.err("You are not on branch '%s' but on '%s'" % (options.debian_branch, branch)) raise GbpError( "Use --ignore-branch to ignore or --debian-branch to set the branch name." ) source = DebianSource('.') cp = maybe_create_changelog(repo, source, options) if options.since: since = options.since else: since = guess_documented_commit(cp, repo, options.debian_tag) if since: msg = "Continuing from commit '%s'" % since else: msg = "Starting from first commit" gbp.log.info(msg) found_snapshot_banner = has_snapshot_banner(cp) if args: gbp.log.info("Only looking for changes on '%s'" % " ".join(args)) commits = repo.get_commits(since=since, until=until, paths=args, options=options.git_log.split(" ")) commits.reverse() add_section = False # add a new changelog section if: if (options.new_version or options.bpo or options.nmu or options.qa or options.team or options.security or options.local_suffix): if options.bpo: version_change['increment'] = '--bpo' elif options.nmu: version_change['increment'] = '--nmu' elif options.qa: version_change['increment'] = '--qa' elif options.team: version_change['increment'] = '--team' elif options.security: version_change['increment'] = '--security' elif options.local_suffix: version_change[ 'increment'] = '--local=%s' % options.local_suffix else: version_change['version'] = options.new_version # the user wants to force a new version add_section = True elif cp['Distribution'] != "UNRELEASED" and not found_snapshot_banner: if commits: # the last version was a release and we have pending commits add_section = True if options.snapshot: # the user want to switch to snapshot mode add_section = True if add_section and not version_change and not source.is_native(): # Get version from upstream if none provided v = guess_version_from_upstream(repo, options.upstream_tag, options.upstream_branch, cp) if v: version_change['version'] = v i = 0 for c in commits: i += 1 parsed = parse_commit(repo, c, options, last_commit=(i == len(commits))) commit_msg, (commit_author, commit_email) = parsed if not commit_msg: # Some commits can be ignored continue if add_section: # Add a section containing just this message (we can't # add an empty section with dch) cp.add_section(distribution="UNRELEASED", msg=commit_msg, version=version_change, author=commit_author, email=commit_email, dch_options=dch_options) # Adding a section only needs to happen once. add_section = False else: cp.add_entry(commit_msg, commit_author, commit_email, dch_options) # Show a message if there were no commits (not even ignored # commits). if not commits: gbp.log.info("No changes detected from %s to %s." % (since, until)) if add_section: # If we end up here, then there were no commits to include, # so we put a dummy message in the new section. cp.add_section(distribution="UNRELEASED", msg=["UNRELEASED"], version=version_change, dch_options=dch_options) fixup_section(repo, use_git_author=options.use_git_author, options=options, dch_options=dch_options) if options.release: do_release(changelog, repo, cp, use_git_author=options.use_git_author, dch_options=dch_options) elif options.snapshot: (snap, commit, version) = do_snapshot(changelog, repo, options.snapshot_number) gbp.log.info("Changelog %s (snapshot #%d) prepared up to %s" % (version, snap, commit[:7])) if editor_cmd: gbpc.Command(editor_cmd, ["debian/changelog"])() if options.postedit: cp = ChangeLog(filename=changelog) Hook('Postimport', options.postedit, extra_env={'GBP_DEBIAN_VERSION': cp.version})() if options.commit: # Get the version from the changelog file (since dch might # have incremented it, there's no way we can already know # the version). version = ChangeLog(filename=changelog).version # Commit the changes to the changelog file msg = changelog_commit_msg(options, version) repo.commit_files([changelog], msg) gbp.log.info("Changelog committed for version %s" % version) except KeyboardInterrupt: ret = 1 gbp.log.err("Interrupted. Aborting.") except (gbpc.CommandExecFailed, GbpError, GitRepositoryError, DebianSourceError, NoChangeLogError) as err: if str(err): gbp.log.err(err) ret = 1 maybe_debug_raise() finally: os.chdir(old_cwd) return ret