aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorGuido Günther <agx@sigxcpu.org>2014-08-19 20:07:35 +0200
committerGuido Günther <agx@sigxcpu.org>2014-08-19 22:02:26 +0200
commitae5805e4db74e844f78777c2fd91f409e0fcd7a8 (patch)
treef28e0d72dda6928b9890fdf60f7fc3889b8f53bc
parent6823e519deaf2a37a3d6225cd0392954c423b569 (diff)
Improve error messages on formatting errors
Make it easier for the user to detect misformated replacement strings in config files and command line options.
-rw-r--r--debian/git-buildpackage.install1
-rw-r--r--gbp/deb/git.py3
-rw-r--r--gbp/format.py44
-rwxr-xr-xgbp/scripts/buildpackage.py7
-rw-r--r--gbp/scripts/import_orig.py3
5 files changed, 53 insertions, 5 deletions
diff --git a/debian/git-buildpackage.install b/debian/git-buildpackage.install
index 9d46900f..1a25e1dc 100644
--- a/debian/git-buildpackage.install
+++ b/debian/git-buildpackage.install
@@ -5,6 +5,7 @@ usr/lib/python2.?/dist-packages/gbp/config.py
usr/lib/python2.?/dist-packages/gbp/dch.py
usr/lib/python2.?/dist-packages/gbp/deb/
usr/lib/python2.?/dist-packages/gbp/errors.py
+usr/lib/python2.?/dist-packages/gbp/format.py
usr/lib/python2.?/dist-packages/gbp/git/
usr/lib/python2.?/dist-packages/gbp/__init__.py
usr/lib/python2.?/dist-packages/gbp/log.py
diff --git a/gbp/deb/git.py b/gbp/deb/git.py
index 6105fe7d..2a848d4f 100644
--- a/gbp/deb/git.py
+++ b/gbp/deb/git.py
@@ -19,6 +19,7 @@
import re
from gbp.git import GitRepository, GitRepositoryError
from gbp.deb.pristinetar import DebianPristineTar
+from gbp.format import format_msg
class DebianGitRepository(GitRepository):
"""A git repository that holds the source of a Debian package"""
@@ -104,7 +105,7 @@ class DebianGitRepository(GitRepository):
>>> DebianGitRepository.version_to_tag("debian/%(version)s", "0:0~0")
'debian/0%0_0'
"""
- return format % dict(version=DebianGitRepository._sanitize_version(version))
+ return format_msg(format, dict(version=DebianGitRepository._sanitize_version(version)))
@staticmethod
def _sanitize_version(version):
diff --git a/gbp/format.py b/gbp/format.py
new file mode 100644
index 00000000..2a4af15c
--- /dev/null
+++ b/gbp/format.py
@@ -0,0 +1,44 @@
+# vim: set fileencoding=utf-8 :
+#
+# (C) 2014 Guido Guenther <agx@sigxcpu.org>
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+"""Format a message"""
+
+from gbp.errors import GbpError
+
+def format_msg(msg, args):
+ """
+ Format a strin with the given dict. Be a bit more verbose than
+ default python about the error cause.
+
+ >>> format_msg("%(foo)", {})
+ Traceback (most recent call last):
+ ...
+ GbpError: Failed to format %(foo): Missing value 'foo' in {}
+ >>> format_msg("%(foo)", {'foo': 'bar'})
+ Traceback (most recent call last):
+ ...
+ GbpError: Failed to format %(foo) with {'foo': 'bar'}: incomplete format
+ >>> format_msg("A %(foo)s is a %(bar)s", {'foo': 'dog', 'bar': 'mamal'})
+ 'A dog is a mamal'
+ """
+ try:
+ return msg % args
+ except ValueError as e:
+ raise GbpError("Failed to format %s with %s: %s" % (msg, args, e))
+ except KeyError as e:
+ raise GbpError("Failed to format %s: Missing value %s in %s" % (msg, e, args))
+
+
diff --git a/gbp/scripts/buildpackage.py b/gbp/scripts/buildpackage.py
index 86cf2703..ef058aed 100755
--- a/gbp/scripts/buildpackage.py
+++ b/gbp/scripts/buildpackage.py
@@ -29,6 +29,7 @@ from gbp.command_wrappers import (Command,
from gbp.config import (GbpOptionParserDebian, GbpOptionGroup)
from gbp.deb.git import (GitRepositoryError, DebianGitRepository)
from gbp.deb.source import DebianSource, DebianSourceError
+from gbp.format import format_msg
from gbp.git.vfs import GitVfs
from gbp.deb.upstreamsource import DebianUpstreamSource
from gbp.errors import GbpError
@@ -603,9 +604,9 @@ def main(argv):
gbp.log.info("Tagging %s as %s" % (source.changelog.version, tag))
if options.retag and repo.has_tag(tag):
repo.delete_tag(tag)
- tag_msg=options.debian_tag_msg % dict(
- pkg=source.sourcepkg,
- version=source.changelog.version)
+ tag_msg = format_msg(options.debian_tag_msg,
+ dict(pkg=source.sourcepkg,
+ version=source.changelog.version))
repo.create_tag(name=tag,
msg=tag_msg,
sign=options.sign_tags, keyid=options.keyid)
diff --git a/gbp/scripts/import_orig.py b/gbp/scripts/import_orig.py
index 8eed96b5..a08c1c32 100644
--- a/gbp/scripts/import_orig.py
+++ b/gbp/scripts/import_orig.py
@@ -29,6 +29,7 @@ from gbp.deb.changelog import ChangeLog, NoChangeLogError
from gbp.deb.git import (GitRepositoryError, DebianGitRepository)
from gbp.config import GbpOptionParserDebian, GbpOptionGroup, no_upstream_branch_msg
from gbp.errors import GbpError
+from gbp.format import format_msg
import gbp.log
from gbp.scripts.common.import_orig import (orig_needs_repack, cleanup_tmp_tree,
ask_package_name, ask_package_version,
@@ -373,7 +374,7 @@ def main(argv):
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)()
+ gbpc.Command(format_msg(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()