fix convert failed caused by NoneType 'createopts'
authorGui Chen <gui.chen@intel.com>
Tue, 27 Dec 2011 08:41:17 +0000 (16:41 +0800)
committerGui Chen <gui.chen@intel.com>
Tue, 27 Dec 2011 08:41:17 +0000 (16:41 +0800)
put distro_name to common section

Signed-off-by: Gui Chen <gui.chen@intel.com>
mic/conf.py
mic/imager/baseimager.py
plugins/imager/livecd_plugin.py
plugins/imager/liveusb_plugin.py

index 3c3b018..4d1aa5f 100644 (file)
@@ -25,7 +25,9 @@ from .utils import misc, runner, proxy, errors
 DEFAULT_GSITECONF = '/etc/mic/mic.conf'
 
 class ConfigMgr(object):
-    DEFAULTS = {'common': {},
+    DEFAULTS = {'common': {
+                    "distro_name": "Default Distribution",
+                },
                 'create': {
                     "tmpdir": '/var/tmp/mic',
                     "cachedir": '/var/tmp/mic/cache',
@@ -41,7 +43,6 @@ class ConfigMgr(object):
                     "logfile": None,
                     "record_pkgs": [],
                     "compress_disk_image": None,
-                    "distro_name": "Default Distribution",
                     "name_prefix": None,
                     "proxy": None,
                     "no_proxy": None,
@@ -111,6 +112,11 @@ class ConfigMgr(object):
         parser = ConfigParser.SafeConfigParser()
         parser.read(siteconf)
 
+        # append common section items to other sections
+        for section in self.DEFAULTS.keys():
+            if section != "common":
+                getattr(self, section).update(self.common)
+
         for section in parser.sections():
             if section in self.DEFAULTS.keys():
                 getattr(self, section).update(dict(parser.items(section)))
index edeefec..099a7cf 100644 (file)
@@ -63,6 +63,14 @@ class BaseImageCreator(object):
         self.__builddir = None
         self.__bindmounts = []
 
+        self.ks = None
+        self.name = "target"
+        self.tmpdir = "/var/tmp/mic"
+        self.cachedir = "/var/tmp/mic/cache"
+        self.destdir = "."
+        self.target_arch = "noarch"
+        self._local_pkgs_path = None
+
         # Eeach image type can change these values as they might be image type
         # specific
         if not hasattr(self, "_valid_compression_methods"):
@@ -72,46 +80,37 @@ class BaseImageCreator(object):
         self._img_compression_method = None
 
         if createopts:
-            # A pykickstart.KickstartParser instance."""
-            self.ks = createopts['ks']
+            optmap = {"pkgmgr" : "pkgmgr_name",
+                      "outdir" : "destdir",
+                      "arch" : "target_arch",
+                      "local_pkgs_path" : "_local_pkgs_path",
+                      "compress_disk_image" : "_img_compression_method",
+                     }
+    
+            # update setting from createopts
+            for key in createopts.keys():
+                if key in optmap:
+                    option = optmap[key]
+                else:
+                    option = key
+                setattr(self, option, createopts[key])
 
-            self.destdir = os.path.abspath(os.path.expanduser(createopts["outdir"]))
+            self.destdir = os.path.abspath(os.path.expanduser(self.destdir))
 
-            # A name for the image."""
-            self.name = createopts['name']
-            if createopts['release']:
+            if 'release' in createopts and createopts['release']:
                 self.name += '-' + createopts['release']
 
-                # check whether destine dir exist
                 if os.path.exists(self.destdir):
-                    if msger.ask('Image dir: %s already exists, '
-                                 'cleanup and continue?' % self.destdir):
+                    if msger.ask("Image dir: %s already exists, cleanup and" \
+                                 "continue?" % self.destdir):
                         shutil.rmtree(self.destdir, ignore_errors = True)
                     else:
-                        raise Abort('Canceled')
-
-                # pending FEA: save log by default for --release
+                        raise Abort("Canceled")
 
-            # The directory in which all temporary files will be created."""
-            self.tmpdir = createopts['tmpdir']
-            self.cachedir = createopts['cachedir']
-            self.target_arch = createopts['arch']
-            self._local_pkgs_path = createopts['local_pkgs_path']
-            self._img_compression_method = createopts['compress_disk_image']
-
-        else:
-            self.ks = None
-            self.name = "target"
-            self.tmpdir = "/var/tmp/mic"
-            self.cachedir = "/var/tmp/mic/cache"
-            self.destdir = "."
-            self.target_arch = "noarch"
-            self._local_pkgs_path = None
+                    # pending FEA: save log by default for --release
 
         self._dep_checks = ["ls", "bash", "cp", "echo", "modprobe", "passwd"]
 
-        self.distro_name = createopts['distro_name']
-
         # Output image file names
         self.outimage = []
 
index 8f8db22..ab152e1 100644 (file)
@@ -171,7 +171,8 @@ class LiveCDPlugin(ImagerPlugin):
             except OSError, (err, msg):
                raise errors.CreatorError("Failed to run post cleanups: %s" % msg)
 
-        convertor = livecd.LiveCDImageCreator()
+        convertoropts = configmgr.convert
+        convertor = livecd.LiveCDImageCreator(convertoropts)
         convertor.name = os.path.splitext(os.path.basename(base_on))[0]
         imgtype = misc.get_image_type(base_on)
         if imgtype == "btrfsimg":
index c9e76bb..c41c79b 100644 (file)
@@ -174,7 +174,8 @@ class LiveUSBPlugin(ImagerPlugin):
             except OSError, (err, msg):
                raise errors.CreatorError("Failed to run post cleanups: %s" % msg)
 
-        convertor = liveusb.LiveUSBImageCreator()
+        convertoropts = configmgr.convert
+        convertor = liveusb.LiveUSBImageCreator(convertoropts)
         convertor.name = os.path.splitext(os.path.basename(base_on))[0]
         imgtype = misc.get_image_type(base_on)
         if imgtype == "btrfsimg":