call copy_attachment() after configure() and move attachment files
[tools/mic.git] / plugins / imager / raw_plugin.py
old mode 100644 (file)
new mode 100755 (executable)
index 2543b90..ef537a4
 # Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 
 import os
+import subprocess
 import shutil
 import re
 import tempfile
 
 from mic import chroot, msger, rt_util
-from mic.utils import misc, fs_related, errors, runner, cmdln
+from mic.utils import misc, fs_related, errors, runner
 from mic.conf import configmgr
 from mic.plugin import pluginmgr
 from mic.utils.partitionedfs import PartitionedMount
@@ -33,19 +34,7 @@ class RawPlugin(ImagerPlugin):
     name = 'raw'
 
     @classmethod
-    @cmdln.option("--compress-disk-image", dest="compress_image", type='choice',
-                  choices=("gz", "bz2"), default=None,
-                  help="Same with --compress-image")
-    @cmdln.option("--compress-image", dest="compress_image", type='choice',
-                  choices=("gz", "bz2"), default = None,
-                  help="Compress all raw images before package")
-    @cmdln.option("--generate-bmap", action="store_true", default = None,
-                  help="also generate the block map file")
-    @cmdln.option("--fstab-entry", dest="fstab_entry", type='choice',
-                  choices=("name", "uuid"), default="uuid",
-                  help="Set fstab entry, 'name' means using device names, "
-                       "'uuid' means using filesystem uuid")
-    def do_create(self, subcmd, opts, *args):
+    def do_create(self, args):
         """${cmd_name}: create raw image
 
         Usage:
@@ -54,25 +43,12 @@ class RawPlugin(ImagerPlugin):
         ${cmd_option_list}
         """
 
-        if len(args) != 1:
-            raise errors.Usage("Extra arguments given")
-
         creatoropts = configmgr.create
-        ksconf = args[0]
+        ksconf = args.ksfile
 
         if creatoropts['runtime'] == "bootstrap":
             configmgr._ksconf = ksconf
             rt_util.bootstrap_mic()
-        elif not rt_util.inbootstrap():
-            try:
-                fs_related.find_binary_path('mic-native')
-            except errors.CreatorError:
-                if not msger.ask("Subpackage \"mic-native\" has not been "
-                                 "installed in your host system, still "
-                                 "continue with \"native\" running mode?",
-                                 False):
-                    raise errors.Abort("Abort because subpackage 'mic-native' "
-                                       "has not been installed")
 
         recording_pkgs = []
         if len(creatoropts['record_pkgs']) > 0:
@@ -106,8 +82,8 @@ class RawPlugin(ImagerPlugin):
                                       (creatoropts['pkgmgr'],
                                        ','.join(backends.keys())))
 
-        creator = raw.RawImageCreator(creatoropts, pkgmgr, opts.compress_image,
-                                      opts.generate_bmap, opts.fstab_entry)
+        creator = raw.RawImageCreator(creatoropts, pkgmgr, args.compress_image,
+                                      args.generate_bmap, args.fstab_entry)
 
         if len(recording_pkgs) > 0:
             creator._recording_pkgs = recording_pkgs
@@ -125,12 +101,13 @@ class RawPlugin(ImagerPlugin):
             creator.install()
             creator.configure(creatoropts["repomd"])
             creator.copy_kernel()
+            creator.copy_attachment()
             creator.unmount()
             creator.generate_bmap()
-            creator.package(creatoropts["outdir"])
+            creator.package(creatoropts["destdir"])
             creator.create_manifest()
             if creatoropts['release'] is not None:
-                creator.release_output(ksconf, creatoropts['outdir'], creatoropts['release'])
+                creator.release_output(ksconf, creatoropts['destdir'], creatoropts['release'])
             creator.print_outimage_info()
 
         except errors.CreatorError:
@@ -138,6 +115,15 @@ class RawPlugin(ImagerPlugin):
         finally:
             creator.cleanup()
 
+        #Run script of --run_script after image created
+        if creatoropts['run_script']:
+            cmd = creatoropts['run_script']
+            try:
+                runner.show(cmd)
+            except OSError,err:
+                msger.warning(str(err))
+
+
         msger.info("Finished.")
         return 0