6 from micng.pluginbase.imager_plugin import ImagerPlugin
7 import micng.utils.cmdln as cmdln
8 import micng.utils.errors as errors
9 import micng.configmgr as configmgr
10 import micng.pluginmgr as pluginmgr
11 import micng.imager.fs as fs
12 import micng.chroot as chroot
15 class FsPlugin(ImagerPlugin):
17 @cmdln.option("--include-src", dest="include_src", help="include source pakcage")
18 def do_create(self, subcmd, opts, *args):
19 """${cmd_name}: create fs image
29 raise errors.Usage("Extra arguments given")
31 cfgmgr = configmgr.getConfigMgr()
32 createopts = cfgmgr.create
33 cfgmgr.setProperty("ksconf", ksconf)
35 plgmgr = pluginmgr.PluginMgr()
37 for (key, pcls) in plgmgr.getBackendPlugins():
38 if key == createopts['pkgmgr']:
41 #logging.warn("Can't find backend plugin: %s" % createopts['pkgmgr'])
42 raise CreatorError("Can't find backend plugin: %s" % createopts['pkgmgr'])
43 # try other backend plugin
46 # raise CreatorError("None backend found, please check it")
48 creator = fs.FsImageCreator(createopts, pkgmgr)
50 creator.check_depend_tools()
51 creator.mount(None, createopts["cachedir"])
53 #Download the source packages ###private options
55 installed_pkgs = creator.get_installed_packages()
56 print '--------------------------------------------------'
57 print 'Generating the image with source rpms included, The number of source packages is %d.' %(len(installed_pkgs))
58 if not misc.SrcpkgsDownload(installed_pkgs, createopts["repomd"], creator._instroot, createopts["cachedir"]):
59 print "Source packages can't be downloaded"
61 creator.configure(createopts["repomd"])
63 creator.package(createopts["outdir"])
64 outimage = creator.outimage
65 creator.print_outimage_info()
66 except errors.CreatorError, e:
67 raise errors.CreatorError("failed to create image : %s" % e)
74 def do_chroot(self, target):#chroot.py parse opts&args
76 chroot.chroot(target, None, "/bin/env HOME=/root /bin/bash")
78 print >> sys.stderr, "Failed to chroot to %s." % target
80 chroot.cleanup_after_chroot("dir", None, None, None)
83 mic_plugin = ["fs", FsPlugin]