On Mon, May 15, 2017 at 10:18:22AM -0700, Vagrant Cascadian wrote:
> File "/home/vagrant/simple-cdd/simple_cdd/utils.py", line 207, in
> verify_file
> raise Fail("Invalid checksum for {}: expected {}, got {}", absname,
> hashsum, hasher.hexdigest())
> simple_cdd.exceptions.Fail: <unprintable Fail object>
>
> During handling of the above exception, another exception occurred:
>
> Traceback (most recent call last):
> File "/home/vagrant/simple-cdd/simple_cdd/log.py", line 85, in emit
> record.message = record.getMessage()
> File "/usr/lib/python3.5/logging/__init__.py", line 331, in getMessage
> msg = msg % self.args
> TypeError: not all arguments converted during string formattingFail used %-formatting internally, but it was sometimes called with printf-style format strings and sometimes with string.format style format strings. I'm attaching a patch that unifies everything to string.format-style strings. Enrico -- GPG key: 4096R/634F4BD1E7AD5568 2009-05-08 Enrico Zini <[email protected]>
From 1b2196f7c9c3607c347a4be76a2b4c4cee1c7c7b Mon Sep 17 00:00:00 2001 From: Enrico Zini <[email protected]> Date: Mon, 15 May 2017 20:29:40 +0200 Subject: [PATCH] Standardised Fail behaviour on string.format --- build-simple-cdd | 10 +++++----- simple_cdd/exceptions.py | 2 +- simple_cdd/gnupg.py | 6 +++--- simple_cdd/tools/base.py | 4 ++-- simple_cdd/tools/mirror_reprepro.py | 8 ++++---- simple_cdd/utils.py | 2 +- 6 files changed, 16 insertions(+), 16 deletions(-) diff --git a/build-simple-cdd b/build-simple-cdd index 5da6284..f629e58 100755 --- a/build-simple-cdd +++ b/build-simple-cdd @@ -175,7 +175,7 @@ class SimpleCDD: if self.args.force_preseed: log.warn("preseed file invalid: %s", p) else: - raise Fail("preseed file invalid: %s", p) + raise Fail("preseed file invalid: {}", p) def paranoid_checks(self): @@ -280,7 +280,7 @@ class SimpleCDD: log.info("re-setting mirror for new debpartial-mirror dir: %s", self.env.get("MIRROR")) if not os.path.isdir(self.env.get("MIRROR")): - raise Fail("mirror dir is not a directory: %s", self.env.get("MIRROR")) + raise Fail("mirror dir is not a directory: {}", self.env.get("MIRROR")) log.debug("Checking if the mirror is complete...") self.checkpackages() @@ -380,7 +380,7 @@ class SimpleCDD: elif isinstance(val, int): val = str(val) else: - raise Fail("Unknown variable type for value %s=%r", name, val) + raise Fail("Unknown variable type for value {}={!r}", name, val) log.info("export %s=%s", name, shell_quote(val)) os.environ[name] = val @@ -408,7 +408,7 @@ class SimpleCDD: if len(candidates) == 1: return candidates[0] - raise Fail("Cannot find built ISO in %s", outdir) + raise Fail("Cannot find built ISO in {}", outdir) def checkpackages(self): @@ -501,7 +501,7 @@ class SimpleCDD: qemu = "qemu-system-" + arch qemu_bin = shell_which(qemu) if qemu_bin is None: - raise Fail("Cannot find qemu executable %s", qemu) + raise Fail("Cannot find qemu executable {}", qemu) qemu_opts = [] diff --git a/simple_cdd/exceptions.py b/simple_cdd/exceptions.py index 9eab13f..b83da59 100644 --- a/simple_cdd/exceptions.py +++ b/simple_cdd/exceptions.py @@ -4,4 +4,4 @@ class Fail(BaseException): cannot proceed. """ def __str__(self): - return self.args[0] % self.args[1:] + return self.args[0].format(self.args[1:]) diff --git a/simple_cdd/gnupg.py b/simple_cdd/gnupg.py index 78ffe7e..2f3c4f5 100644 --- a/simple_cdd/gnupg.py +++ b/simple_cdd/gnupg.py @@ -45,14 +45,14 @@ class Gnupg: for line in lines: x.write(line.decode('utf-8')) else: - raise Fail("Unable to extract data from %s to %s, returned %d", sigpathname, pathname, proc.returncode) + raise Fail("Unable to extract data from {} to {}, returned {}", sigpathname, pathname, proc.returncode) def verify_gpg_sig(self, *extra_args): args = self.common_gpg_args() args.extend(extra_args) retval = run_command("verify gpg signature", args) if retval != 0: - raise Fail("Signature verification failed on %s", pathname) + raise Fail("Signature verification failed on {}", pathname) def verify_detached_sig(self, pathname, sigpathname): return self.verify_gpg_sig("--verify", sigpathname, pathname) @@ -72,7 +72,7 @@ class Gnupg: if retval != 0: for line in stderr.decode("utf-8").split("\n"): log.error("GPG standard error: %s", line) - raise Fail("Importing %s into %s failed, gpg error code %s", keyring_file, self.env.get("GNUPGHOME"), retval) + raise Fail("Importing {} into {} failed, gpg error code {}", keyring_file, self.env.get("GNUPGHOME"), retval) def list_valid_keys(self, keyring_file): """ diff --git a/simple_cdd/tools/base.py b/simple_cdd/tools/base.py index 11b1262..efab8bb 100644 --- a/simple_cdd/tools/base.py +++ b/simple_cdd/tools/base.py @@ -63,7 +63,7 @@ class ToolShell(Tool): pathname = os.path.join(d, "tools", self.type, self.name) if not os.path.exists(pathname): continue return pathname - raise Fail("Cannot find tool %s/%s in %s", self.type, self.name, self.env.get("simple_cdd_dirs")) + raise Fail("Cannot find tool {}/{} in {}", self.type, self.name, self.env.get("simple_cdd_dirs")) def check_pre(self): """ @@ -126,7 +126,7 @@ class ToolShell(Tool): if retval == 0: log.info("%s/%s ran successfully, full log can be found in %s", self.type, self.name, scriptname) else: - raise Fail("%s/%s exited with code %s, full log can be found in %s", self.type, self.name, retval, scriptname) + raise Fail("{}/{} exited with code {}, full log can be found in {}", self.type, self.name, retval, scriptname) return retval def run(self): diff --git a/simple_cdd/tools/mirror_reprepro.py b/simple_cdd/tools/mirror_reprepro.py index b01b489..900be0f 100644 --- a/simple_cdd/tools/mirror_reprepro.py +++ b/simple_cdd/tools/mirror_reprepro.py @@ -245,14 +245,14 @@ class ToolMirrorReprepro(ToolShell): cmd.extend(["--ignore=wrongdistribution", "includedeb", codename, f]) retval = run_command("reprepro: including local deb file", cmd, env=reprepro_env) if retval != 0: - raise Fail("reprepro failed with exit code: %d", retval) + raise Fail("reprepro failed with exit code: {}", retval) elif f.endswith(".udeb"): cmd = ["reprepro"] cmd.extend(self.env.get("reprepro_opts")) cmd.extend(["--ignore=wrongdistribution", "includeudeb", codename, f]) retval = run_command("reprepro: including local deb file", cmd, env=reprepro_env) if retval != 0: - raise Fail("reprepro failed with exit code: %d", retval) + raise Fail("reprepro failed with exit code: {}", retval) if codename != di_codename: cmd = ["reprepro"] cmd.extend(self.env.get("reprepro_opts")) @@ -267,7 +267,7 @@ class ToolMirrorReprepro(ToolShell): cmd.extend(["--noskipold", "update"]) retval = run_command("reprepro: updating package lists", cmd, env=reprepro_env) if retval != 0: - raise Fail("reprepro failed with exit code: %d", retval) + raise Fail("reprepro failed with exit code: {}", retval) # TODO: we can compute here via dose-debcheck if $all_packages are all # installable, and warn otherwise or fail before we start building a @@ -286,7 +286,7 @@ class ToolMirrorReprepro(ToolShell): cmd.extend(["--noskipold", "remove", self.env.get("CODENAME"), pkg]) retval = run_command("reprepro: remove console-tools-freebsd", cmd, env=reprepro_env) if retval != 0: - raise Fail("reprepro failed with exit code: %d", retval) + raise Fail("reprepro failed with exit code: {}", retval) self.check_post(retval) diff --git a/simple_cdd/utils.py b/simple_cdd/utils.py index e3a7370..9cceba2 100644 --- a/simple_cdd/utils.py +++ b/simple_cdd/utils.py @@ -176,7 +176,7 @@ class Checksums: # Get the checksum record for this file file_sums = self.by_relname.get(relname, None) if file_sums is None: - raise Fail("No checksums found for %s in %s", relname, ", ".join(self.sources)) + raise Fail("No checksums found for {} in {}", relname, ", ".join(self.sources)) # Check file size if we have it expected_size = file_sums.get("size", None) -- 2.11.0
signature.asc
Description: PGP signature

