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.
19 from mic import chroot, msger, rt_util
20 from mic.utils import misc, errors, fs_related, runner
21 from mic.imager import fs
22 from mic.plugin import pluginmgr
24 from mic.pluginbase import ImagerPlugin
25 class FsPlugin(ImagerPlugin):
29 def do_create(self, args):
30 """${cmd_name}: create fs image
33 creatoropts, pkgmgr, recording_pkgs = rt_util.prepare_create(args)
35 creator = fs.FsImageCreator(creatoropts, pkgmgr)
36 creator._include_src = args.include_src
38 if len(recording_pkgs) > 0:
39 creator._recording_pkgs = recording_pkgs
41 self.check_image_exists(creator.destdir,
44 creatoropts['release'])
47 creator.check_depend_tools()
48 creator.mount(None, creatoropts["cachedir"])
51 #Download the source packages ###private options
53 installed_pkgs = creator.get_installed_packages()
54 msger.info('Generating the image with source rpms included ...')
55 if not misc.SrcpkgsDownload(installed_pkgs, creatoropts["repomd"],
56 creator._instroot, creatoropts["cachedir"]):
57 msger.warning("Source packages can't be downloaded")
59 creator.configure(creatoropts["repomd"])
62 creator.package(creatoropts["destdir"])
63 creator.create_manifest()
64 if creatoropts['release'] is not None:
65 creator.release_output(args.ksfile, creatoropts['destdir'],
66 creatoropts['release'])
67 creator.print_outimage_info()
68 except errors.CreatorError:
73 #Run script of --run_script after image created
74 if creatoropts['run_script']:
75 cmd = creatoropts['run_script']
78 except OSError as err:
79 msger.warning(str(err))
82 msger.info("Finished.")
86 def do_chroot(self, target, cmd=[]):#chroot.py parse opts&args
89 cmdline = ' '.join(cmd)
92 envcmd = fs_related.find_binary_inchroot("env", target)
94 cmdline = "%s HOME=/root %s" % (envcmd, cmdline)
95 chroot.chroot(target, None, cmdline)
97 chroot.cleanup_after_chroot("dir", None, None, None)