6 import micng.utils.cmdln as cmdln
7 import micng.utils.misc as misc
8 import micng.utils.errors as errors
9 import micng.configmgr as configmgr
10 import micng.pluginmgr as pluginmgr
11 import micng.creator as creator
13 class Micng(cmdln.Cmdln):
14 """Usage: micng SUBCOMMAND [OPTS] [ARGS...]
16 MeeGo Image Creator Tool.
21 For additional information, see
22 * http://www.meego.com/
28 def do_create(self, argv):
29 """${cmd_name}: create image
34 cr = creator.Creator()
35 ret = cr.main(argv[1:])
39 def do_convert(self, subcmd, opts, *args):
40 """${cmd_name}: convert an image format to another one
43 micng convert <imagefile> <destformat>
50 raise errors.Usage("It takes 2 arguments (1 given)")
55 raise errors.Usage("Extra argument given")
58 raise errors.Usage("You must run as root")
60 srcformat = misc.get_image_type(srcimg)
61 if srcformat == "ext3fsimg":
64 pkgmgr = pluginmgr.PluginMgr()
66 imagers = pmgr.getImagerPlugins()
70 for iname, icls in imagers:
71 if iname == srcformat and hasattr(icls, "do_unpack"):
73 if iname == destformat and hasattr(icls, "do_pack"):
76 if (srcimager and destimager) is None:
77 raise CreatorError("Can't convert from %s to %s" %(srcformat, desformat))
79 base_on = srcimager.do_unpack(srcimg)
80 destimager.do_pack(base_on)
82 @cmdln.option("-d", "--debug", action="store_true", help="debug message")
83 @cmdln.option("-v", "--verbose", action="store_true", help="verbose infomation")
85 def do_chroot(self, subcmd, opts, *args):
86 """${cmd_name}: chroot an image
89 micng chroot <imagefile>
100 raise errors.Usage("Extra argument given")
102 if os.geteuid() != 0:
103 raise errors.Usage("You must run as root")
105 # Fixeme? sub-logger to be used
107 logging.getLogger().setLevel(logging.INFO)
109 logging.getLogger().setLevel(logging.DEBUG)
111 imagetype = misc.get_image_type(targetimage)
114 if imagetype == "ext3fsimg":
117 pkgmgr = pluginmgr.PluginMgr()
121 for (pname, pcls) in pkgmgr.getImagerPlugins():
122 if pname == imagetype and hasattr(pcls, "do_chroot"):
127 raise CreatorError("Don't support image type: %s" % imagetype)
129 chrootclass.do_chroot(targetimage)
131 if __name__ == "__main__":
132 logging.getLogger().setLevel(logging.ERROR)
136 except errors.CreatorError, msg:
138 print >> sys.stderr, msg
139 except errors.Usage, msg:
141 print >> sys.stderr, msg