Auto merged
[vuplus_bitbake] / bin / oeinstall
1 #!/usr/bin/env python
2
3 import sys, os, oe
4 from oe import *
5
6 __version__ = 1.0
7 cfg_oe = data.init()
8
9 def usage():
10         print
11         print "Usage: oeinstall [options ...]"
12         print
13         print "Installs specified files of supported types into a root filesystem."
14         print "Currently only supports installing OEFILES into the rootfs directly"
15         print "using their do_install target."
16         print
17         print "Options:"
18         print "  %s\t\t%s" % ("-r [arg], --root [arg]", "root directory (default=${IMAGE_ROOTFS})")
19         print "  %s\t\t%s" % ("-f [arg], --files [arg]", ".oe files available (default=${OEFILES})")
20         print "  %s\t\t%s" % ("-t [arg], --type [arg]", "installation type (direct, and any for which package_[type].oeclass exists)")
21         print "  %s\t\t%s" % ("-V, --version", "output version information and exit")
22         print
23         sys.exit(0)
24
25 def version():
26         print "OpenEmbedded Build Infrastructure Core version %s" % oe.__version__
27         print "OEInstall version %s" % __version__
28
29 def getopthash(l):
30         h = {}
31         for (opt, val) in l:
32                 h[opt] = val
33         return h
34
35 import getopt
36 try:
37         (opts, args) = getopt.getopt(sys.argv[1:], 'Vr:f:t:', [ 'version', 'root=', 'files=', 'type=' ])
38 except getopt.GetoptError:
39         usage()
40
41 # handle opts
42 opthash = getopthash(opts)
43
44 if '--version' in opthash or '-V' in opthash:
45         version()
46         sys.exit(0)
47
48 try:
49         cfg_oe = parse.handle("conf/oe.conf", cfg_oe)
50 except Exception, e:
51         fatal("Unable to open oe.conf: %s" % e)
52
53 # sanity check
54 if cfg_oe is None:
55         fatal("Unable to open/parse conf/oe.conf")
56         usage(1)
57
58 rootfs = data.getVar('IMAGE_ROOTFS', cfg_oe, 1)
59
60 if '--root' in opthash:
61         rootfs = opthash['--root']
62 if '-r' in opthash:
63         rootfs = opthash['-r']
64
65 if not rootfs:
66         oe.fatal("root filesystem not specified")
67
68 data.setVar('IMAGE_ROOTFS', rootfs, cfg_oe)
69
70 #type = 'direct'
71 type = 'tar'
72
73 if '--type' in opthash:
74         type = opthash['--type']
75 if '-t' in opthash:
76         type = opthash['-t']
77
78 topdir = data.getVar('TOPDIR', cfg_oe, 1) or os.getcwd()
79
80 # Iterate through .oe files
81 files = (data.getVar("OEFILES", cfg_oe, 1) or "").split()
82 if '-f' in opthash:
83         files.extend(opthash['-f'])
84 if '--files' in opthash:
85         files.extend(opthash['--files'])
86 data.setVar("OEFILES", ''.join(files), cfg_oe)
87
88 def get_oefiles():
89         """Get default oefiles"""
90         dirs = os.listdir(os.getcwd())
91         oefiles = []
92         for f in dirs:
93                 (root, ext) = os.path.splitext(f)
94                 if ext == ".oe":
95                         oefiles.append(os.path.abspath(os.path.join(os.getcwd(),f)))
96         return oefiles
97
98 if not len(files):
99         files = get_oefiles()
100
101 if not len(files):
102         usage()
103
104 def inst_pkg(d):
105         from oe import data, build, error
106         if data.getVar('pkg_preinst', d):
107                 try:
108                         build.exec_func('pkg_preinst', d)
109                 except build.FuncFailed:
110                         oe.note("preinst execution failure")
111                         return 0
112         if type is not 'direct':
113                 try:
114                         build.exec_func('package_%s_fn' % type, d)
115                 except build.FuncFailed:
116                         oe.error("failed obtaining the filename of the outputted package for %s" % type)
117                         return 0
118         if data.getVar('package_%s_install' % type, d):
119                 try:
120                         build.exec_func('package_%s_install' % type, d)
121                         print "package %s (%s) installed." % (p, data.getVar('PN', d, 1))
122                 except build.FuncFailed:
123                         return 0
124         else:
125                 oe.error("no package_%s_install function to execute. skipping." % type)
126                 return 0
127         if data.getVar('pkg_postinst', d):
128                 try:
129                         build.exec_func('pkg_postinst', d)
130                 except build.FuncFailed:
131                         oe.note("postinst execution failure")
132                         pass
133         return 1
134
135
136 # if type is not direct, add 'package_[type]' to INHERIT
137 if type is not 'direct':
138         inherit = data.getVar('INHERIT', cfg_oe, 1) or ""
139         inherit += " base package_%s" % type
140         data.setVarFlag('INHERIT', 'export', 1, cfg_oe)
141         data.setVar('INHERIT', inherit, cfg_oe)
142
143 pkgs_to_install = None
144 if args:
145         if not pkgs_to_install:
146                 pkgs_to_install = []
147         pkgs_to_install.extend(args)
148 if not pkgs_to_install:
149         inst_oepkgs = data.getVar('INST_OEPKGS', cfg_oe, 1)
150         if inst_oepkgs:
151                 pkgs_to_install = inst_oepkgs.split()
152 debug(1, "installing: %s" % pkgs_to_install)
153
154 import glob
155 for f in files:
156         if pkgs_to_install is not None and len(pkgs_to_install) == 0:
157                 # done!
158                 break
159         globbed = glob.glob(f) or [ f ]
160         if globbed:
161                 if [ f ] != globbed:
162                         files += globbed
163                         continue
164         from copy import deepcopy
165         fdata = deepcopy(cfg_oe)
166         try:
167                 parse.handle(f, fdata)
168         except Exception, e:
169                 error("%s" % e)
170                 fdata = None
171         if fdata is None:
172                 continue
173         # allow metadata files to add items to OEFILES
174         data.update_data(fdata)
175         addoefiles = data.getVar('OEFILES', fdata) or None
176         if addoefiles:
177                 for aof in addoefiles.split():
178                         if not files.count(aof):
179                                 if not os.path.isabs(aof):
180                                         aof = os.path.join(os.path.dirname(f),aof)
181                                 files.append(aof)
182         pkgs = (data.getVar('PACKAGES', fdata, 1) or "").split()
183         # Iterate through PACKAGES
184         for p in pkgs:
185                 if pkgs_to_install is not None:
186                         if not p in pkgs_to_install:
187                                 continue
188                 d = deepcopy(fdata)
189                 data.setVar('PKG', p, d)
190                 # Add package to overrides, collapse the metadata
191                 overrides = data.getVar('OVERRIDES', d, 1) or ""
192                 overrides += ":%s" % p
193                 data.setVar('OVERRIDES', overrides, d)
194                 data.update_data(d)
195                 data.setVarFlag('INHERIT', 'export', 1, d)
196                 # Look at vars to determine the file names for the package type in question
197                 # Call installer for a given package type as pulled from the metadata with INHERIT set properly
198                 data.setVar('D', rootfs, d)
199                 if inst_pkg(d):
200                         if pkgs_to_install is not None:
201                                 del pkgs_to_install[pkgs_to_install.index(p)]
202                 if pkgs_to_install is not None and len(pkgs_to_install) == 0:
203                         break