summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRadostin Stoyanov <rstoyanov1@gmail.com>2017-07-04 13:46:41 +0100
committerCédric Bosdonnat <cbosdonnat@suse.com>2017-07-04 16:13:51 +0200
commit7daf37d2a5155e742b3c4daea24923e4a7b7d855 (patch)
treeaed5516ff2efcfea8d47c289bbd3c4e6fcc94d46
parent970b4247bd9a39d36ade980967371e4d1bc3f893 (diff)
downloadvirt-bootstrap.git-7daf37d2a5155e742b3c4daea24923e4a7b7d855.tar.gz
virt-bootstrap.git-7daf37d2a5155e742b3c4daea24923e4a7b7d855.tar.xz
virt-bootstrap.git-7daf37d2a5155e742b3c4daea24923e4a7b7d855.zip
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
-rw-r--r--src/virtBootstrap/sources.py19
1 files changed, 12 insertions, 7 deletions
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:///<image>" to "docker://<image>"
+ if not registry and image.startswith('/'):
+ image = image[1:]
+
+ # Convert "docker://<image>/" to "docker://<image>"
+ elif image.endswith('/'):
+ image = image[:-1]
+
+ self.url = "docker://" + registry + image
def unpack(self, dest):
"""