refine the fs plugin code and other cleanups
authorJF Ding <Jian-feng.Ding@intel.com>
Thu, 1 Sep 2011 06:14:23 +0000 (15:14 +0900)
committerJF Ding <Jian-feng.Ding@intel.com>
Thu, 1 Sep 2011 06:14:23 +0000 (15:14 +0900)
mic/imager/baseimager.py
mic/imager/fs.py
mic/imager/livecd.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
tools/mic

index 720d036..225e06b 100644 (file)
@@ -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()
index fe0a52a..52599f5 100644 (file)
@@ -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)
index d04b5a8..ea6b2aa 100644 (file)
@@ -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
 
index 236d31f..e5d9bbd 100644 (file)
@@ -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
index 139476d..b9e69a7 100644 (file)
@@ -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
 
index 2720434..b61a96d 100644 (file)
@@ -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
 
index b571922..fcdaf53 100644 (file)
@@ -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
 
index 324d12a..ea2d40b 100644 (file)
@@ -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
 
index caa9366..d0137c0 100755 (executable)
--- 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("<usage> %s\n" % msg)
 
     except errors.ConfigError, msg:
-        msger.error("Config error: %s\n" % msg)
+        msger.error("<config> %s\n" % msg)
 
     except errors.CreatorError, msg:
-        msger.error("Creator error: %s\n" % msg)
+        msger.error("<creator> %s\n" % msg)