From b9f9ee2f9fd7d6714dad17e84fd5fc401fb73c7e Mon Sep 17 00:00:00 2001 From: Marko Saukko Date: Wed, 18 Jan 2012 15:47:41 +0200 Subject: [PATCH] Introduce --copy-kernel cmdline option to copy kernel files to output directory. Signed-off-by: Marko Saukko --- mic/conf.py | 1 + mic/creator.py | 9 ++++++++- mic/imager/baseimager.py | 20 ++++++++++++++++---- plugins/imager/fs_plugin.py | 1 + plugins/imager/livecd_plugin.py | 1 + plugins/imager/liveusb_plugin.py | 1 + plugins/imager/loop_plugin.py | 1 + plugins/imager/raw_plugin.py | 1 + 8 files changed, 30 insertions(+), 5 deletions(-) diff --git a/mic/conf.py b/mic/conf.py index 112164c..287f69a 100644 --- a/mic/conf.py +++ b/mic/conf.py @@ -49,6 +49,7 @@ class ConfigMgr(object): "name_prefix": None, "proxy": None, "no_proxy": None, + "copy_kernel": False, "runtime": None, }, diff --git a/mic/creator.py b/mic/creator.py index 5b28deb..da72946 100644 --- a/mic/creator.py +++ b/mic/creator.py @@ -95,6 +95,10 @@ class Creator(cmdln.Cmdln): help='Sets the disk image compression. NOTE: The ' 'available values might depend on the used ' 'filesystem type.') + optparser.add_option('', '--copy-kernel', action='store_true', + dest='copy_kernel', + help='Copy kernel files from image /boot directory' + 'to the image output directory.') return optparser def preoptparse(self, argv): @@ -193,7 +197,10 @@ class Creator(cmdln.Cmdln): if self.options.compress_disk_image is not None: configmgr.create['compress_disk_image'] = \ self.options.compress_disk_image - + + if self.options.copy_kernel: + configmgr.create['copy_kernel'] = self.options.copy_kernel + def main(self, argv=None): if argv is None: argv = sys.argv diff --git a/mic/imager/baseimager.py b/mic/imager/baseimager.py index d5f7588..4a39922 100644 --- a/mic/imager/baseimager.py +++ b/mic/imager/baseimager.py @@ -1,3 +1,4 @@ + #!/usr/bin/python -tt # # Copyright (c) 2007 Red Hat Inc. @@ -73,6 +74,8 @@ class BaseImageCreator(object): self.destdir = "." self.target_arch = "noarch" self._local_pkgs_path = None + # If the kernel is save to the destdir when copy_kernel cmd is called. + self._copy_kernel = False # Eeach image type can change these values as they might be image type # specific @@ -83,11 +86,13 @@ class BaseImageCreator(object): self._img_compression_method = None if createopts: + # Mapping table for variables that have different names. optmap = {"pkgmgr" : "pkgmgr_name", "outdir" : "destdir", "arch" : "target_arch", "local_pkgs_path" : "_local_pkgs_path", "compress_disk_image" : "_img_compression_method", + "copy_kernel" : "_copy_kernel", } # update setting from createopts @@ -1172,11 +1177,18 @@ class BaseImageCreator(object): if not os.path.exists("%s" % fp): outimages.remove(fp) - def save_kernel(self, destdir): - if not os.path.exists(destdir): - os.makedirs(destdir) + def copy_kernel(self): + """ Copy kernel files to the outimage directory. + + NOTE: This needs to be called before unmounting the instroot. + + """ + if not self._copy_kernel: + return + if not os.path.exists(self.destdir): + os.makedirs(self.destdir) for kernel in glob.glob("%s/boot/vmlinuz-*" % self._instroot): - kernelfilename = "%s/%s-%s" % (destdir, self.name, os.path.basename(kernel)) + kernelfilename = "%s/%s-%s" % (self.destdir, self.name, os.path.basename(kernel)) shutil.copy(kernel, kernelfilename) self.outimage.append(kernelfilename) diff --git a/plugins/imager/fs_plugin.py b/plugins/imager/fs_plugin.py index a46b7ae..aa88e16 100644 --- a/plugins/imager/fs_plugin.py +++ b/plugins/imager/fs_plugin.py @@ -112,6 +112,7 @@ class FsPlugin(ImagerPlugin): msger.warning("Source packages can't be downloaded") creator.configure(creatoropts["repomd"]) + creator.copy_kernel() creator.unmount() creator.package(creatoropts["outdir"]) if creatoropts['release'] is not None: diff --git a/plugins/imager/livecd_plugin.py b/plugins/imager/livecd_plugin.py index 6572eef..7828e5c 100644 --- a/plugins/imager/livecd_plugin.py +++ b/plugins/imager/livecd_plugin.py @@ -102,6 +102,7 @@ class LiveCDPlugin(ImagerPlugin): creator.mount(None, creatoropts["cachedir"]) creator.install() creator.configure(creatoropts["repomd"]) + creator.copy_kernel() creator.unmount() creator.package(creatoropts["outdir"]) if creatoropts['release'] is not None: diff --git a/plugins/imager/liveusb_plugin.py b/plugins/imager/liveusb_plugin.py index cbcf81e..45fd308 100644 --- a/plugins/imager/liveusb_plugin.py +++ b/plugins/imager/liveusb_plugin.py @@ -104,6 +104,7 @@ class LiveUSBPlugin(ImagerPlugin): creator.mount(None, creatoropts["cachedir"]) creator.install() creator.configure(creatoropts["repomd"]) + creator.copy_kernel() creator.unmount() creator.package(creatoropts["outdir"]) if creatoropts['release'] is not None: diff --git a/plugins/imager/loop_plugin.py b/plugins/imager/loop_plugin.py index c84efe6..51ea79b 100644 --- a/plugins/imager/loop_plugin.py +++ b/plugins/imager/loop_plugin.py @@ -112,6 +112,7 @@ class LoopPlugin(ImagerPlugin): creator.mount(None, creatoropts["cachedir"]) creator.install() creator.configure(creatoropts["repomd"]) + creator.copy_kernel() creator.unmount() creator.package(creatoropts["outdir"]) diff --git a/plugins/imager/raw_plugin.py b/plugins/imager/raw_plugin.py index 25134c6..f0d02bb 100644 --- a/plugins/imager/raw_plugin.py +++ b/plugins/imager/raw_plugin.py @@ -102,6 +102,7 @@ class RawPlugin(ImagerPlugin): creator.mount(None, creatoropts["cachedir"]) creator.install() creator.configure(creatoropts["repomd"]) + creator.copy_kernel() creator.unmount() creator.package(creatoropts["outdir"]) if creatoropts['release'] is not None: -- 2.7.4