From 7daf37d2a5155e742b3c4daea24923e4a7b7d855 Mon Sep 17 00:00:00 2001 From: Radostin Stoyanov Date: Tue, 4 Jul 2017 13:46:41 +0100 Subject: Improve URI parse of DockerSource Decrease the number of instance attributes of class DockerSource. Since variables "image" and "registry" are only used to create valid Docker URI they could be used as local variables instead of instance attributes to improve encapsulation. Add comments to improve readability. Fix problem with invalid docker URLs --- src/virtBootstrap/sources.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) (limited to 'src/virtBootstrap/sources.py') diff --git a/src/virtBootstrap/sources.py b/src/virtBootstrap/sources.py index ab1091a..6195fd2 100644 --- a/src/virtBootstrap/sources.py +++ b/src/virtBootstrap/sources.py @@ -261,19 +261,24 @@ class DockerSource(object): @param no_cache: Whether to store downloaded images or not """ - self.registry = kwargs['uri'].netloc - self.image = kwargs['uri'].path self.username = kwargs['username'] self.password = kwargs['password'] self.output_format = kwargs['fmt'] self.insecure = kwargs['not_secure'] self.no_cache = kwargs['no_cache'] - if not self.registry and self.image.startswith('/'): - self.image = self.image[1:] - elif self.image and not self.image.startswith('/'): - self.image = '/' + self.image - self.url = "docker://" + self.registry + self.image + registry = kwargs['uri'].netloc + image = kwargs['uri'].path + + # Convert "docker:///" to "docker://" + if not registry and image.startswith('/'): + image = image[1:] + + # Convert "docker:///" to "docker://" + elif image.endswith('/'): + image = image[:-1] + + self.url = "docker://" + registry + image def unpack(self, dest): """ -- cgit