[virt-tools-list] [virt-bootstrap] [PATCH v2 11/14] sources: Use default values of arguments

Radostin Stoyanov rstoyanov1 at gmail.com
Tue Aug 1 11:28:52 UTC 2017


---
 src/virtBootstrap/sources/docker_source.py | 16 ++++++++--------
 src/virtBootstrap/sources/file_source.py   |  8 ++++----
 src/virtBootstrap/utils.py                 |  1 +
 src/virtBootstrap/virt_bootstrap.py        |  4 ++--
 4 files changed, 15 insertions(+), 14 deletions(-)

diff --git a/src/virtBootstrap/sources/docker_source.py b/src/virtBootstrap/sources/docker_source.py
index 74dc548..d990b89 100644
--- a/src/virtBootstrap/sources/docker_source.py
+++ b/src/virtBootstrap/sources/docker_source.py
@@ -56,14 +56,14 @@ class DockerSource(object):
         """
 
         self.url = self.gen_valid_uri(kwargs['uri'])
-        self.username = kwargs['username']
-        self.password = kwargs['password']
-        self.uid_map = kwargs['uid_map']
-        self.gid_map = kwargs['gid_map']
-        self.root_password = kwargs['root_password']
-        self.output_format = kwargs['fmt']
-        self.insecure = kwargs['not_secure']
-        self.no_cache = kwargs['no_cache']
+        self.username = kwargs.get('username', None)
+        self.password = kwargs.get('password', None)
+        self.uid_map = kwargs.get('uid_map', None)
+        self.gid_map = kwargs.get('gid_map', None)
+        self.root_password = kwargs.get('root_password', None)
+        self.output_format = kwargs.get('fmt', utils.DEFAULT_OUTPUT_FORMAT)
+        self.insecure = kwargs.get('not_secure', False)
+        self.no_cache = kwargs.get('no_cache', False)
         self.progress = kwargs['progress'].update_progress
         self.images_dir = utils.get_image_dir(self.no_cache)
         self.manifest = None
diff --git a/src/virtBootstrap/sources/file_source.py b/src/virtBootstrap/sources/file_source.py
index 4e73da2..2a7617c 100644
--- a/src/virtBootstrap/sources/file_source.py
+++ b/src/virtBootstrap/sources/file_source.py
@@ -43,10 +43,10 @@ class FileSource(object):
         @param progress: Instance of the progress module
         """
         self.path = kwargs['uri'].path
-        self.output_format = kwargs['fmt']
-        self.uid_map = kwargs['uid_map']
-        self.gid_map = kwargs['gid_map']
-        self.root_password = kwargs['root_password']
+        self.output_format = kwargs.get('fmt', utils.DEFAULT_OUTPUT_FORMAT)
+        self.uid_map = kwargs.get('uid_map', None)
+        self.gid_map = kwargs.get('gid_map', None)
+        self.root_password = kwargs.get('root_password', None)
         self.progress = kwargs['progress'].update_progress
 
     def unpack(self, dest):
diff --git a/src/virtBootstrap/utils.py b/src/virtBootstrap/utils.py
index 6cfe63c..578c776 100644
--- a/src/virtBootstrap/utils.py
+++ b/src/virtBootstrap/utils.py
@@ -41,6 +41,7 @@ import passlib.hosts
 # Create logger
 logger = logging.getLogger(__name__)
 
+DEFAULT_OUTPUT_FORMAT = 'dir'
 # Default virtual size of qcow2 image
 DEF_QCOW2_SIZE = 5 * 1024 * 1024 * 1024
 
diff --git a/src/virtBootstrap/virt_bootstrap.py b/src/virtBootstrap/virt_bootstrap.py
index 3cc7edb..cbd9f0c 100755
--- a/src/virtBootstrap/virt_bootstrap.py
+++ b/src/virtBootstrap/virt_bootstrap.py
@@ -93,7 +93,7 @@ def parse_idmap(idmap):
 
 # pylint: disable=too-many-arguments
 def bootstrap(uri, dest,
-              fmt='dir',
+              fmt=utils.DEFAULT_OUTPUT_FORMAT,
               username=None,
               password=None,
               root_password=None,
@@ -199,7 +199,7 @@ def main():
                         help=_("Map both UIDs/GIDs"))
     parser.add_argument("--no-cache", action="store_true",
                         help=_("Do not store downloaded Docker images"))
-    parser.add_argument("-f", "--format", default='dir',
+    parser.add_argument("-f", "--format", default=utils.DEFAULT_OUTPUT_FORMAT,
                         choices=['dir', 'qcow2'],
                         help=_("Format to be used for the root filesystem"))
     parser.add_argument("-d", "--debug", action="store_const", dest="loglevel",
-- 
2.13.3




More information about the virt-tools-list mailing list