summaryrefslogtreecommitdiff
path: root/tools/micng
diff options
context:
space:
mode:
Diffstat (limited to 'tools/micng')
-rw-r--r--[-rwxr-xr-x]tools/micng115
1 files changed, 92 insertions, 23 deletions
diff --git a/tools/micng b/tools/micng
index ea98dbd..86e81c0 100755..100644
--- a/tools/micng
+++ b/tools/micng
@@ -1,35 +1,104 @@
#!/usr/bin/python -t
-import sys, os
-import subprocess
+import os
+import sys
+import logging
import micng.utils.cmdln as cmdln
+import micng.utils.misc as misc
+import micng.utils.errors as errors
+import micng.configmgr as configmgr
+import micng.pluginmgr as pluginmgr
+import micng.creator as creator
+
+class Micng(cmdln.Cmdln):
+ """Usage: micng SUBCOMMAND [OPTS] [ARGS...]
+
+ MeeGo Image Creator Tool.
+
+ ${command_list}
+ ${help_list}
+ global ${option_list}
+ For additional information, see
+ * http://www.meego.com/
+ """
+ name = 'micng'
+ version = None
-class Mic(cmdln.Cmdln):
- def run_subcmd(self, subcmd, opts, args):
- creator = "mic-image-create"
- tools = {
- "cr":creator, "create":creator,
- }
-
- argv = [tools[subcmd]]
- argv.extend(args)
- subprocess.call(argv)
-
@cmdln.alias("cr")
def do_create(self, argv):
"""${cmd_name}: create image
- ${cmd_usage}
- ${cmd_option_list}
+ ${cmd_usage}
+ ${cmd_option_list}
"""
- self.run_subcmd("create", None, argv[1:])
-
- @cmdln.alias("cv")
- def do_convert(self, argv):
- """${cmd_name}: convert an image format to another one
+ cr = creator.Creator()
+ ret = cr.main(argv[1:])
+ return ret
+
+# @cmdln.alias("cv")
+# def do_convert(self, argv):
+# """${cmd_name}: convert an image format to another one
+# """
+# pass
+
+ @cmdln.option("-d", "--debug", action="store_true", help="debug message")
+ @cmdln.option("-v", "--verbose", action="store_true", help="verbose infomation")
+ @cmdln.alias("ch")
+ def do_chroot(self, subcmd, opts, *args):
+ """${cmd_name}: chroot an image
+
+ usage:
+ micng chroot <imagefile>
+
+ ${cmd_option_list}
"""
+ if len(args) == 0:
+ self.emptyline()
+ # print help
+ return
+ if len(args) == 1:
+ targetimage = args[0]
+ else:
+ raise errors.Usage("Extra argument given")
+
+ if os.geteuid() != 0:
+ raise errors.Usage("You must run as root")
+
+ # Fixeme? sub-logger to be used
+ if opts.verbose:
+ logging.getLogger().setLevel(logging.INFO)
+ if opts.debug:
+ logging.getLogger().setLevel(logging.DEBUG)
+
+ imagetype = misc.get_image_type(targetimage)
+ if not imagetype:
+ imagetype = "fs"
+ if imagetype == "ext3fsimg":
+ imagetype = "loop"
+
+ pkgmgr = pluginmgr.PluginMgr()
+ pkgmgr.loadPlugins()
+
+ chrootclass = None
+ for (pname, pcls) in pkgmgr.getImagerPlugins():
+ if pname == imagetype and hasattr(pcls, "do_chroot"):
+ chrootclass = pcls
+ break
+
+ if not chrootclass:
+ raise CreatorError("Don't support image type: %s" % imagetype)
+
+ chrootclass.do_chroot(targetimage)
if __name__ == "__main__":
- mic = Mic()
- ret = mic.main()
- sys.exit(ret)
+ logging.getLogger().setLevel(logging.ERROR)
+ micng = Micng()
+ try:
+ ret = micng.main()
+ except errors.CreatorError, msg:
+ ret = 2
+ print >> sys.stderr, msg
+ except errors.Usage, msg:
+ ret = 2
+ print >> sys.stderr, msg
+ sys.exit(ret)