From bf012b0ec3e3f3a20ed6dd823857afdd9b28c968 Mon Sep 17 00:00:00 2001 From: JF Ding Date: Thu, 1 Sep 2011 15:14:23 +0900 Subject: [PATCH] refine the fs plugin code and other cleanups --- mic/imager/baseimager.py | 14 ------------ mic/imager/fs.py | 12 +++------- mic/imager/livecd.py | 2 +- plugins/imager/fs_plugin.py | 47 +++++++++++++++++++++++++--------------- plugins/imager/livecd_plugin.py | 2 +- plugins/imager/liveusb_plugin.py | 2 +- plugins/imager/loop_plugin.py | 2 +- plugins/imager/raw_plugin.py | 2 +- tools/mic | 6 ++--- 9 files changed, 41 insertions(+), 48 deletions(-) diff --git a/mic/imager/baseimager.py b/mic/imager/baseimager.py index 720d036..225e06b 100644 --- a/mic/imager/baseimager.py +++ b/mic/imager/baseimager.py @@ -1021,20 +1021,6 @@ class BaseImageCreator(object): self.outimage.append(os.path.join(destdir, f)) self.do_genchecksum(os.path.join(destdir, f)) - def create(self): - """Install, configure and package an image. - - This method is a utility method which creates and image by calling some - of the other methods in the following order - mount(), install(), - configure(), unmount and package(). - - """ - self.mount(None, self.cachedir) - self.install() - self.configure(self.repometadata) - self.unmount() - self.package(self.destdir) - def print_outimage_info(self): msger.info("Your new image can be found here:") self.outimage.sort() diff --git a/mic/imager/fs.py b/mic/imager/fs.py index fe0a52a..52599f5 100644 --- a/mic/imager/fs.py +++ b/mic/imager/fs.py @@ -21,7 +21,6 @@ import os, sys import subprocess from baseimager import BaseImageCreator -from mic.utils.fs_related import makedirs from mic import msger class FsImageCreator(BaseImageCreator): @@ -30,21 +29,16 @@ class FsImageCreator(BaseImageCreator): self._fstype = None self._fsopts = None - def _stage_final_image(self): - """ nothing to do""" - pass - def package(self, destdir = "."): - self._stage_final_image() + destdir = os.path.abspath(os.path.expanduser(destdir)) if not os.path.exists(destdir): - makedirs(destdir) + os.makedirs(destdir) - destdir = os.path.abspath(os.path.expanduser(destdir)) if self._recording_pkgs: self._save_recording_pkgs(destdir) - msger.info("Copying %s to %s, please be patient to wait" % (self._instroot, destdir + "/" + self.name)) + msger.info("Copying %s to %s ..." % (self._instroot, destdir + "/" + self.name)) args = ['cp', "-af", self._instroot, destdir + "/" + self.name ] subprocess.call(args) diff --git a/mic/imager/livecd.py b/mic/imager/livecd.py index d04b5a8..ea6b2aa 100644 --- a/mic/imager/livecd.py +++ b/mic/imager/livecd.py @@ -248,7 +248,7 @@ class LiveImageCreatorBase(LoopImageCreator): elif os.path.exists("/usr/lib/anaconda-runtime/implantisomd5"): implantisomd5 = "/usr/lib/anaconda-runtime/implantisomd5" else: - msger.warn("isomd5sum not installed; not setting up mediacheck") + msger.warning("isomd5sum not installed; not setting up mediacheck") implantisomd5 = "" return diff --git a/plugins/imager/fs_plugin.py b/plugins/imager/fs_plugin.py index 236d31f..e5d9bbd 100644 --- a/plugins/imager/fs_plugin.py +++ b/plugins/imager/fs_plugin.py @@ -1,16 +1,27 @@ -#!/usr/bin/python -import sys -import subprocess +#!/usr/bin/python -tt +# +# Copyright 2011 Intel, Inc. +# +# This copyrighted material is made available to anyone wishing to use, modify, +# copy, or redistribute it subject to the terms and conditions of the GNU +# General Public License v.2. This program is distributed in the hope that it +# will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the +# implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. +# See the GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License along with +# this program; if not, write to the Free Software Foundation, Inc., 51 +# Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Any Red Hat +# trademarks that are incorporated in the source code or documentation are not +# subject to the GNU General Public License and may only be used or replicated +# with the express permission of Red Hat, Inc. +# -import mic.utils.cmdln as cmdln -import mic.utils.errors as errors -import mic.configmgr as configmgr -import mic.pluginmgr as pluginmgr -import mic.imager.fs as fs -import mic.chroot as chroot +from mic import configmgr, pluginmgr, chroot, msger +from mic.utils import cmdln, errors +from mic.imager import fs from mic.pluginbase import ImagerPlugin - class FsPlugin(ImagerPlugin): name = 'fs' @@ -22,8 +33,10 @@ class FsPlugin(ImagerPlugin): ${cmd_usage} ${cmd_option_list} """ - if len(args) == 0: - return + + if not args: + raise errors.Usage("More arguments needed") + if len(args) == 1: ksconf = args[0] else: @@ -52,10 +65,10 @@ class FsPlugin(ImagerPlugin): #Download the source packages ###private options if opts.include_src: installed_pkgs = creator.get_installed_packages() - print '--------------------------------------------------' - print 'Generating the image with source rpms included, The number of source packages is %d.' %(len(installed_pkgs)) + msger.info('--------------------------------------------------') + msger.info('Generating the image with source rpms included, The number of source packages is %d.' %(len(installed_pkgs))) if not misc.SrcpkgsDownload(installed_pkgs, createopts["repomd"], creator._instroot, createopts["cachedir"]): - print "Source packages can't be downloaded" + msger.warning("Source packages can't be downloaded") creator.configure(createopts["repomd"]) creator.unmount() @@ -66,7 +79,7 @@ class FsPlugin(ImagerPlugin): raise errors.CreatorError("failed to create image : %s" % e) finally: creator.cleanup() - print "Finished." + msger.info("Finished.") return 0 @@ -75,7 +88,7 @@ class FsPlugin(ImagerPlugin): try: chroot.chroot(target, None, "/bin/env HOME=/root /bin/bash") except: - print >> sys.stderr, "Failed to chroot to %s." % target + msger.warning("Failed to chroot to %s." % target) finally: chroot.cleanup_after_chroot("dir", None, None, None) return 1 diff --git a/plugins/imager/livecd_plugin.py b/plugins/imager/livecd_plugin.py index 139476d..b9e69a7 100644 --- a/plugins/imager/livecd_plugin.py +++ b/plugins/imager/livecd_plugin.py @@ -40,7 +40,7 @@ class LiveCDPlugin(ImagerPlugin): pkgmgr = None plgmgr = pluginmgr.PluginMgr() for (key, pcls) in plgmgr.get_plugins('backend').iteritems(): - if key == createopts['pkgmgr']: + if key == creatoropts['pkgmgr']: pkgmgr = pcls break diff --git a/plugins/imager/liveusb_plugin.py b/plugins/imager/liveusb_plugin.py index 2720434..b61a96d 100644 --- a/plugins/imager/liveusb_plugin.py +++ b/plugins/imager/liveusb_plugin.py @@ -43,7 +43,7 @@ class LiveUSBPlugin(ImagerPlugin): pkgmgr = None plgmgr = pluginmgr.PluginMgr() for (key, pcls) in plgmgr.get_plugins('backend').iteritems(): - if key == createopts['pkgmgr']: + if key == creatoropts['pkgmgr']: pkgmgr = pcls break diff --git a/plugins/imager/loop_plugin.py b/plugins/imager/loop_plugin.py index b571922..fcdaf53 100644 --- a/plugins/imager/loop_plugin.py +++ b/plugins/imager/loop_plugin.py @@ -41,7 +41,7 @@ class LoopPlugin(ImagerPlugin): pkgmgr = None plgmgr = pluginmgr.PluginMgr() for (key, pcls) in plgmgr.get_plugins('backend').iteritems(): - if key == createopts['pkgmgr']: + if key == creatoropts['pkgmgr']: pkgmgr = pcls break diff --git a/plugins/imager/raw_plugin.py b/plugins/imager/raw_plugin.py index 324d12a..ea2d40b 100644 --- a/plugins/imager/raw_plugin.py +++ b/plugins/imager/raw_plugin.py @@ -42,7 +42,7 @@ class RawPlugin(ImagerPlugin): pkgmgr = None plgmgr = pluginmgr.PluginMgr() for (key, pcls) in plgmgr.get_plugins('backend').iteritems(): - if key == createopts['pkgmgr']: + if key == creatoropts['pkgmgr']: pkgmgr = pcls break diff --git a/tools/mic b/tools/mic index caa9366..d0137c0 100755 --- a/tools/mic +++ b/tools/mic @@ -173,10 +173,10 @@ if __name__ == "__main__": sys.exit(mic.main()) except errors.Usage, msg: - msger.error("Usage error: %s\n" % msg) + msger.error(" %s\n" % msg) except errors.ConfigError, msg: - msger.error("Config error: %s\n" % msg) + msger.error(" %s\n" % msg) except errors.CreatorError, msg: - msger.error("Creator error: %s\n" % msg) + msger.error(" %s\n" % msg) -- 2.7.4