summaryrefslogtreecommitdiffstats
path: root/meta/lib/oe/packagedata.py
diff options
context:
space:
mode:
authorTudor Florea <tudor.florea@enea.com>2014-10-16 03:05:19 +0200
committerTudor Florea <tudor.florea@enea.com>2014-10-16 03:05:19 +0200
commitc527fd1f14c27855a37f2e8ac5346ce8d940ced2 (patch)
treebb002c1fdf011c41dbd2f0927bed23ecb5f83c97 /meta/lib/oe/packagedata.py
downloadpoky-daisy-140929.tar.gz
initial commit for Enea Linux 4.0-140929daisy-140929
Migrated from the internal git server on the daisy-enea-point-release branch Signed-off-by: Tudor Florea <tudor.florea@enea.com>
Diffstat (limited to 'meta/lib/oe/packagedata.py')
-rw-r--r--meta/lib/oe/packagedata.py94
1 files changed, 94 insertions, 0 deletions
diff --git a/meta/lib/oe/packagedata.py b/meta/lib/oe/packagedata.py
new file mode 100644
index 0000000000..cd5f0445f5
--- /dev/null
+++ b/meta/lib/oe/packagedata.py
@@ -0,0 +1,94 @@
1import codecs
2
3def packaged(pkg, d):
4 return os.access(get_subpkgedata_fn(pkg, d) + '.packaged', os.R_OK)
5
6def read_pkgdatafile(fn):
7 pkgdata = {}
8
9 def decode(str):
10 c = codecs.getdecoder("string_escape")
11 return c(str)[0]
12
13 if os.access(fn, os.R_OK):
14 import re
15 f = open(fn, 'r')
16 lines = f.readlines()
17 f.close()
18 r = re.compile("([^:]+):\s*(.*)")
19 for l in lines:
20 m = r.match(l)
21 if m:
22 pkgdata[m.group(1)] = decode(m.group(2))
23
24 return pkgdata
25
26def get_subpkgedata_fn(pkg, d):
27 return d.expand('${PKGDATA_DIR}/runtime/%s' % pkg)
28
29def has_subpkgdata(pkg, d):
30 return os.access(get_subpkgedata_fn(pkg, d), os.R_OK)
31
32def read_subpkgdata(pkg, d):
33 return read_pkgdatafile(get_subpkgedata_fn(pkg, d))
34
35def has_pkgdata(pn, d):
36 fn = d.expand('${PKGDATA_DIR}/%s' % pn)
37 return os.access(fn, os.R_OK)
38
39def read_pkgdata(pn, d):
40 fn = d.expand('${PKGDATA_DIR}/%s' % pn)
41 return read_pkgdatafile(fn)
42
43#
44# Collapse FOO_pkg variables into FOO
45#
46def read_subpkgdata_dict(pkg, d):
47 ret = {}
48 subd = read_pkgdatafile(get_subpkgedata_fn(pkg, d))
49 for var in subd:
50 newvar = var.replace("_" + pkg, "")
51 if newvar == var and var + "_" + pkg in subd:
52 continue
53 ret[newvar] = subd[var]
54 return ret
55
56def _pkgmap(d):
57 """Return a dictionary mapping package to recipe name."""
58
59 pkgdatadir = d.getVar("PKGDATA_DIR", True)
60
61 pkgmap = {}
62 try:
63 files = os.listdir(pkgdatadir)
64 except OSError:
65 bb.warn("No files in %s?" % pkgdatadir)
66 files = []
67
68 for pn in filter(lambda f: not os.path.isdir(os.path.join(pkgdatadir, f)), files):
69 try:
70 pkgdata = read_pkgdatafile(os.path.join(pkgdatadir, pn))
71 except OSError:
72 continue
73
74 packages = pkgdata.get("PACKAGES") or ""
75 for pkg in packages.split():
76 pkgmap[pkg] = pn
77
78 return pkgmap
79
80def pkgmap(d):
81 """Return a dictionary mapping package to recipe name.
82 Cache the mapping in the metadata"""
83
84 pkgmap_data = d.getVar("__pkgmap_data", False)
85 if pkgmap_data is None:
86 pkgmap_data = _pkgmap(d)
87 d.setVar("__pkgmap_data", pkgmap_data)
88
89 return pkgmap_data
90
91def recipename(pkg, d):
92 """Return the recipe name for the given binary package name."""
93
94 return pkgmap(d).get(pkg)