3 # Copyright (c) 2011 Intel, Inc.
5 # This program is free software; you can redistribute it and/or modify it
6 # under the terms of the GNU General Public License as published by the Free
7 # Software Foundation; version 2 of the License
9 # This program is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 # You should have received a copy of the GNU General Public License along
15 # with this program; if not, write to the Free Software Foundation, Inc., 59
16 # Temple Place - Suite 330, Boston, MA 02111-1307, USA.
21 from mic import chroot, msger
22 from mic.utils import cmdln, misc, errors, fs_related
23 from mic.imager import fs
24 from mic.conf import configmgr
25 from mic.plugin import pluginmgr
27 from mic.pluginbase import ImagerPlugin
28 class FsPlugin(ImagerPlugin):
32 @cmdln.option("--include-src",
36 help="Generate a image with source rpms included")
37 def do_create(self, subcmd, opts, *args):
38 """${cmd_name}: create fs image
41 ${name} ${cmd_name} <ksfile> [OPTS]
46 creatoropts = configmgr.create
50 if len(creatoropts['record_pkgs']) > 0:
51 recording_pkgs = creatoropts['record_pkgs']
53 if creatoropts['release'] is not None:
54 if 'name' not in recording_pkgs:
55 recording_pkgs.append('name')
57 ksconf = misc.normalize_ksfile(ksconf,
58 creatoropts['release'],
61 configmgr._ksconf = ksconf
63 # Called After setting the configmgr._ksconf as the creatoropts['name'] is reset there.
64 if creatoropts['release'] is not None:
65 creatoropts['outdir'] = "%s/%s/images/%s/" % (creatoropts['outdir'], creatoropts['release'], creatoropts['name'])
67 # try to find the pkgmgr
69 for (key, pcls) in pluginmgr.get_plugins('backend').iteritems():
70 if key == creatoropts['pkgmgr']:
75 pkgmgrs = pluginmgr.get_plugins('backend').keys()
76 raise errors.CreatorError("Can't find package manager: %s (availables: %s)" % (creatoropts['pkgmgr'], ', '.join(pkgmgrs)))
78 creator = fs.FsImageCreator(creatoropts, pkgmgr)
79 creator._include_src = opts.include_src
81 if len(recording_pkgs) > 0:
82 creator._recording_pkgs = recording_pkgs
84 self.check_image_exists(creator.destdir,
87 creatoropts['release'])
90 creator.check_depend_tools()
91 creator.mount(None, creatoropts["cachedir"])
93 #Download the source packages ###private options
95 installed_pkgs = creator.get_installed_packages()
96 msger.info('--------------------------------------------------')
97 msger.info('Generating the image with source rpms included ...')
98 if not misc.SrcpkgsDownload(installed_pkgs, creatoropts["repomd"], creator._instroot, creatoropts["cachedir"]):
99 msger.warning("Source packages can't be downloaded")
101 creator.configure(creatoropts["repomd"])
102 creator.copy_kernel()
104 creator.package(creatoropts["outdir"])
105 if creatoropts['release'] is not None:
106 creator.release_output(ksconf, creatoropts['outdir'], creatoropts['release'])
107 creator.print_outimage_info()
108 except errors.CreatorError:
113 msger.info("Finished.")
117 def do_chroot(self, target):#chroot.py parse opts&args
119 envcmd = fs_related.find_binary_inchroot("env", target)
121 cmdline = "%s HOME=/root /bin/bash" % envcmd
123 cmdline = "/bin/bash"
124 chroot.chroot(target, None, cmdline)
126 chroot.cleanup_after_chroot("dir", None, None, None)