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. (From OE-Core rev: f0af7471e688047c7bac5130457e5f9cc2fd5107) Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
parent
0f77efe9ae
commit
4b33006379
|
@ -27,7 +27,7 @@ import fnmatch
|
||||||
import re
|
import re
|
||||||
import argparse
|
import argparse
|
||||||
import logging
|
import logging
|
||||||
from collections import defaultdict
|
from collections import defaultdict, OrderedDict
|
||||||
|
|
||||||
scripts_path = os.path.dirname(os.path.realpath(__file__))
|
scripts_path = os.path.dirname(os.path.realpath(__file__))
|
||||||
lib_path = scripts_path + '/lib'
|
lib_path = scripts_path + '/lib'
|
||||||
|
@ -184,30 +184,47 @@ def read_value(args):
|
||||||
else:
|
else:
|
||||||
print(readvar(revlink, qvar))
|
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):
|
def lookup_pkg(args):
|
||||||
# Handle both multiple arguments and multiple values within an arg (old syntax)
|
# Handle both multiple arguments and multiple values within an arg (old syntax)
|
||||||
pkgs = []
|
pkgs = []
|
||||||
for pkgitem in args.recipepkg:
|
for pkgitem in args.pkg:
|
||||||
pkgs.extend(pkgitem.split())
|
pkgs.extend(pkgitem.split())
|
||||||
|
|
||||||
mappings = defaultdict(list)
|
mappings = lookup_pkglist(pkgs, args.pkgdata_dir, args.reverse)
|
||||||
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
|
|
||||||
if len(mappings) < len(pkgs):
|
if len(mappings) < len(pkgs):
|
||||||
missing = list(set(pkgs) - set(mappings.keys()))
|
missing = list(set(pkgs) - set(mappings.keys()))
|
||||||
logger.error("The following packages could not be found: %s" % ', '.join(missing))
|
logger.error("The following packages could not be found: %s" % ', '.join(missing))
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
items = []
|
if args.reverse:
|
||||||
for pkg in pkgs:
|
items = mappings.values()
|
||||||
items.extend(mappings.get(pkg, []))
|
else:
|
||||||
|
items = []
|
||||||
|
for pkg in pkgs:
|
||||||
|
items.extend(mappings.get(pkg, []))
|
||||||
|
|
||||||
print('\n'.join(items))
|
print('\n'.join(items))
|
||||||
|
|
||||||
def lookup_recipe(args):
|
def lookup_recipe(args):
|
||||||
|
@ -265,9 +282,10 @@ def main():
|
||||||
subparsers = parser.add_subparsers(title='subcommands', metavar='<subcommand>')
|
subparsers = parser.add_subparsers(title='subcommands', metavar='<subcommand>')
|
||||||
|
|
||||||
parser_lookup_pkg = subparsers.add_parser('lookup-pkg',
|
parser_lookup_pkg = subparsers.add_parser('lookup-pkg',
|
||||||
help='Translate recipe-space package names to runtime package names',
|
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)')
|
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('recipepkg', nargs='+', help='Recipe-space package name to look up')
|
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_pkg.set_defaults(func=lookup_pkg)
|
||||||
|
|
||||||
parser_lookup_recipe = subparsers.add_parser('lookup-recipe',
|
parser_lookup_recipe = subparsers.add_parser('lookup-recipe',
|
||||||
|
|
Loading…
Reference in New Issue