eliminate usage of string module
[vuplus_bitbake] / bin / oeimage
1 #!/usr/bin/env python
2
3 import sys, os, oe
4 from oe import *
5
6 __version__ = 1.0
7 type = "jffs2"
8 cfg_oe = data.init()
9 cfg_oespawn = data.init()
10
11
12 def usage():
13         print "Usage: oeimage [options ...]"
14         print "Creates an image for a target device from a root filesystem,"
15         print "obeying configuration parameters from the OpenEmbedded"
16         print "configuration files, thereby easing handling of deviceisms."
17         print ""
18         print "  %s\t\t%s" % ("-r [arg], --root [arg]", "root directory (default=${IMAGE_ROOTFS})")
19         print "  %s\t\t%s" % ("-t [arg], --type [arg]", "image type (jffs2[default], cramfs)")
20         print "  %s\t\t%s" % ("-v, --version", "output version information and exit")
21         sys.exit(0)
22
23 def version():
24         print "OpenEmbedded Build Infrastructure Core version %s" % oe.__version__
25         print "OEImage version %s" % __version__
26
27 def emit_oe(d, base_d = {}):
28         for v in d.keys():
29                 if d[v] != base_d[v]:
30                         data.emit_var(v, d)
31
32 def getopthash(l):
33         h = {}
34         for (opt, val) in l:
35                 h[opt] = val
36         return h
37
38 import getopt
39 try:
40         (opts, args) = getopt.getopt(sys.argv[1:], 'vr:t:', [ 'version', 'root=', 'type=' ])
41 except getopt.GetoptError:
42         usage()
43
44 # handle opts
45 opthash = getopthash(opts)
46
47 if '--version' in opthash or '-v' in opthash:
48         version()
49         sys.exit(0)
50
51 try:
52         cfg_oe = parse.handle("conf/oe.conf", cfg_oe)
53 except IOError:
54         fatal("Unable to open oe.conf")
55
56 # sanity check
57 if cfg_oe is None:
58         fatal("Unable to open/parse conf/oe.conf")
59         usage(1)
60
61 rootfs = data.getVar('IMAGE_ROOTFS', cfg_oe, 1)
62
63 if '--root' in opthash:
64         rootfs = opthash['--root']
65 if '-r' in opthash:
66         rootfs = opthash['-r']
67
68 if '--type' in opthash:
69         type = opthash['--type']
70 if '-t' in opthash:
71         type = opthash['-t']
72
73 if not rootfs:
74         oe.fatal("IMAGE_ROOTFS not defined")
75
76 data.setVar('IMAGE_ROOTFS', rootfs, cfg_oe)
77
78 from copy import copy, deepcopy
79 localdata = deepcopy(cfg_oe)
80
81 overrides = data.getVar('OVERRIDES', localdata)
82 if not overrides:
83         oe.fatal("OVERRIDES not defined.")
84 data.setVar('OVERRIDES', '%s:%s' % (overrides, type), localdata)
85 data.update_data(localdata)
86 data.setVar('OVERRIDES', overrides, localdata)
87
88 topdir = data.getVar('TOPDIR', localdata, 1) or os.getcwd()
89
90 cmd = data.getVar('IMAGE_CMD', localdata, 1)
91 if not cmd:
92         oe.fatal("IMAGE_CMD not defined")
93
94 outdir = data.getVar('DEPLOY_DIR_IMAGE', localdata, 1)
95 if not outdir:
96         oe.fatal('DEPLOY_DIR_IMAGE not defined')
97 mkdirhier(outdir)
98
99 #depends = data.getVar('IMAGE_DEPENDS', localdata, 1) or ""
100 #if depends:
101 #       oe.note("Spawning oemake to satisfy dependencies: %s" % depends)
102 #       ret = os.system('oemake %s' % depends)
103 #       if ret != 0:
104 #               oe.error("executing oemake to satisfy dependencies")
105
106 oe.note("Executing %s" % cmd)
107 data.setVar('T', '${TMPDIR}', localdata)
108 data.setVar('image_cmd', cmd, localdata)
109 data.setVarFlag('image_cmd', 'func', 1, localdata)
110 try:
111         oe.build.exec_func('image_cmd', localdata)
112 except oe.build.FuncFailed:
113         sys.exit(1)
114 #ret = os.system(cmd)
115 #sys.exit(ret)