summaryrefslogtreecommitdiffstats
path: root/meta/lib/oe/packagedata.py
diff options
context:
space:
mode:
Diffstat (limited to 'meta/lib/oe/packagedata.py')
-rw-r--r--meta/lib/oe/packagedata.py106
1 files changed, 106 insertions, 0 deletions
diff --git a/meta/lib/oe/packagedata.py b/meta/lib/oe/packagedata.py
new file mode 100644
index 0000000000..7f0a89d282
--- /dev/null
+++ b/meta/lib/oe/packagedata.py
@@ -0,0 +1,106 @@
1import os
2import bb.data
3import codecs
4
5def packaged(pkg, d):
6 return os.access(get_subpkgedata_fn(pkg, d) + '.packaged', os.R_OK)
7
8def read_pkgdatafile(fn):
9 pkgdata = {}
10
11 def decode(str):
12 c = codecs.getdecoder("string_escape")
13 return c(str)[0]
14
15 if os.access(fn, os.R_OK):
16 import re
17 f = file(fn, 'r')
18 lines = f.readlines()
19 f.close()
20 r = re.compile("([^:]+):\s*(.*)")
21 for l in lines:
22 m = r.match(l)
23 if m:
24 pkgdata[m.group(1)] = decode(m.group(2))
25
26 return pkgdata
27
28def get_subpkgedata_fn(pkg, d):
29 archs = bb.data.expand("${PACKAGE_ARCHS}", d).split(" ")
30 archs.reverse()
31 pkgdata = bb.data.expand('${TMPDIR}/pkgdata/', d)
32 targetdir = bb.data.expand('${TARGET_VENDOR}-${TARGET_OS}/runtime/', d)
33 for arch in archs:
34 fn = pkgdata + arch + targetdir + pkg
35 if os.path.exists(fn):
36 return fn
37 return bb.data.expand('${PKGDATA_DIR}/runtime/%s' % pkg, d)
38
39def has_subpkgdata(pkg, d):
40 return os.access(get_subpkgedata_fn(pkg, d), os.R_OK)
41
42def read_subpkgdata(pkg, d):
43 return read_pkgdatafile(get_subpkgedata_fn(pkg, d))
44
45def has_pkgdata(pn, d):
46 fn = bb.data.expand('${PKGDATA_DIR}/%s' % pn, d)
47 return os.access(fn, os.R_OK)
48
49def read_pkgdata(pn, d):
50 fn = bb.data.expand('${PKGDATA_DIR}/%s' % pn, d)
51 return read_pkgdatafile(fn)
52
53#
54# Collapse FOO_pkg variables into FOO
55#
56def read_subpkgdata_dict(pkg, d):
57 ret = {}
58 subd = read_pkgdatafile(get_subpkgedata_fn(pkg, d))
59 for var in subd:
60 newvar = var.replace("_" + pkg, "")
61 ret[newvar] = subd[var]
62 return ret
63
64def _pkgmap(d):
65 """Return a dictionary mapping package to recipe name."""
66
67 target_os = d.getVar("TARGET_OS", True)
68 target_vendor = d.getVar("TARGET_VENDOR", True)
69 basedir = os.path.dirname(d.getVar("PKGDATA_DIR", True))
70
71 dirs = ("%s%s-%s" % (arch, target_vendor, target_os)
72 for arch in d.getVar("PACKAGE_ARCHS", True).split())
73
74 pkgmap = {}
75 for pkgdatadir in (os.path.join(basedir, sys) for sys in dirs):
76 try:
77 files = os.listdir(pkgdatadir)
78 except OSError:
79 continue
80
81 for pn in filter(lambda f: not os.path.isdir(os.path.join(pkgdatadir, f)), files):
82 try:
83 pkgdata = read_pkgdatafile(os.path.join(pkgdatadir, pn))
84 except OSError:
85 continue
86
87 for pkg in pkgdata["PACKAGES"].split():
88 pkgmap[pkg] = pn
89
90 return pkgmap
91
92def pkgmap(d):
93 """Return a dictionary mapping package to recipe name.
94 Cache the mapping in the metadata"""
95
96 pkgmap_data = d.getVar("__pkgmap_data", False)
97 if pkgmap_data is None:
98 pkgmap_data = _pkgmap(d)
99 d.setVar("__pkgmap_data", pkgmap_data)
100
101 return pkgmap_data
102
103def recipename(pkg, d):
104 """Return the recipe name for the given binary package name."""
105
106 return pkgmap(d).get(pkg)