summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authoryanqingx.li <yanqingx.li@intel.com>2012-09-26 14:47:55 +0800
committerGui Chen <gui.chen@intel.com>2012-09-26 15:08:22 +0800
commitfee503b47d468cbc7c539910796269b65cbff750 (patch)
treeae593364b7fe4f4e064e3d526009ace86f60accf /tools
parentab277036676eb8cc77d21ce1b9366da5ee8c67d2 (diff)
downloadmic-fee503b47d468cbc7c539910796269b65cbff750.tar.gz
mic-fee503b47d468cbc7c539910796269b65cbff750.tar.bz2
mic-fee503b47d468cbc7c539910796269b65cbff750.zip
support running specified command for mic chroot
usage: mic chroot CHROOT [COMMAND [ARGS]] this feature enables running command with non-interactive Change-Id: Ic7e74a00c83e3cef5684c2ee94a755389ba4276d
Diffstat (limited to 'tools')
-rwxr-xr-xtools/mic19
1 files changed, 12 insertions, 7 deletions
diff --git a/tools/mic b/tools/mic
index d0c6fed..e45b1ec 100755
--- a/tools/mic
+++ b/tools/mic
@@ -69,6 +69,13 @@ class MicCmd(cmdln.Cmdln):
self.print_version()
+ def optparser_setup(func):
+ """Setup optparser for a function"""
+ if not hasattr(func, "optparser"):
+ func.optparser = cmdln.SubCmdOptionParser()
+ func.optparser.disable_interspersed_args()
+ return func
+
def help_create(self):
cr = creator.Creator()
cr.optparser = cr.get_optparser()
@@ -166,11 +173,12 @@ class MicCmd(cmdln.Cmdln):
@cmdln.option('-s', '--saveto',
action='store', dest='saveto', default=None,
help="Save the unpacked image to specified dir")
+ @optparser_setup
def do_chroot(self, subcmd, opts, *args):
"""${cmd_name}: chroot into an image
Usage:
- mic chroot <imagefile>
+ mic chroot [options] <imagefile> [command [arg]...]
${cmd_option_list}
"""
@@ -181,11 +189,8 @@ class MicCmd(cmdln.Cmdln):
if hasattr(handler, "optparser"):
handler.optparser.print_help()
return 1
-
- if len(args) == 1:
- targetimage = args[0]
- else:
- raise errors.Usage("Extra argument given")
+
+ targetimage = args[0]
if not os.path.exists(targetimage):
raise errors.CreatorError("Cannot find the image: %s"
@@ -209,7 +214,7 @@ class MicCmd(cmdln.Cmdln):
raise errors.CreatorError("Cannot support image type: %s" \
% imagetype)
- chrootclass.do_chroot(targetimage)
+ chrootclass.do_chroot(targetimage, args[1:])
if __name__ == "__main__":
try: