]> code.ossystems Code Review - openembedded-core.git/commitdiff
Move packagedata code into oe.packagedata (sync from OE)
authorChris Larson <chris_larson@mentor.com>
Sun, 10 Oct 2010 04:24:38 +0000 (21:24 -0700)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Fri, 20 May 2011 16:41:24 +0000 (17:41 +0100)
Signed-off-by: Chris Larson <chris_larson@mentor.com>
meta/classes/package.bbclass
meta/classes/package_rpm.bbclass
meta/classes/packagedata.bbclass
meta/lib/oe/packagedata.py [new file with mode: 0644]

index 4eb349d431f23811b54503050898a5964b66749d..2c6d30ccd890ec6c7c3be7cbdd3753d5b1677db5 100644 (file)
@@ -295,7 +295,9 @@ def runstrip(file, elftype, d):
 #
 
 def get_package_mapping (pkg, d):
-       data = read_subpkgdata(pkg, d)
+       import oe.packagedata
+
+       data = oe.packagedata.read_subpkgdata(pkg, d)
        key = "PKG_%s" % pkg
 
        if key in data:
index b86356de2ecbddfcc24f929ab1bafad4dad5d30b..1d8c68633067ab8a7f2f59498a65a450297c5e7f 100644 (file)
@@ -316,6 +316,7 @@ package_install_internal_rpm () {
 
 python write_specfile () {
        import textwrap
+       import oe.packagedata
 
        # We need to change '-' in a version field to '+'
        # This needs to be done BEFORE the mapping_rename_hook
@@ -328,7 +329,7 @@ python write_specfile () {
                                ver = depends_dict[dep]
                                if dep and ver:
                                        if '-' in ver:
-                                               subd = read_subpkgdata_dict(dep, d)
+                                               subd = oe.packagedata.read_subpkgdata_dict(dep, d)
                                                pv = subd['PV']
                                                reppv = pv.replace('-', '+')
                                                ver = ver.replace(pv, reppv)
index 86f18a9e96a34405e30df3c5f70bf5411b3bafe0..bf051feea80c89f08420a541a5706d1d39ea84b8 100644 (file)
@@ -1,73 +1,13 @@
-def packaged(pkg, d):
-       return os.access(get_subpkgedata_fn(pkg, d) + '.packaged', os.R_OK)
-
-def read_pkgdatafile(fn):
-       pkgdata = {}
-
-       def decode(str):
-               import codecs
-               c = codecs.getdecoder("string_escape")
-               return c(str)[0]
-
-       if os.access(fn, os.R_OK):
-               import re
-               f = file(fn, 'r')
-               lines = f.readlines()
-               f.close()
-               r = re.compile("([^:]+):\s*(.*)")
-               for l in lines:
-                       m = r.match(l)
-                       if m:
-                               pkgdata[m.group(1)] = decode(m.group(2))
-
-       return pkgdata
-
-def get_subpkgedata_fn(pkg, d):
-       archs = bb.data.expand("${PACKAGE_ARCHS}", d).split(" ")
-       archs.reverse()
-       pkgdata = bb.data.expand('${TMPDIR}/pkgdata/', d)
-       targetdir = bb.data.expand('${TARGET_VENDOR}-${TARGET_OS}/runtime/', d)
-       for arch in archs:
-               fn = pkgdata + arch + targetdir + pkg
-               if os.path.exists(fn):
-                       return fn
-       return bb.data.expand('${PKGDATA_DIR}/runtime/%s' % pkg, d)
-
-def has_subpkgdata(pkg, d):
-       return os.access(get_subpkgedata_fn(pkg, d), os.R_OK)
-
-def read_subpkgdata(pkg, d):
-       return read_pkgdatafile(get_subpkgedata_fn(pkg, d))
-
-def has_pkgdata(pn, d):
-       fn = bb.data.expand('${PKGDATA_DIR}/%s' % pn, d)
-       return os.access(fn, os.R_OK)
-
-def read_pkgdata(pn, d):
-       fn = bb.data.expand('${PKGDATA_DIR}/%s' % pn, d)
-       return read_pkgdatafile(fn)
-
 python read_subpackage_metadata () {
-       data = read_pkgdata(bb.data.getVar('PN', d, 1), d)
+       import oe.packagedata
+
+       data = oe.packagedata.read_pkgdata(bb.data.getVar('PN', d, 1), d)
 
        for key in data.keys():
                bb.data.setVar(key, data[key], d)
 
        for pkg in bb.data.getVar('PACKAGES', d, 1).split():
-               sdata = read_subpkgdata(pkg, d)
+               sdata = oe.packagedata.read_subpkgdata(pkg, d)
                for key in sdata.keys():
                        bb.data.setVar(key, sdata[key], d)
 }
-
-
-#
-# Collapse FOO_pkg variables into FOO
-#
-def read_subpkgdata_dict(pkg, d):
-       ret = {}
-       subd = read_pkgdatafile(get_subpkgedata_fn(pkg, d))
-       for var in subd:
-               newvar = var.replace("_" + pkg, "")
-               ret[newvar] = subd[var]
-       return ret
-
diff --git a/meta/lib/oe/packagedata.py b/meta/lib/oe/packagedata.py
new file mode 100644 (file)
index 0000000..7f0a89d
--- /dev/null
@@ -0,0 +1,106 @@
+import os
+import bb.data
+import codecs
+
+def packaged(pkg, d):
+    return os.access(get_subpkgedata_fn(pkg, d) + '.packaged', os.R_OK)
+
+def read_pkgdatafile(fn):
+    pkgdata = {}
+
+    def decode(str):
+        c = codecs.getdecoder("string_escape")
+        return c(str)[0]
+
+    if os.access(fn, os.R_OK):
+        import re
+        f = file(fn, 'r')
+        lines = f.readlines()
+        f.close()
+        r = re.compile("([^:]+):\s*(.*)")
+        for l in lines:
+            m = r.match(l)
+            if m:
+                pkgdata[m.group(1)] = decode(m.group(2))
+
+    return pkgdata
+
+def get_subpkgedata_fn(pkg, d):
+    archs = bb.data.expand("${PACKAGE_ARCHS}", d).split(" ")
+    archs.reverse()
+    pkgdata = bb.data.expand('${TMPDIR}/pkgdata/', d)
+    targetdir = bb.data.expand('${TARGET_VENDOR}-${TARGET_OS}/runtime/', d)
+    for arch in archs:
+        fn = pkgdata + arch + targetdir + pkg
+        if os.path.exists(fn):
+            return fn
+    return bb.data.expand('${PKGDATA_DIR}/runtime/%s' % pkg, d)
+
+def has_subpkgdata(pkg, d):
+    return os.access(get_subpkgedata_fn(pkg, d), os.R_OK)
+
+def read_subpkgdata(pkg, d):
+    return read_pkgdatafile(get_subpkgedata_fn(pkg, d))
+
+def has_pkgdata(pn, d):
+    fn = bb.data.expand('${PKGDATA_DIR}/%s' % pn, d)
+    return os.access(fn, os.R_OK)
+
+def read_pkgdata(pn, d):
+    fn = bb.data.expand('${PKGDATA_DIR}/%s' % pn, d)
+    return read_pkgdatafile(fn)
+
+#
+# Collapse FOO_pkg variables into FOO
+#
+def read_subpkgdata_dict(pkg, d):
+    ret = {}
+    subd = read_pkgdatafile(get_subpkgedata_fn(pkg, d))
+    for var in subd:
+        newvar = var.replace("_" + pkg, "")
+        ret[newvar] = subd[var]
+    return ret
+
+def _pkgmap(d):
+    """Return a dictionary mapping package to recipe name."""
+
+    target_os = d.getVar("TARGET_OS", True)
+    target_vendor = d.getVar("TARGET_VENDOR", True)
+    basedir = os.path.dirname(d.getVar("PKGDATA_DIR", True))
+
+    dirs = ("%s%s-%s" % (arch, target_vendor, target_os)
+            for arch in d.getVar("PACKAGE_ARCHS", True).split())
+
+    pkgmap = {}
+    for pkgdatadir in (os.path.join(basedir, sys) for sys in dirs):
+        try:
+            files = os.listdir(pkgdatadir)
+        except OSError:
+            continue
+
+        for pn in filter(lambda f: not os.path.isdir(os.path.join(pkgdatadir, f)), files):
+            try:
+                pkgdata = read_pkgdatafile(os.path.join(pkgdatadir, pn))
+            except OSError:
+                continue
+
+            for pkg in pkgdata["PACKAGES"].split():
+                pkgmap[pkg] = pn
+
+    return pkgmap
+
+def pkgmap(d):
+    """Return a dictionary mapping package to recipe name.
+    Cache the mapping in the metadata"""
+
+    pkgmap_data = d.getVar("__pkgmap_data", False)
+    if pkgmap_data is None:
+        pkgmap_data = _pkgmap(d)
+        d.setVar("__pkgmap_data", pkgmap_data)
+
+    return pkgmap_data
+
+def recipename(pkg, d):
+    """Return the recipe name for the given binary package name."""
+
+    return pkgmap(d).get(pkg)