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.
22 from mic import configmgr, pluginmgr, chroot, msger
23 from mic.utils import cmdln, errors
24 from mic.imager import fs
26 from mic.pluginbase import ImagerPlugin
27 class FsPlugin(ImagerPlugin):
31 @cmdln.option("--include-src", dest="include_src", help="include source pakcage")
32 def do_create(self, subcmd, opts, *args):
33 """${cmd_name}: create fs image
40 raise errors.Usage("More arguments needed")
45 raise errors.Usage("Extra arguments given")
47 cfgmgr = configmgr.getConfigMgr()
48 createopts = cfgmgr.create
49 cfgmgr.setProperty("ksconf", ksconf)
51 # try to find the pkgmgr
53 for (key, pcls) in pluginmgr.PluginMgr().get_plugins('backend').iteritems():
54 if key == createopts['pkgmgr']:
59 raise CreatorError("Can't find backend plugin: %s" % createopts['pkgmgr'])
61 creator = fs.FsImageCreator(createopts, pkgmgr)
63 destdir = os.path.abspath(os.path.expanduser(createopts["outdir"]))
64 fsdir = os.path.join(destdir, creator.name)
66 if not os.path.exists(destdir):
68 elif os.path.exists(fsdir):
69 if msger.ask('The target dir: %s already exists, need to delete it?' % fsdir):
74 creator.check_depend_tools()
75 creator.mount(None, createopts["cachedir"])
77 #Download the source packages ###private options
79 installed_pkgs = creator.get_installed_packages()
80 msger.info('--------------------------------------------------')
81 msger.info('Generating the image with source rpms included, The number of source packages is %d.' %(len(installed_pkgs)))
82 if not misc.SrcpkgsDownload(installed_pkgs, createopts["repomd"], creator._instroot, createopts["cachedir"]):
83 msger.warning("Source packages can't be downloaded")
85 creator.configure(createopts["repomd"])
87 creator.package(destdir)
88 outimage = creator.outimage
89 creator.print_outimage_info()
90 except errors.CreatorError:
95 msger.info("Finished.")
99 def do_chroot(self, target):#chroot.py parse opts&args
101 chroot.chroot(target, None, "/bin/env HOME=/root /bin/bash")
103 chroot.cleanup_after_chroot("dir", None, None, None)