[OE-core] [PATCH v2 4/7] oe-pkgdata-util: allow reverse package name lookups
Paul Eggleton
paul.eggleton at linux.intel.com
Wed Feb 11 14:59:57 UTC 2015
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 at linux.intel.com>
---
scripts/oe-pkgdata-util | 54 ++++++++++++++++++++++++++++++++-----------------
1 file changed, 36 insertions(+), 18 deletions(-)
diff --git a/scripts/oe-pkgdata-util b/scripts/oe-pkgdata-util
index 1603dfb..91a1234 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',
--
1.9.3
More information about the Openembedded-core
mailing list