summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorPaul Eggleton <paul.eggleton@linux.intel.com>2015-02-06 11:02:44 +0000
committerRichard Purdie <richard.purdie@linuxfoundation.org>2015-02-14 08:40:36 +0000
commitf0af7471e688047c7bac5130457e5f9cc2fd5107 (patch)
tree100dca8902871f17aaa1ef733b8570b3b051333f /scripts
parent77411c775c4bf3fa7897985916c2d4a4af2dda47 (diff)
downloadopenembedded-core-f0af7471e688047c7bac5130457e5f9cc2fd5107.tar.gz
openembedded-core-f0af7471e688047c7bac5130457e5f9cc2fd5107.tar.bz2
openembedded-core-f0af7471e688047c7bac5130457e5f9cc2fd5107.zip
oe-pkgdata-util: allow reverse package name lookups
Add a -r/--reverse option to the lookup-pkg subcommand to enable looking up the recipe-space package name for one or more runtime package names. Also make this subcommand into a function that can be reused elsewhere. Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
Diffstat (limited to 'scripts')
-rwxr-xr-xscripts/oe-pkgdata-util54
1 files changed, 36 insertions, 18 deletions
diff --git a/scripts/oe-pkgdata-util b/scripts/oe-pkgdata-util
index 1603dfbc2e..91a1234ba4 100755
--- a/scripts/oe-pkgdata-util
+++ b/scripts/oe-pkgdata-util
@@ -27,7 +27,7 @@ import fnmatch
import re
import argparse
import logging
-from collections import defaultdict
+from collections import defaultdict, OrderedDict
scripts_path = os.path.dirname(os.path.realpath(__file__))
lib_path = scripts_path + '/lib'
@@ -184,30 +184,47 @@ def read_value(args):
else:
print(readvar(revlink, qvar))
+def lookup_pkglist(pkgs, pkgdata_dir, reverse):
+ if reverse:
+ mappings = OrderedDict()
+ for pkg in pkgs:
+ revlink = os.path.join(pkgdata_dir, "runtime-reverse", pkg)
+ logger.debug(revlink)
+ if os.path.exists(revlink):
+ mappings[pkg] = os.path.basename(os.readlink(revlink))
+ else:
+ mappings = defaultdict(list)
+ for pkg in pkgs:
+ pkgfile = os.path.join(pkgdata_dir, 'runtime', pkg)
+ if os.path.exists(pkgfile):
+ with open(pkgfile, 'r') as f:
+ for line in f:
+ fields = line.rstrip().split(': ')
+ if fields[0] == 'PKG_%s' % pkg:
+ mappings[pkg].append(fields[1])
+ break
+ return mappings
+
def lookup_pkg(args):
# Handle both multiple arguments and multiple values within an arg (old syntax)
pkgs = []
- for pkgitem in args.recipepkg:
+ for pkgitem in args.pkg:
pkgs.extend(pkgitem.split())
- mappings = defaultdict(list)
- for pkg in pkgs:
- pkgfile = os.path.join(args.pkgdata_dir, 'runtime', pkg)
- if os.path.exists(pkgfile):
- with open(pkgfile, 'r') as f:
- for line in f:
- fields = line.rstrip().split(': ')
- if fields[0] == 'PKG_%s' % pkg:
- mappings[pkg].append(fields[1])
- break
+ mappings = lookup_pkglist(pkgs, args.pkgdata_dir, args.reverse)
+
if len(mappings) < len(pkgs):
missing = list(set(pkgs) - set(mappings.keys()))
logger.error("The following packages could not be found: %s" % ', '.join(missing))
sys.exit(1)
- items = []
- for pkg in pkgs:
- items.extend(mappings.get(pkg, []))
+ if args.reverse:
+ items = mappings.values()
+ else:
+ items = []
+ for pkg in pkgs:
+ items.extend(mappings.get(pkg, []))
+
print('\n'.join(items))
def lookup_recipe(args):
@@ -265,9 +282,10 @@ def main():
subparsers = parser.add_subparsers(title='subcommands', metavar='<subcommand>')
parser_lookup_pkg = subparsers.add_parser('lookup-pkg',
- help='Translate recipe-space package names to runtime package names',
- description='Looks up the specified recipe-space package name(s) to see what the final runtime package name is (e.g. glibc becomes libc6)')
- parser_lookup_pkg.add_argument('recipepkg', nargs='+', help='Recipe-space package name to look up')
+ help='Translate between recipe-space package names and runtime package names',
+ description='Looks up the specified recipe-space package name(s) to see what the final runtime package name is (e.g. glibc becomes libc6), or with -r/--reverse looks up the other way.')
+ parser_lookup_pkg.add_argument('pkg', nargs='+', help='Package name to look up')
+ parser_lookup_pkg.add_argument('-r', '--reverse', help='Switch to looking up recipe-space package names from runtime package names', action='store_true')
parser_lookup_pkg.set_defaults(func=lookup_pkg)
parser_lookup_recipe = subparsers.add_parser('lookup-recipe',