Add release option
authorGui Chen <gui.chen@intel.com>
Mon, 12 Sep 2011 00:37:37 +0000 (08:37 +0800)
committerJF Ding <jian-feng.ding@intel.com>
Mon, 12 Sep 2011 13:15:01 +0000 (06:15 -0700)
Signed-off-by: Gui Chen <gui.chen@intel.com>
mic/configmgr.py
mic/creator.py
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 0fbdb50..cc2cec7 100644 (file)
@@ -42,6 +42,7 @@ DEFAULT_CREATE = {
     "ks": None,
     "repomd": None,
     "local_pkgs_path": None,
+    "release": None,
 }
 
 class ConfigMgr(object):
index 6db5635..b25547b 100644 (file)
@@ -58,9 +58,10 @@ class Creator(cmdln.Cmdln):
         optparser = cmdln.CmdlnOptionParser(self)
         optparser.add_option('-d', '--debug', action='store_true', dest='debug', help=SUPPRESS_HELP)
         optparser.add_option('-v', '--verbose', action='store_true', dest='verbose', help=SUPPRESS_HELP)
-        optparser.add_option('-o', '--outdir', type='string', action='store', dest='outdir', default=None, help='output directory')
+        optparser.add_option('-o', '--outdir', type='string', action='store', dest='outdir', default=None, help='Output directory')
         optparser.add_option('', '--local-pkgs-path', type='string', dest='local_pkgs_path', default=None, help='Path for local pkgs(rpms) to be installed')
         optparser.add_option('', '--logfile', type='string', dest='logfile', default=None, help='Path of logfile')
+        optparser.add_option('', '--release', type='string', dest='release', default=None, help='Generate release package')
         return optparser
 
     def preoptparse(self, argv):
@@ -112,6 +113,9 @@ class Creator(cmdln.Cmdln):
         if self.options.local_pkgs_path is not None:
             self.configmgr.create['local_pkgs_path'] = self.options.local_pkgs_path
 
+        if self.options.release:
+            self.configmgr.create['release'] = self.options.release
+
         if self.options.logfile:
             msger.set_interactive(False)
             msger.set_logfile(self.options.logfile)
index bb2e58d..07e5e8c 100644 (file)
@@ -42,6 +42,27 @@ import runner
 
 from mic import msger
 
+def save_ksconf_file(ksconf, release="latest", arch = "ia32", oldconf = None):
+    if not os.path.exists(ksconf):
+        return
+
+    if oldconf is not None:
+        oldconf = ksconf
+    fd = open(ksconf, 'r')
+    kscont = fd.read()
+    fd.close()
+
+    if kscont.find("/@ARCH@") != -1:
+        kscont.replace("@ARCH@", arch)
+    if kscont.find("/@BUILD_ID@/") != -1:
+        kscont = kscont.replace("@BUILD_ID@", release)
+        ksconf = "/var/tmp/%s" % ksconf
+        fd = open(ksconf, "w")
+        fd.write(kscont)
+        fd.close()
+
+    return ksconf
+
 def get_image_type(path):
 
     def _get_extension_name(path):
@@ -603,7 +624,8 @@ def create_release(config, destdir, name, outimages, release):
     thatsubdir = None
     for i in range(len(outimages)):
         file = outimages[i]
-        if not os.path.isdir(file) and os.path.dirname(file) != destdir:
+        if not os.path.isdir(file) and \
+          os.path.realpath(os.path.dirname(file)) != os.path.realpath(destdir):
             thatsubdir = os.path.dirname(file)
             newfile = os.path.join(destdir, os.path.basename(file))
             shutil.move(file, newfile)
index 5594cc1..395c2ce 100644 (file)
@@ -20,7 +20,7 @@
 import os
 
 from mic import configmgr, pluginmgr, chroot, msger
-from mic.utils import cmdln, errors
+from mic.utils import cmdln, misc, errors
 from mic.imager import fs
 
 from mic.pluginbase import ImagerPlugin
@@ -44,7 +44,15 @@ class FsPlugin(ImagerPlugin):
 
         cfgmgr = configmgr.getConfigMgr()
         createopts = cfgmgr.create
