fix help command incorrect issue
authorGui Chen <gui.chen@intel.com>
Mon, 10 Sep 2012 11:14:03 +0000 (19:14 +0800)
committerGui Chen <gui.chen@intel.com>
Wed, 12 Sep 2012 08:55:03 +0000 (16:55 +0800)
Signed-off-by: Gui Chen <gui.chen@intel.com>
mic/creator.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

index 17faa80..428e2b7 100644 (file)
@@ -242,24 +242,16 @@ class Creator(cmdln.Cmdln):
 
         return self.cmd(args)
 
-    def precmd(self, argv): # check arguments before cmd
-        if argv[0] == 'help' or argv[0] == '?':
-            return argv
+    def precmd(self, argv): # check help before cmd
         if len(argv) == 1:
             return ['help', argv[0]]
-        elif len(argv) > 2:
-            raise errors.Usage("Extra arguments given")
 
-        if not os.path.exists(argv[1]):
-            raise errors.CreatorError("Can't find file: %s" % argv[1])
+        if '-h' in argv or '?' in argv or '--help' in argv or 'help' in argv:
+            return argv
 
         if os.geteuid() != 0:
             raise msger.error("Root permission is required, abort")
 
-        if configmgr.bootstrap['enable']:
-            configmgr._ksconf = argv[1]
-            rt_util.bootstrap_mic()
-
         return argv
 
     def do_auto(self, subcmd, opts, *args):
@@ -292,6 +284,12 @@ class Creator(cmdln.Cmdln):
 
             return None
 
+        if len(args) != 1:
+            raise errors.Usage("Extra arguments given")
+
+        if not os.path.exists(args[0]):
+            raise errors.CreatorError("Can't find the file: %s" % args[0])
+
         with open(args[0], 'r') as rf:
             first_line = rf.readline()
 
index 7944b60..e2ee82b 100644 (file)
@@ -18,7 +18,7 @@
 import os
 import sys
 
-from mic import chroot, msger
+from mic import chroot, msger, rt_util
 from mic.utils import cmdln, misc, errors, fs_related
 from mic.imager import fs
 from mic.conf import configmgr
@@ -43,9 +43,16 @@ class FsPlugin(ImagerPlugin):
         ${cmd_option_list}
         """
 
+        if len(args) != 1:
+            raise errors.Usage("Extra arguments given")
+
         creatoropts = configmgr.create
         ksconf = args[0]
 
+        if configmgr.bootstrap['enable']:
+            configmgr._ksconf = ksconf
+            rt_util.bootstrap_mic()
+
         recording_pkgs = []
         if len(creatoropts['record_pkgs']) > 0:
             recording_pkgs = creatoropts['record_pkgs']
index fbd7fb5..275f5c1 100644 (file)
@@ -19,7 +19,7 @@ import os
 import shutil
 import tempfile
 
-from mic import chroot, msger
+from mic import chroot, msger, rt_util
 from mic.utils import misc, fs_related, errors
 from mic.conf import configmgr
 import mic.imager.livecd as livecd
@@ -39,9 +39,16 @@ class LiveCDPlugin(ImagerPlugin):
         ${cmd_option_list}
         """
 
+        if len(args) != 1:
+            raise errors.Usage("Extra arguments given")
+
         creatoropts = configmgr.create
         ksconf = args[0]
 
+        if configmgr.bootstrap['enable']:
+            configmgr._ksconf = ksconf
+            rt_util.bootstrap_mic()
+
         if creatoropts['arch'] and creatoropts['arch'].startswith('arm'):
             msger.warning('livecd cannot support arm images, Quit')
             return
index 2ea93e5..02cfb45 100644 (file)
@@ -19,7 +19,7 @@ import os
 import shutil
 import tempfile
 
-from mic import chroot, msger
+from mic import chroot, msger, rt_util
 from mic.utils import misc, fs_related, errors
 from mic.utils.partitionedfs import PartitionedMount
 from mic.conf import configmgr
@@ -41,9 +41,16 @@ class LiveUSBPlugin(ImagerPlugin):
         ${cmd_option_list}
         """
 
+        if len(args) != 1:
+            raise errors.Usage("Extra arguments given")
+
         creatoropts = configmgr.create
         ksconf = args[0]
 
+        if configmgr.bootstrap['enable']:
+            configmgr._ksconf = ksconf
+            rt_util.bootstrap_mic()
+
         if creatoropts['arch'] and creatoropts['arch'].startswith('arm'):
             msger.warning('liveusb cannot support arm images, Quit')
             return
index f0d170f..c1bccba 100644 (file)
@@ -19,7 +19,7 @@ import os
 import shutil
 import tempfile
 
-from mic import chroot, msger
+from mic import chroot, msger, rt_util
 from mic.utils import misc, fs_related, errors, cmdln
 from mic.conf import configmgr
 from mic.plugin import pluginmgr
@@ -48,9 +48,16 @@ class LoopPlugin(ImagerPlugin):
         ${cmd_option_list}
         """
 
+        if len(args) != 1:
+            raise errors.Usage("Extra arguments given")
+
         creatoropts = configmgr.create
         ksconf = args[0]
 
+        if configmgr.bootstrap['enable']:
+            configmgr._ksconf = ksconf
+            rt_util.bootstrap_mic()
+
         recording_pkgs = []
         if len(creatoropts['record_pkgs']) > 0:
             recording_pkgs = creatoropts['record_pkgs']
index f310fac..3cb15ed 100644 (file)
@@ -20,7 +20,7 @@ import shutil
 import re
 import tempfile
 
-from mic import chroot, msger
+from mic import chroot, msger, rt_util
 from mic.utils import misc, fs_related, errors, runner, cmdln
 from mic.conf import configmgr
 from mic.plugin import pluginmgr
@@ -48,9 +48,16 @@ class RawPlugin(ImagerPlugin):
         ${cmd_option_list}
         """
 
+        if len(args) != 1:
+            raise errors.Usage("Extra arguments given")
+
         creatoropts = configmgr.create
         ksconf = args[0]
 
+        if configmgr.bootstrap['enable']:
+            configmgr._ksconf = ksconf
+            rt_util.bootstrap_mic()
+
         recording_pkgs = []
         if len(creatoropts['record_pkgs']) > 0:
             recording_pkgs = creatoropts['record_pkgs']