1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
|
#!/usr/bin/python -t
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
@cmdln.alias("cr")
def do_create(self, argv):
"""${cmd_name}: create image
${cmd_usage}
${cmd_option_list}
"""
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__":
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)
|