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, rt_util
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]
47 raise errors.Usage("Extra arguments given")
49 creatoropts = configmgr.create
52 if configmgr.bootstrap['enable']:
53 configmgr._ksconf = ksconf
54 rt_util.bootstrap_mic()
57 if len(creatoropts['record_pkgs']) > 0:
58 recording_pkgs = creatoropts['record_pkgs']
60 if creatoropts['release'] is not None:
61 if 'name' not in recording_pkgs:
62 recording_pkgs.append('name')
64 configmgr._ksconf = ksconf
66 # Called After setting the configmgr._ksconf as the creatoropts['name'] is reset there.
67 if creatoropts['release'] is not None:
68 creatoropts['outdir'] = "%s/%s/images/%s/" % (creatoropts['outdir'], creatoropts['release'], creatoropts['name'])
70 # try to find the pkgmgr
72 backends = pluginmgr.get_plugins('backend')
73 if 'auto' == creatoropts['pkgmgr']:
74 for key in configmgr.prefer_backends:
76 pkgmgr = backends[key]
79 for key in backends.keys():
80 if key == creatoropts['pkgmgr']:
81 pkgmgr = backends[key]
85 raise errors.CreatorError("Can't find backend: %s, "
86 "available choices: %s" %
87 (creatoropts['pkgmgr'],
88 ','.join(backends.keys())))
90 creator = fs.FsImageCreator(creatoropts, pkgmgr)
91 creator._include_src = opts.include_src
93 if len(recording_pkgs) > 0:
94 creator._recording_pkgs = recording_pkgs
96 self.check_image_exists(creator.destdir,
99 creatoropts['release'])
102 creator.check_depend_tools()
103 creator.mount(None, creatoropts["cachedir"])
105 #Download the source packages ###private options
107 installed_pkgs = creator.get_installed_packages()
108 msger.info('--------------------------------------------------')
109 msger.info('Generating the image with source rpms included ...')
110 if not misc.SrcpkgsDownload(installed_pkgs, creatoropts["repomd"], creator._instroot, creatoropts["cachedir"]):
111 msger.warning("Source packages can't be downloaded")
113 creator.configure(creatoropts["repomd"])
114 creator.copy_kernel()
116 creator.package(creatoropts["outdir"])
117 if creatoropts['release'] is not None:
118 creator.release_output(ksconf, creatoropts['outdir'], creatoropts['release'])
119 creator.print_outimage_info()
120 except errors.CreatorError:
125 msger.info("Finished.")
129 def do_chroot(self, target, cmd):#chroot.py parse opts&args
132 cmdline = ' '.join(cmd)
134 cmdline = "/bin/bash"
135 envcmd = fs_related.find_binary_inchroot("env", target)
137 cmdline = "%s HOME=/root %s" % (envcmd, cmdline)
138 chroot.chroot(target, None, cmdline)
140 chroot.cleanup_after_chroot("dir", None, None, None)