use 'latest' and 'ia32' as default when @BUILD_ID@ and @ARCH@ not specified
authorGui Chen <gui.chen@intel.com>
Tue, 19 Jun 2012 04:10:28 +0000 (12:10 +0800)
committerGui Chen <gui.chen@intel.com>
Tue, 19 Jun 2012 04:13:01 +0000 (12:13 +0800)
Signed-off-by: Gui Chen <gui.chen@intel.com>
mic/utils/misc.py
plugins/imager/fs_plugin.py
plugins/imager/livecd_plugin.py
plugins/imager/liveusb_plugin.py
plugins/imager/loop_plugin.py
plugins/imager/raw_plugin.py

index 1b5f086..1360be1 100644 (file)
@@ -170,14 +170,26 @@ def get_md5sum(fpath):
             md5sum.update(data)
     return md5sum.hexdigest()
 
-def save_ksconf_file(ksconf, release="latest", arch="ia32"):
+def normalize_ksfile(ksconf, release, arch):
+    def _clrtempks():
+        try:
+            os.unlink(ksconf)
+        except:
+            pass
+
     if not os.path.exists(ksconf):
         return
 
+    if not release:
+        release = "latest"
+    if not arch or re.match(r'i.86', arch):
+        arch = "ia32"
+
     with open(ksconf) as f:
         ksc = f.read()
 
     if "@ARCH@" in ksc or "@BUILD_ID@" in ksc:
+        msger.info("Substitute macro variable @BUILD_ID@/@ARCH in ks: %s" % ksconf)
         ksc = ksc.replace("@ARCH@", arch)
         ksc = ksc.replace("@BUILD_ID@", release)
         fd, ksconf = tempfile.mkstemp(prefix=os.path.basename(ksconf), dir="/tmp/")
@@ -186,6 +198,9 @@ def save_ksconf_file(ksconf, release="latest", arch="ia32"):
 
         msger.debug('new ks path %s' % ksconf)
 
+        import atexit
+        atexit.register(_clrtempks)
+
     return ksconf
 
 def _check_meego_chroot(rootdir):
index aceb653..1425516 100644 (file)
@@ -62,7 +62,10 @@ class FsPlugin(ImagerPlugin):
         if creatoropts['release'] is not None:
             if 'name' not in recording_pkgs:
                 recording_pkgs.append('name')
-            ksconf = misc.save_ksconf_file(ksconf, creatoropts['release'])
+
+        ksconf = misc.normalize_ksfile(ksconf,
+                                       creatoropts['release'],
+                                       creatoropts['arch'])
 
         configmgr._ksconf = ksconf
     
index 5b9349f..762e133 100644 (file)
@@ -62,7 +62,10 @@ class LiveCDPlugin(ImagerPlugin):
         if creatoropts['release'] is not None:
             if 'name' not in recording_pkgs:
                 recording_pkgs.append('name')
-            ksconf = misc.save_ksconf_file(ksconf, creatoropts['release'])
+
+        ksconf = misc.normalize_ksfile(ksconf,
+                                       creatoropts['release'],
+                                       creatoropts['arch'])
 
         configmgr._ksconf = ksconf
     
index c5735aa..000870f 100644 (file)
@@ -64,7 +64,10 @@ class LiveUSBPlugin(ImagerPlugin):
         if creatoropts['release'] is not None:
             if 'name' not in recording_pkgs:
                 recording_pkgs.append('name')
-            ksconf = misc.save_ksconf_file(ksconf, creatoropts['release'])
+
+        ksconf = misc.normalize_ksfile(ksconf,
+                                       creatoropts['release'],
+                                       creatoropts['arch'])
 
         configmgr._ksconf = ksconf
     
index 29276c7..5814cb5 100644 (file)
@@ -67,8 +67,10 @@ class LoopPlugin(ImagerPlugin):
         if creatoropts['release'] is not None:
             if 'name' not in recording_pkgs:
                 recording_pkgs.append('name')
-            ksconf = misc.save_ksconf_file(ksconf, creatoropts['release'])
 
+        ksconf = misc.normalize_ksfile(ksconf,
+                                       creatoropts['release'],
+                                       creatoropts['arch'])
         configmgr._ksconf = ksconf
 
         # Called After setting the configmgr._ksconf
index f156606..6f91812 100644 (file)
@@ -67,7 +67,10 @@ class RawPlugin(ImagerPlugin):
         if creatoropts['release'] is not None:
             if 'name' not in recording_pkgs:
                 recording_pkgs.append('name')
-            ksconf = misc.save_ksconf_file(ksconf, creatoropts['release'])
+
+        ksconf = misc.normalize_ksfile(ksconf,
+                                       creatoropts['release'],
+                                       creatoropts['arch'])
 
         configmgr._ksconf = ksconf