-        cfgmgr._ksconf = args[0]
+        ksconf = args[0]
+
+        recording_pkgs = None
+        if createopts['release'] is not None:
+            recording_pkgs = "name"
+            ksconf = misc.save_ksconf_file(ksconf, createopts['release'])
+            name = os.path.splitext(os.path.basename(ksconf))[0]
+            createopts['outdir'] = "%s/%s-%s/" % (createopts['outdir'], name, createopts['release'])
+        cfgmgr._ksconf = ksconf
 
         # try to find the pkgmgr
         pkgmgr = None
@@ -58,6 +66,9 @@ class FsPlugin(ImagerPlugin):
 
         creator = fs.FsImageCreator(createopts, pkgmgr)
 
+        if recording_pkgs is not None:
+            creator._recording_pkgs = recording_pkgs
+
         destdir = os.path.abspath(os.path.expanduser(createopts["outdir"]))
         fsdir = os.path.join(destdir, creator.name)
 
@@ -84,6 +95,8 @@ class FsPlugin(ImagerPlugin):
             creator.unmount()
             creator.package(destdir)
             outimage = creator.outimage
+            if createopts['release'] is not None:
+                misc.create_release(ksconf, creatoropts['outdir'], creatoropts['name'], outimage, creatoropts['release'])
             creator.print_outimage_info()
         except errors.CreatorError:
             raise
index c5032af..67f595f 100644 (file)
@@ -45,12 +45,20 @@ class LiveCDPlugin(ImagerPlugin):
 
         cfgmgr = configmgr.getConfigMgr()
         creatoropts = cfgmgr.create
-        cfgmgr._ksconf = args[0]
+        ksconf = args[0]
 
         if creatoropts['arch'] and creatoropts['arch'].startswith('arm'):
             msger.warning('livecd cannot support arm images, Quit')
             return
 
+        recording_pkgs = None
+        if creatoropts['release'] is not None:
+            recording_pkgs = "name"
+            ksconf = misc.save_ksconf_file(ksconf, creatoropts['release'])
+            name = os.path.splitext(os.path.basename(ksconf))[0]
+            creatoropts['outdir'] = "%s/%s-%s/" % (creatoropts['outdir'], name, creatoropts['release'])
+        cfgmgr._ksconf = ksconf
+
         # try to find the pkgmgr
         pkgmgr = None
         for (key, pcls) in pluginmgr.PluginMgr().get_plugins('backend').iteritems():
@@ -62,6 +70,10 @@ class LiveCDPlugin(ImagerPlugin):
             raise errors.CreatorError("Can't find package manager: %s" % creatoropts['pkgmgr'])
 
         creator = livecd.LiveCDImageCreator(creatoropts, pkgmgr)
+
+        if recording_pkgs is not None:
+            creator._recording_pkgs = recording_pkgs
+
         try:
             creator.check_depend_tools()
             creator.mount(None, creatoropts["cachedir"])
@@ -70,6 +82,8 @@ class LiveCDPlugin(ImagerPlugin):
             creator.unmount()
             creator.package(creatoropts["outdir"])
             outimage = creator.outimage
+            if creatoropts['release'] is not None:
+                misc.create_release(ksconf, creatoropts['outdir'], creatoropts['name'], outimage, creatoropts['release'])
             creator.print_outimage_info()
             outimage = creator.outimage
 
index 6c4617b..96e03e9 100644 (file)
@@ -47,12 +47,20 @@ class LiveUSBPlugin(ImagerPlugin):
 
         cfgmgr = configmgr.getConfigMgr()
         creatoropts = cfgmgr.create
-        cfgmgr._ksconf = args[0]
+        ksconf = args[0]
 
         if creatoropts['arch'] and creatoropts['arch'].startswith('arm'):
             msger.warning('liveusb cannot support arm images, Quit')
             return
 
+        recording_pkgs = None
+        if creatoropts['release'] is not None:
+            recording_pkgs = "name"
+            ksconf = misc.save_ksconf_file(ksconf, creatoropts['release'])
+            name = os.path.splitext(os.path.basename(ksconf))[0]
+            creatoropts['outdir'] = "%s/%s-%s/" % (creatoropts['outdir'], name, creatoropts['release'])
+        cfgmgr._ksconf = ksconf
+
         # try to find the pkgmgr
         pkgmgr = None
         for (key, pcls) in pluginmgr.PluginMgr().get_plugins('backend').iteritems():
