1 #!/usr/bin/python -tt
\r
2 # vim: ai ts=4 sts=4 et sw=4
\r
4 # Copyright (c) 2012 Intel, Inc.
\r
6 # This program is free software; you can redistribute it and/or modify it
\r
7 # under the terms of the GNU General Public License as published by the Free
\r
8 # Software Foundation; version 2 of the License
\r
10 # This program is distributed in the hope that it will be useful, but
\r
11 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
\r
12 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
\r
15 # You should have received a copy of the GNU General Public License along
\r
16 # with this program; if not, write to the Free Software Foundation, Inc., 59
\r
17 # Temple Place - Suite 330, Boston, MA 02111-1307, USA.
\r
19 """Implementation of subcmd: chroot
\r
27 from mic import msger
\r
28 from mic.utils import misc, errors
\r
29 from mic.conf import configmgr
\r
30 from mic.plugin import pluginmgr
\r
32 def _root_confirm():
\r
33 """Make sure command is called by root
\r
34 There are a lot of commands needed to be run during creating images,
\r
35 some of them must be run with root privilege like mount, kpartx"""
\r
36 if os.geteuid() != 0:
\r
37 msger.error('Root permission is required to continue, abort')
\r
39 def main(parser, args, argv):
\r
40 """mic choot entry point."""
\r
42 #args is argparser namespace, argv is the input cmd line
\r
44 raise errors.Usage("Invalid arguments")
\r
46 targetimage = args.imagefile
\r
47 if not os.path.exists(targetimage):
\r
48 raise errors.CreatorError("Cannot find the image: %s"
\r
53 configmgr.chroot['saveto'] = args.saveto
\r
55 imagetype = misc.get_image_type(targetimage)
\r
56 if imagetype in ("ext3fsimg", "ext4fsimg", "btrfsimg"):
\r
60 for pname, pcls in pluginmgr.get_plugins('imager').iteritems():
\r
61 if pname == imagetype and hasattr(pcls, "do_chroot"):
\r
66 raise errors.CreatorError("Cannot support image type: %s" \
\r
69 chrootclass.do_chroot(targetimage, args.cmd)
\r