aboutsummaryrefslogtreecommitdiffhomepage
path: root/gbp/scripts/dch.py
diff options
context:
space:
mode:
Diffstat (limited to 'gbp/scripts/dch.py')
-rw-r--r--gbp/scripts/dch.py127
1 files changed, 72 insertions, 55 deletions
diff --git a/gbp/scripts/dch.py b/gbp/scripts/dch.py
index 230d908b..2835ea9b 100644
--- a/gbp/scripts/dch.py
+++ b/gbp/scripts/dch.py
@@ -19,7 +19,6 @@
from __future__ import print_function
-from six.moves import configparser
import os.path
import re
import sys
@@ -33,6 +32,7 @@ from gbp.deb import compare_versions
from gbp.deb.source import DebianSource, DebianSourceError
from gbp.deb.git import GitRepositoryError, DebianGitRepository
from gbp.deb.changelog import ChangeLog, NoChangeLogError
+from gbp.scripts.common import ExitCodes
user_customizations = {}
snapshot_re = re.compile("\s*\*\* SNAPSHOT build @(?P<commit>[a-z0-9]+)\s+\*\*")
@@ -61,11 +61,15 @@ def get_author_email(repo, use_git_config):
author = email = None
if use_git_config:
- try: author = repo.get_config('user.name')
- except KeyError: pass
+ try:
+ author = repo.get_config('user.name')
+ except KeyError:
+ pass
- try: email = repo.get_config('user.email')
- except KeyError: pass
+ try:
+ email = repo.get_config('user.email')
+ except KeyError:
+ pass
return author, email
@@ -81,7 +85,7 @@ def fixup_section(repo, use_git_author, options, dch_options):
author, email = get_author_email(repo, use_git_author)
used_options = ['distribution', 'urgency']
opts = []
- mainttrailer_opts = [ '--nomainttrailer', '--mainttrailer', '-t' ]
+ mainttrailer_opts = ['--nomainttrailer', '--mainttrailer', '-t']
# This must not be done for snapshots or snapshots changelog entries
# will not be concatenated
@@ -100,7 +104,7 @@ def fixup_section(repo, use_git_author, options, dch_options):
break
else:
opts.append(mainttrailer_opts[0])
- ChangeLog.spawn_dch(msg='', author=author, email=email, dch_options=dch_options+opts)
+ ChangeLog.spawn_dch(msg='', author=author, email=email, dch_options=dch_options + opts)
def snapshot_version(version):
@@ -118,12 +122,12 @@ def snapshot_version(version):
"""
try:
(release, suffix) = version.rsplit('~', 1)
- (snapshot, commit) = suffix.split('.', 1)
+ (snapshot, commit) = suffix.split('.', 1)
if not commit.startswith('gbp'):
raise ValueError
else:
snapshot = int(snapshot)
- except ValueError: # not a snapshot release
+ except ValueError: # not a snapshot release
release = version
snapshot = 0
return release, snapshot
@@ -143,13 +147,13 @@ def mangle_changelog(changelog, cp, snapshot=''):
cr = open(changelog, 'r')
print("%(Source)s (%(MangledVersion)s) "
- "%(Distribution)s; urgency=%(urgency)s\n" % cp, file=cw)
+ "%(Distribution)s; urgency=%(urgency)s\n" % cp, file=cw)
- cr.readline() # skip version and empty line
+ cr.readline() # skip version and empty line
cr.readline()
line = cr.readline()
if snapshot_re.match(line):
- cr.readline() # consume the empty line after the snapshot header
+ cr.readline() # consume the empty line after the snapshot header
line = ''
if snapshot:
@@ -191,7 +195,8 @@ def do_snapshot(changelog, repo, next_snapshot):
cp['MangledVersion'] = "%s~%s" % (release, suffix)
mangle_changelog(changelog, cp, commit)
- return snapshot, commit
+ return snapshot, commit, cp['MangledVersion']
+
def parse_commit(repo, commitid, opts, last_commit=False):
"""Parse a commit and return message, author, and author email"""
@@ -286,10 +291,10 @@ def process_editor_option(options):
elif options.release:
states.append("release")
- if options.spawn_editor in states:
- return "sensible-editor"
- else:
+ if options.spawn_editor == 'never' or options.spawn_editor not in states:
return None
+ else:
+ return "sensible-editor"
def changelog_commit_msg(options, version):
@@ -300,7 +305,7 @@ def build_parser(name):
try:
parser = GbpOptionParserDebian(command=os.path.basename(name),
usage='%prog [options] paths')
- except configparser.ParsingError as err:
+ except GbpError as err:
gbp.log.err(err)
return None
@@ -320,15 +325,17 @@ def build_parser(name):
parser.add_option_group(naming_group)
parser.add_option_group(custom_group)
- parser.add_boolean_config_file_option(option_name = "ignore-branch", dest="ignore_branch")
+ parser.add_boolean_config_file_option(option_name="ignore-branch", dest="ignore_branch")
naming_group.add_config_file_option(option_name="upstream-branch", dest="upstream_branch")
naming_group.add_config_file_option(option_name="debian-branch", dest="debian_branch")
naming_group.add_config_file_option(option_name="upstream-tag", dest="upstream_tag")
naming_group.add_config_file_option(option_name="debian-tag", dest="debian_tag")
naming_group.add_config_file_option(option_name="snapshot-number", dest="snapshot_number",
- help="expression to determine the next snapshot number, default is '%(snapshot-number)s'")
+ help="expression to determine the next snapshot number, "
+ "default is '%(snapshot-number)s'")
parser.add_config_file_option(option_name="git-log", dest="git_log",
- help="options to pass to git-log, default is '%(git-log)s'")
+ help="options to pass to git-log, "
+ "default is '%(git-log)s'")
parser.add_option("-v", "--verbose", action="store_true", dest="verbose", default=False,
help="verbose command execution")
parser.add_config_file_option(option_name="color", dest="color", type='tristate')
@@ -336,42 +343,49 @@ def build_parser(name):
dest="color_scheme")
range_group.add_option("-s", "--since", dest="since", help="commit to start from (e.g. HEAD^^^, debian/0.4.3)")
range_group.add_option("-a", "--auto", action="store_true", dest="auto", default=False,
- help="autocomplete changelog from last snapshot or tag")
+ help="autocomplete changelog from last snapshot or tag")
version_group.add_option("-R", "--release", action="store_true", dest="release", default=False,
- help="mark as release")
+ help="mark as release")
version_group.add_option("-S", "--snapshot", action="store_true", dest="snapshot", default=False,
- help="mark as snapshot build")
+ help="mark as snapshot build")
version_group.add_option("-D", "--distribution", dest="distribution", help="Set distribution")
version_group.add_option("--force-distribution", action="store_true", dest="force_distribution", default=False,
- help="Force the provided distribution to be used, even if it doesn't match the list of known distributions")
+ help="Force the provided distribution to be used, "
+ "even if it doesn't match the list of known distributions")
version_group.add_option("-N", "--new-version", dest="new_version",
- help="use this as base for the new version number")
- version_group.add_option("-U", "--urgency", dest="urgency", help="Set urgency level")
+ help="use this as base for the new version number")
+ version_group.add_config_file_option("urgency", dest="urgency")
version_group.add_option("--bpo", dest="bpo", action="store_true", default=False,
- help="Increment the Debian release number for an upload to backports, and add a backport upload changelog comment.")
+ help="Increment the Debian release number for an upload to backports, "
+ "and add a backport upload changelog comment.")
version_group.add_option("--nmu", dest="nmu", action="store_true", default=False,
- help="Increment the Debian release number for a non-maintainer upload")
+ help="Increment the Debian release number for a non-maintainer upload")
version_group.add_option("--qa", dest="qa", action="store_true", default=False,
- help="Increment the Debian release number for a Debian QA Team upload, and add a QA upload changelog comment.")
+ help="Increment the Debian release number for a Debian QA Team upload, "
+ "and add a QA upload changelog comment.")
version_group.add_option("--team", dest="team", action="store_true", default=False,
- help="Increment the Debian release number for a Debian Team upload, and add a Team upload changelog comment.")
+ help="Increment the Debian release number for a Debian Team upload, "
+ "and add a Team upload changelog comment.")
version_group.add_option("--security", dest="security", action="store_true", default=False,
- help="Increment the Debian release number for a security upload and add a security upload changelog comment.")
+ help="Increment the Debian release number for a security upload and "
+ "add a security upload changelog comment.")
version_group.add_boolean_config_file_option(option_name="git-author", dest="use_git_author")
commit_group.add_boolean_config_file_option(option_name="meta", dest="meta")
commit_group.add_config_file_option(option_name="meta-closes", dest="meta_closes")
commit_group.add_config_file_option(option_name="meta-closes-bugnum", dest="meta_closes_bugnum")
commit_group.add_boolean_config_file_option(option_name="full", dest="full")
commit_group.add_config_file_option(option_name="id-length", dest="idlen",
- help="include N digits of the commit id in the changelog entry, default is '%(id-length)s'",
- type="int", metavar="N")
+ help="include N digits of the commit id in the changelog entry, "
+ "default is '%(id-length)s'",
+ type="int", metavar="N")
commit_group.add_config_file_option(option_name="ignore-regex", dest="ignore_regex",
- help="Ignore commit lines matching regex, default is '%(ignore-regex)s'")
+ help="Ignore commit lines matching regex, "
+ "default is '%(ignore-regex)s'")
commit_group.add_boolean_config_file_option(option_name="multimaint", dest="multimaint")
commit_group.add_boolean_config_file_option(option_name="multimaint-merge", dest="multimaint_merge")
commit_group.add_config_file_option(option_name="spawn-editor", dest="spawn_editor")
parser.add_config_file_option(option_name="commit-msg",
- dest="commit_msg")
+ dest="commit_msg")
parser.add_option("-c", "--commit", action="store_true", dest="commit", default=False,
help="commit changelog file after generating")
@@ -381,15 +395,13 @@ def build_parser(name):
custom_group.add_config_file_option(option_name="customizations",
dest="customization_file",
help=help_msg)
-
-
return parser
def parse_args(argv):
parser = build_parser(argv[0])
if not parser:
- return None, None
+ return [None] * 4
(options, args) = parser.parse_args(argv[1:])
gbp.log.setup(options.color, options.verbose, options.color_scheme)
@@ -397,6 +409,7 @@ def parse_args(argv):
editor_cmd = process_editor_option(options)
return options, args, dch_options, editor_cmd
+
def main(argv):
ret = 0
changelog = 'debian/changelog'
@@ -405,9 +418,11 @@ def main(argv):
version_change = {}
branch = None
-
options, args, dch_options, editor_cmd = parse_args(argv)
+ if not options:
+ return ExitCodes.parse_error
+
try:
try:
repo = DebianGitRepository('.')
@@ -440,7 +455,7 @@ def main(argv):
msg = "Starting from first commit"
gbp.log.info(msg)
found_snapshot_banner = has_snapshot_banner(cp)
- else: # Fallback: continue from last tag
+ else: # Fallback: continue from last tag
since = repo.find_version(options.debian_tag, cp['Version'])
if not since:
raise GbpError("Version %s not found" % cp['Version'])
@@ -451,9 +466,10 @@ def main(argv):
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):
+ options.team or options.security):
if options.bpo:
version_change['increment'] = '--bpo'
elif options.nmu:
@@ -468,14 +484,13 @@ def main(argv):
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
+ 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
@@ -488,7 +503,7 @@ def main(argv):
for c in commits:
i += 1
parsed = parse_commit(repo, c, options,
- last_commit = i == len(commits))
+ last_commit=(i == len(commits)))
commit_msg, (commit_author, commit_email) = parsed
if not commit_msg:
# Some commits can be ignored
@@ -507,7 +522,6 @@ def main(argv):
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:
@@ -527,8 +541,8 @@ def main(argv):
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))
+ (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"])()
@@ -541,8 +555,10 @@ def main(argv):
# 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)
-
+ gbp.log.info("Changelog committed for version %s" % version)
+ except KeyboardInterrupt:
+ ret = 1
+ gbp.log.err("Interrupted. Aborting.")
except (gbpc.CommandExecFailed,
GbpError,
GitRepositoryError,
@@ -553,6 +569,7 @@ def main(argv):
ret = 1
return ret
+
if __name__ == "__main__":
sys.exit(main(sys.argv))