diff options
author | Paul Eggleton <paul.eggleton@linux.intel.com> | 2015-02-06 11:02:44 +0000 |
---|---|---|
committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2015-02-14 08:41:01 +0000 |
commit | 4b330063791a4b616e2c7e17839b9c0b3ff89fd0 (patch) | |
tree | 31c1fcbcdf0c66b09cdef02c1c821d4bb5c659d7 | |
parent | 0f77efe9aec725285ac9d41b379325161a980644 (diff) | |
download | poky-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-x | scripts/oe-pkgdata-util | 54 |
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 | |||
27 | import re | 27 | import re |
28 | import argparse | 28 | import argparse |
29 | import logging | 29 | import logging |
30 | from collections import defaultdict | 30 | from collections import defaultdict, OrderedDict |
31 | 31 | ||
32 | scripts_path = os.path.dirname(os.path.realpath(__file__)) | 32 | scripts_path = os.path.dirname(os.path.realpath(__file__)) |
33 | lib_path = scripts_path + '/lib' | 33 | lib_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 | ||
187 | def 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 | |||
187 | def lookup_pkg(args): | 208 | def 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 | ||
213 | def lookup_recipe(args): | 230 | def 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', |