summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorZhou Shuangquan <shuangquan.zhou@intel.com>2011-08-10 10:20:36 +0800
committerZhou Shuangquan <shuangquan.zhou@intel.com>2011-08-10 10:20:36 +0800
commit98657e38015bb1c3b3e04ba7a1e8c1bc72906c46 (patch)
treeeb983173750ffad3598144d7685585e5ebd8455a /tools
parentc9a40ffb278a34263b841f079e1e08f02214e0f8 (diff)
downloadmic-98657e38015bb1c3b3e04ba7a1e8c1bc72906c46.tar.gz
mic-98657e38015bb1c3b3e04ba7a1e8c1bc72906c46.tar.bz2
mic-98657e38015bb1c3b3e04ba7a1e8c1bc72906c46.zip
Initial checkin of micng
Note: create fs/loop/raw/livecd/liveusb chroot fs/loop/raw/livecd/liveusb Signed-off-by: Zhou Shuangquan <shuangquan.zhou@intel.com>
Diffstat (limited to 'tools')
-rwxr-xr-xtools/mic-image-create67
-rw-r--r--[-rwxr-xr-x]tools/micng115
-rwxr-xr-xtools/micng.ref120
3 files changed, 92 insertions, 210 deletions
diff --git a/tools/mic-image-create b/tools/mic-image-create
deleted file mode 100755
index 49bf4b4..0000000
--- a/tools/mic-image-create
+++ /dev/null
@@ -1,67 +0,0 @@
-#!/usr/bin/python -t
-
-import sys, os, os.path, string
-import micng.utils.argparse as argparse
-import micng.configmgr as configmgr
-import micng.pluginmgr as pluginmgr
-
-class Creator(object):
- name = 'create'
-
- def __init__(self):
- self.configmgr = configmgr.getConfigMgr()
- self.pluginmgr = pluginmgr.PluginMgr()
- self.pluginmgr.loadPlugins()
- self.plugincmds = self.pluginmgr.getPluginByCateg('imager')
-
- def main(self, argv=None):
-# import pdb
-# pdb.set_trace()
- if os.getuid() != 0:
- print "Please run the program as root"
- return 0
- prog = os.path.basename(sys.argv[0])
- parser = argparse.ArgumentParser(
- usage='%s [COMMONOPT] <subcommand> [SUBOPT] ARGS' % prog,
- )
- parser.add_argument('-k', '--cache', dest='cache', help='cache diretory')
- parser.add_argument('-o', '--outdir', dest='outdir', help='output diretory')
- parser.add_argument('-t', '--tmpdir', dest='tmpdir', help='temp diretory')
-
-
- subparsers = parser.add_subparsers(title='subcommands')
- for subcmd, klass in self.plugincmds:
- subcmd_help = 'create ' + subcmd + ' image'
- subcmd_parser = subparsers.add_parser(
- subcmd,
- usage=prog+' [COMMONOPT] '+subcmd+' [SUBOPT] ARGS',
- help=subcmd_help
- )
- if hasattr(klass, 'do_options'):
- add_subopt = getattr(klass, 'do_options')
- add_subopt(subcmd_parser)
- if hasattr(klass, 'do_create'):
- do_create = getattr(klass, 'do_create')
- subcmd_parser.set_defaults(func=do_create)
-
- if not argv:
- parser.print_help()
- return True
-
- args = parser.parse_args(argv)
- if args.outdir:
- self.configmgr.setProperty('outdir', args.outdir)
- if args.tmpdir:
- self.configmgr.setProperty('tmpdir', args.tmpdir)
- if args.cache:
- self.configmgr.setProperty('cache', args.cache)
-# print 'outdir', self.configmgr.getProperty('outdir')
-# print 'tmpdir', self.configmgr.getProperty('tmpdir')
-# print 'cache', self.configmgr.getProperty('cache')
- args.func(args)
- return True
-
-if __name__ == "__main__":
- create = Creator()
- ret = create.main(sys.argv[1:])
- sys.exit(ret)
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)
diff --git a/tools/micng.ref b/tools/micng.ref
deleted file mode 100755
index 5d2ad7b..0000000
--- a/tools/micng.ref
+++ /dev/null
@@ -1,120 +0,0 @@
-#!/usr/bin/python
-
-# Copyright (C) 2010 Intel Inc. All rights reserved.
-# This program is free software; it may be used, copied, modified
-# and distributed under the terms of the GNU General Public Licence,
-# either version 2, or version 3 (at your option).
-
-import sys
-import mic3.cmdln as cmdln
-import optparse as _optparse
-
-try:
- import mic3.__version__
- VERSION = mic3.__version__.version
-except:
- VERSION = 'unknown'
-
-class MIC3(cmdln.Cmdln):
- """Usage: mic [GLOBALOPTS] SUBCOMMAND [OPTS] [ARGS...]
- or: mic help SUBCOMMAND
-
- MeeGo Image Tool.
- Type 'mic help <subcommand>' for help on a specific subcommand.
-
- ${command_list}
- ${help_list}
- global ${option_list}
- For additional information, see
- * http://www.meego.com/
- """
-
- name = 'mic'
- version = VERSION
-
- @cmdln.option("-v", "--verbose", action="store_true",
- help="print extra information")
-
- def get_cmd_help(self, cmdname):
- doc = self._get_cmd_handler(cmdname).__doc__
- doc = self._help_reindent(doc)
- doc = self._help_preprocess(doc, cmdname)
- doc = doc.rstrip() + '\n' # trim down trailing space
- return self._str(doc)
-
- """ create image """
- @cmdln.alias('cr')
- @cmdln.option("-c", "--config", type="string", dest="config",
- help="Path to kickstart config file")
-
- @cmdln.option("-f", "--format", type="string", dest="format",
- help="Image format, you can specify as fs, livecd, liveusb, loop, raw, nand, mrstnand, ubi, jffs2, vdi or vmdk")
-
- @cmdln.option("-t", "--tmpdir", type="string",
- dest="tmpdir",
- help="Temporary directory to use (default: /var/tmp)")
- @cmdln.option("-k", "--cache", type="string",
- dest="cachedir", default=None,
- help="Cache directory to use (default: private cache)")
- @cmdln.option("-o", "--outdir", type="string",
- dest="outdir", default=None,
- help="Output directory to use (default: current work dir)")
- @cmdln.option("", "--release", type="string",
- dest="release", default=None,
- help="Generate a MeeGo release with all necessary files for publishing.")
- @cmdln.option("", "--genchecksum", action="store_true",
- dest="genchecksum", default=False,
- help="Generate checksum for image file if this option is provided")
- @cmdln.option("-P", "--prefix", type="string",
- dest="prefix", default=None,
- help="Image name prefix (default: meego)")
- @cmdln.option("-S", "--suffix", type="string",
- dest="suffix", default=None,
- help="Image name suffix (default: date stamp)")
- @cmdln.option("-a", "--arch", type="string",
- dest="arch", default=None,
- help="Specify target arch of image, for example: arm")
- @cmdln.option("", "--use-comps", action="store_true",
- dest="use_comps", default=False,
- help="Use comps instead of patterns if comps exists")
- @cmdln.option("", "--record-pkgs", type="string",
- dest="record_pkgs", default=None,
- help="Record the installed packages, valid values: name, content")
- @cmdln.option("", "--fstype", type="string",
- dest="fstype", default="vfat",
- help="File system type for live USB file image, ext3 or vfat, the default is vfat.")
- @cmdln.option("", "--overlay-size-mb", type="int", default=64,
- help="Overlay size in MB as unit, it means how size changes you can save in your live USB disk.")
- @cmdln.option('-d', '--debug', action='store_true',
- help='Output debugging information')
- @cmdln.option('-v', '--verbose', dest='verbose', action='store_true',
- help='Output verbose information')
- @cmdln.option('', '--logfile', type="string", dest="file",
- help='Save debug information to FILE')
- @cmdln.option("", "--save-kernel", action="store_true",
- dest="save_kernel", default=False,
- help="Save kernel image file into outdir")
- @cmdln.option("", "--pkgmgr", type="string",
- help="Specify the package manager, the available package managers have zypper and yum currently.")
- @cmdln.option("", "--volumeid", type="string", default=None,
- help="Specify volume id, valid only for livecd")
- def do_create(self, subcmd, opts, *args):
- """${cmd_name}: Create an image
-
- This command is used to create various images, including
- live CD, live USB, loop, raw/KVM/QEMU, VMWare/vmdk,
- VirtualBox/vdi, Moorestown/mrstnand, jffs2 and ubi.
-
- Examples:
- mic create # create an image according to the default config
- mic create --format=liveusb # create a live USB image
-
- ${cmd_usage}
- ${cmd_option_list}
- """
-
- print subcmd, opts, args
-
-if __name__ == "__main__":
- mic = MIC3()
- sys.exit(mic.main(sys.argv))