@@ -64,6 +72,10 @@ class LiveUSBPlugin(ImagerPlugin):
             raise errors.CreatorError("Can't find package manager: %s" % creatoropts['pkgmgr'])
 
         creator = liveusb.LiveUSBImageCreator(creatoropts, pkgmgr)
+
+        if recording_pkgs is not None:
+            creator._recording_pkgs = recording_pkgs
+
         try:
             creator.check_depend_tools()
             creator.mount(None, creatoropts["cachedir"])
@@ -72,6 +84,8 @@ class LiveUSBPlugin(ImagerPlugin):
             creator.unmount()
             creator.package(creatoropts["outdir"])
             outimage = creator.outimage
+            if creatoropts['release'] is not None:
+                misc.create_release(ksconf, creatoropts['outdir'], creatoropts['name'], outimage, creatoropts['release'])
             creator.print_outimage_info()
             outimage = creator.outimage
 
index b19aed4..2690ce8 100644 (file)
@@ -58,7 +58,15 @@ class LoopPlugin(ImagerPlugin):
 
         cfgmgr = configmgr.getConfigMgr()
         creatoropts = cfgmgr.create
-        cfgmgr._ksconf = args[0]
+        ksconf = args[0]
+
+        recording_pkgs = None
+        if creatoropts['release'] is not None:
+            recording_pkgs = "name"
+            ksconf = misc.save_ksconf_file(ksconf, creatoropts['release'])
+            name = os.path.splitext(os.path.basename(ksconf))[0]
+            creatoropts['outdir'] = "%s/%s-%s/" % (creatoropts['outdir'], name, creatoropts['release'])
+        cfgmgr._ksconf = ksconf
 
         # try to find the pkgmgr
         pkgmgr = None
@@ -71,6 +79,10 @@ class LoopPlugin(ImagerPlugin):
             raise errors.CreatorError("Can't find package manager: %s" % creatoropts['pkgmgr'])
 
         creator = loop.LoopImageCreator(creatoropts, pkgmgr, extra_loop)
+
+        if recording_pkgs is not None:
+            creator._recording_pkgs = recording_pkgs
+
         try:
             creator.check_depend_tools()
             creator.mount(None, creatoropts["cachedir"])
@@ -78,6 +90,9 @@ class LoopPlugin(ImagerPlugin):
             creator.configure(creatoropts["repomd"])
             creator.unmount()
             creator.package(creatoropts["outdir"])
+            outimage = creator.outimage
+            if creatoropts['release'] is not None:
+                misc.create_release(ksconf, creatoropts['outdir'], creatoropts['name'], outimage, creatoropts['release'])
             creator.print_outimage_info()
 
         except errors.CreatorError:
index 5c4b1e3..b76b318 100644 (file)
@@ -48,7 +48,15 @@ class RawPlugin(ImagerPlugin):
 
         cfgmgr = configmgr.getConfigMgr()
         creatoropts = cfgmgr.create
-        cfgmgr._ksconf = args[0]
+        ksconf = args[0]
+
+        recording_pkgs = None
+        if creatoropts['release'] is not None:
+            recording_pkgs = "name"
+            ksconf = misc.save_ksconf_file(ksconf, creatoropts['release'])
+            name = os.path.splitext(os.path.basename(ksconf))[0]
+            creatoropts['outdir'] = "%s/%s-%s/" % (creatoropts['outdir'], name, creatoropts['release'])
+        cfgmgr._ksconf = ksconf
 
         # try to find the pkgmgr
         pkgmgr = None
@@ -61,6 +69,10 @@ class RawPlugin(ImagerPlugin):
             raise errors.CreatorError("Can't find package manager: %s" % creatoropts['pkgmgr'])
 
         creator = raw.RawImageCreator(creatoropts, pkgmgr)
+
+        if recording_pkgs is not None:
+            creator._recording_pkgs = recording_pkgs
+
         try:
             creator.check_depend_tools()
             creator.mount(None, creatoropts["cachedir"])
@@ -68,8 +80,10 @@ class RawPlugin(ImagerPlugin):
             creator.configure(creatoropts["repomd"])
             creator.unmount()
             creator.package(creatoropts["outdir"])
-            creator.print_outimage_info()
             outimage = creator.outimage
+            if creatoropts['release'] is not None:
+                misc.create_release(ksconf, creatoropts['outdir'], creatoropts['name'], outimage, creatoropts['release'])
+            creator.print_outimage_info()
 
         except errors.CreatorError:
             raise