diff options
author | yanqingx.li <yanqingx.li@intel.com> | 2012-09-26 14:47:55 +0800 |
---|---|---|
committer | Gui Chen <gui.chen@intel.com> | 2012-09-26 15:08:22 +0800 |
commit | fee503b47d468cbc7c539910796269b65cbff750 (patch) | |
tree | ae593364b7fe4f4e064e3d526009ace86f60accf /tools | |
parent | ab277036676eb8cc77d21ce1b9366da5ee8c67d2 (diff) | |
download | mic-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-x | tools/mic | 19 |
1 files changed, 12 insertions, 7 deletions
@@ -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: |