"ks": None,
"repomd": None,
"local_pkgs_path": None,
+ "release": None,
}
class ConfigMgr(object):
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):
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)
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):
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)
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
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
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)
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
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():
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"])
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
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():
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"])
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
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
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"])
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:
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
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"])
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