summaryrefslogtreecommitdiffstats
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:41:01 +0000
commit4b330063791a4b616e2c7e17839b9c0b3ff89fd0 (patch)
tree31c1fcbcdf0c66b09cdef02c1c821d4bb5c659d7
parent0f77efe9aec725285ac9d41b379325161a980644 (diff)
downloadpoky-4b330063791a4b616e2c7e17839b9c0b3ff89fd0.tar.gz
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>
-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
27import re 27import re
28import argparse 28import argparse
29import logging 29import logging
30from collections import defaultdict 30from collections import defaultdict, OrderedDict
31 31
32scripts_path = os.path.dirname(os.path.realpath(__file__)) 32scripts_path = os.path.dirname(os.path.realpath(__file__))
33lib_path = scripts_path + '/lib' 33lib_path = scripts_path + '/lib'
@@ -184,30 +184,47 @@ def read_value(args):
184 else: 184 else:
185 print(readvar(revlink, qvar)) 185 print(readvar(revlink, qvar))
186 186
187def lookup_pkglist(pkgs, pkgdata_dir, reverse):
188 if reverse:
189 mappings = OrderedDict()
190 for pkg in pkgs:
191 revlink = os.path.join(pkgdata_dir, "runtime-reverse", pkg)
192 logger.debug(revlink)
193 if os.path.exists(revlink):
194 mappings[pkg] = os.path.basename(os.readlink(revlink))
195 else:
196 mappings = defaultdict(list)
197 for pkg in pkgs:
198 pkgfile = os.path.join(pkgdata_dir, 'runtime', pkg)
199 if os.path.exists(pkgfile):
200 with open(pkgfile, 'r') as f:
201 for line in f:
202 fields = line.rstrip().split(': ')
203 if fields[0] == 'PKG_%s' % pkg:
204 mappings[pkg].append(fields[1])
205 break
206 return mappings
207
187def lookup_pkg(args): 208def lookup_pkg(args):
188 # Handle both multiple arguments and multiple values within an arg (old syntax) 209 # Handle both multiple arguments and multiple values within an arg (old syntax)
189 pkgs = [] 210 pkgs = []
190 for pkgitem in args.recipepkg: 211 for pkgitem in args.pkg:
191 pkgs.extend(pkgitem.split()) 212 pkgs.extend(pkgitem.split())
192 213
193 mappings = defaultdict(list) 214 mappings = lookup_pkglist(pkgs, args.pkgdata_dir, args.reverse)
194 for pkg in pkgs: 215
195 pkgfile = os.path.join(args.pkgdata_dir, 'runtime', pkg)
196 if os.path.exists(pkgfile):
197 with open(pkgfile, 'r') as f:
198 for line in f:
199 fields = line.rstrip().split(': ')
200 if fields[0] == 'PKG_%s' % pkg:
201 mappings[pkg].append(fields[1])
202 break
203 if len(mappings) < len(pkgs): 216 if len(mappings) < len(pkgs):
204 missing = list(set(pkgs) - set(mappings.keys())) 217 missing = list(set(pkgs) - set(mappings.keys()))
205 logger.error("The following packages could not be found: %s" % ', '.join(missing)) 218 logger.error("The following packages could not be found: %s" % ', '.join(missing))
206 sys.exit(1) 219 sys.exit(1)
207 220
208 items = [] 221 if args.reverse:
209 for pkg in pkgs: 222 items = mappings.values()
210 items.extend(mappings.get(pkg, [])) 223 else:
224 items = []
225 for pkg in pkgs:
226 items.extend(mappings.get(pkg, []))
227
211 print('\n'.join(items)) 228 print('\n'.join(items))
212 229
213def lookup_recipe(args): 230def lookup_recipe(args):
@@ -265,9 +282,10 @@ def main():
265 subparsers = parser.add_subparsers(title='subcommands', metavar='<subcommand>') 282 subparsers = parser.add_subparsers(title='subcommands', metavar='<subcommand>')
266 283
267 parser_lookup_pkg = subparsers.add_parser('lookup-pkg', 284 parser_lookup_pkg = subparsers.add_parser('lookup-pkg',
268 help='Translate recipe-space package names to runtime package names', 285 help='Translate between recipe-space package names and runtime package names',
269 description='Looks up the specified recipe-space package name(s) to see what the final runtime package name is (e.g. glibc becomes libc6)') 286 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.')
270 parser_lookup_pkg.add_argument('recipepkg', nargs='+', help='Recipe-space package name to look up') 287 parser_lookup_pkg.add_argument('pkg', nargs='+', help='Package name to look up')
288 parser_lookup_pkg.add_argument('-r', '--reverse', help='Switch to looking up recipe-space package names from runtime package names', action='store_true')
271 parser_lookup_pkg.set_defaults(func=lookup_pkg) 289 parser_lookup_pkg.set_defaults(func=lookup_pkg)
272 290
273 parser_lookup_recipe = subparsers.add_parser('lookup-recipe', 291 parser_lookup_recipe = subparsers.add_parser('lookup-recipe',