diff --git a/dockertidy/Autostop.py b/dockertidy/Autostop.py index d3ea278..36c6b2c 100644 --- a/dockertidy/Autostop.py +++ b/dockertidy/Autostop.py @@ -44,8 +44,11 @@ class AutoStop: prefix and matcher(name) and self._has_been_running_since(container, max_run_time) ) or (not prefix and self._has_been_running_since(container, max_run_time)): self.logger.info( - "Stopping container %s %s: running since %s" % - (container["Id"][:16], name, container["State"]["StartedAt"]) + "Stopping container {id} {name}: running since {started}".format( + id=container["Id"][:16], + name=name, + started=container["State"]["StartedAt"] + ) ) if not dry_run: @@ -55,9 +58,9 @@ class AutoStop: try: client.stop(cid) except requests.exceptions.Timeout as e: - self.logger.warn("Failed to stop container %s: %s" % (cid, e)) - except docker.errors.APIError as ae: - self.logger.warn("Error stopping %s: %s" % (cid, ae)) + self.logger.warn("Failed to stop container {id}: {msg}".format(id=cid, msg=str(e))) + except docker.errors.APIError as e: + self.logger.warn("Error stopping {id}: {msg}".format(id=cid, msg=str(e))) def _build_container_matcher(self, prefixes): diff --git a/dockertidy/Exception.py b/dockertidy/Exception.py index 01f28b5..87c9f76 100644 --- a/dockertidy/Exception.py +++ b/dockertidy/Exception.py @@ -6,7 +6,7 @@ class TidyError(Exception): """Generic exception class for docker-tidy.""" def __init__(self, msg, original_exception=""): - super(TidyError, self).__init__(msg + ("\n%s" % original_exception)) + super(TidyError, self).__init__("{msg}\n{org}".format(msg=msg, org=original_exception)) self.original_exception = original_exception diff --git a/dockertidy/GarbageCollector.py b/dockertidy/GarbageCollector.py index 6c82684..77cfd59 100644 --- a/dockertidy/GarbageCollector.py +++ b/dockertidy/GarbageCollector.py @@ -181,7 +181,7 @@ class GarbageCollector: image_tags = image_summary.get("RepoTags") if self._no_image_tags(image_tags): # The repr of the image Id used by client.containers() - return set(["%s:latest" % image_summary["Id"][:12]]) + return set(["{id}:latest".format(id=image_summary["Id"][:12])]) return set(image_tags) def image_not_in_use(image_summary): @@ -210,7 +210,9 @@ class GarbageCollector: if not image or not self._is_image_old(image, min_date): return - self.logger.info("Removing image %s" % self._format_image(image, image_summary)) + self.logger.info( + "Removing image {name}".format(name=self._format_image(image, image_summary)) + ) if config["dry_run"]: return @@ -230,7 +232,7 @@ class GarbageCollector: if not volume: return - self.logger.info("Removing volume %s" % volume["Name"]) + self.logger.info("Removing volume {name}".format(name=volume["Name"])) if config["dry_run"]: return @@ -249,11 +251,19 @@ class GarbageCollector: try: return func(**kwargs) except requests.exceptions.Timeout as e: - params = ",".join("%s=%s" % item for item in kwargs.items()) - self.logger.warn("Failed to call %s %s %s" % (func.__name__, params, e)) - except docker.errors.APIError as ae: - params = ",".join("%s=%s" % item for item in kwargs.items()) - self.logger.warn("Error calling %s %s %s" % (func.__name__, params, ae)) + params = ",".join("%s=%s" % item for item in kwargs.items()) # noqa + self.logger.warn( + "Failed to call {name} {params} {msg}".format( + name=func.__name__, params=params, msg=str(e) + ) + ) + except docker.errors.APIError as e: + params = ",".join("%s=%s" % item for item in kwargs.items()) # noqa + self.logger.warn( + "Error calling {name} {params} {msg}".format( + name=func.__name__, params=params, msg=str(e) + ) + ) def _format_image(self, image, image_summary): @@ -263,7 +273,7 @@ class GarbageCollector: return "" return ", ".join(tags) - return "%s %s" % (image["Id"][:16], get_tags()) + return "{id} {tags}".format(id=image["Id"][:16], tags=get_tags()) def _build_exclude_set(self): config = self.config.config diff --git a/setup.py b/setup.py index 689045d..47c4bae 100644 --- a/setup.py +++ b/setup.py @@ -81,7 +81,7 @@ setup( "jsonschema==3.2.0", "marshmallow==3.5.1", "nested-lookup==0.2.21", - "pathspec==0.7.0", + "pathspec==0.8.0", "pyrsistent==0.16.0", "python-dateutil==2.8.1", "python-dotenv==0.12.0",