5 import mic.utils.cmdln as cmdln
6 import mic.utils.errors as errors
7 import mic.configmgr as configmgr
8 import mic.pluginmgr as pluginmgr
9 import mic.imager.fs as fs
10 import mic.chroot as chroot
12 from mic.pluginbase import ImagerPlugin
14 class FsPlugin(ImagerPlugin):
18 @cmdln.option("--include-src", dest="include_src", help="include source pakcage")
19 def do_create(self, subcmd, opts, *args):
20 """${cmd_name}: create fs image
30 raise errors.Usage("Extra arguments given")
32 cfgmgr = configmgr.getConfigMgr()
33 createopts = cfgmgr.create
34 cfgmgr.setProperty("ksconf", ksconf)
36 plgmgr = pluginmgr.PluginMgr()
37 for (key, pcls) in plgmgr.get_plugins('backend').iteritems():
38 if key == createopts['pkgmgr']:
42 raise CreatorError("Can't find backend plugin: %s" % createopts['pkgmgr'])
44 creator = fs.FsImageCreator(createopts, pkgmgr)
46 creator.check_depend_tools()
47 creator.mount(None, createopts["cachedir"])
49 #Download the source packages ###private options
51 installed_pkgs = creator.get_installed_packages()
52 print '--------------------------------------------------'
53 print 'Generating the image with source rpms included, The number of source packages is %d.' %(len(installed_pkgs))
54 if not misc.SrcpkgsDownload(installed_pkgs, createopts["repomd"], creator._instroot, createopts["cachedir"]):
55 print "Source packages can't be downloaded"
57 creator.configure(createopts["repomd"])
59 creator.package(createopts["outdir"])
60 outimage = creator.outimage
61 creator.print_outimage_info()
62 except errors.CreatorError, e:
63 raise errors.CreatorError("failed to create image : %s" % e)
71 def do_chroot(self, target):#chroot.py parse opts&args
73 chroot.chroot(target, None, "/bin/env HOME=/root /bin/bash")
75 print >> sys.stderr, "Failed to chroot to %s." % target
77 chroot.cleanup_after_chroot("dir", None, None, None)