3 # Copyright 2011 Intel, Inc.
5 # This copyrighted material is made available to anyone wishing to use, modify,
6 # copy, or redistribute it subject to the terms and conditions of the GNU
7 # General Public License v.2. This program is distributed in the hope that it
8 # will be useful, but WITHOUT ANY WARRANTY expressed or implied, including the
9 # implied warranties of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 # See the GNU General Public License for more details.
12 # You should have received a copy of the GNU General Public License along with
13 # this program; if not, write to the Free Software Foundation, Inc., 51
14 # Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. Any Red Hat
15 # trademarks that are incorporated in the source code or documentation are not
16 # subject to the GNU General Public License and may only be used or replicated
17 # with the express permission of Red Hat, Inc.
20 from mic import configmgr, pluginmgr, chroot, msger
21 from mic.utils import cmdln, errors
22 from mic.imager import fs
24 from mic.pluginbase import ImagerPlugin
25 class FsPlugin(ImagerPlugin):
29 @cmdln.option("--include-src", dest="include_src", help="include source pakcage")
30 def do_create(self, subcmd, opts, *args):
31 """${cmd_name}: create fs image
38 raise errors.Usage("More arguments needed")
43 raise errors.Usage("Extra arguments given")
45 cfgmgr = configmgr.getConfigMgr()
46 createopts = cfgmgr.create
47 cfgmgr.setProperty("ksconf", ksconf)
49 # try to find the pkgmgr
51 plgmgr = pluginmgr.PluginMgr()
52 for (key, pcls) in plgmgr.get_plugins('backend').iteritems():
53 if key == createopts['pkgmgr']:
58 raise CreatorError("Can't find backend plugin: %s" % createopts['pkgmgr'])
60 creator = fs.FsImageCreator(createopts, pkgmgr)
62 creator.check_depend_tools()
63 creator.mount(None, createopts["cachedir"])
65 #Download the source packages ###private options
67 installed_pkgs = creator.get_installed_packages()
68 msger.info('--------------------------------------------------')
69 msger.info('Generating the image with source rpms included, The number of source packages is %d.' %(len(installed_pkgs)))
70 if not misc.SrcpkgsDownload(installed_pkgs, createopts["repomd"], creator._instroot, createopts["cachedir"]):
71 msger.warning("Source packages can't be downloaded")
73 creator.configure(createopts["repomd"])
75 creator.package(createopts["outdir"])
76 outimage = creator.outimage
77 creator.print_outimage_info()
78 except errors.CreatorError, e:
79 raise errors.CreatorError("failed to create image : %s" % e)
82 msger.info("Finished.")
87 def do_chroot(self, target):#chroot.py parse opts&args
89 chroot.chroot(target, None, "/bin/env HOME=/root /bin/bash")
91 msger.warning("Failed to chroot to %s." % target)
93 chroot.cleanup_after_chroot("dir", None, None, None)