blob: c6fba56c89b7f22211e00fac11b4e45d322c62c7 [file] [log] [blame]
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001#!/usr/bin/env python3
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002
3# OpenEmbedded pkgdata utility
4#
5# Written by: Paul Eggleton <paul.eggleton@linux.intel.com>
6#
7# Copyright 2012-2015 Intel Corporation
8#
9# This program is free software; you can redistribute it and/or modify
10# it under the terms of the GNU General Public License version 2 as
11# published by the Free Software Foundation.
12#
13# This program is distributed in the hope that it will be useful,
14# but WITHOUT ANY WARRANTY; without even the implied warranty of
15# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16# GNU General Public License for more details.
17#
18# You should have received a copy of the GNU General Public License along
19# with this program; if not, write to the Free Software Foundation, Inc.,
20# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
21#
22
23import sys
24import os
25import os.path
26import fnmatch
27import re
28import argparse
29import logging
30from collections import defaultdict, OrderedDict
31
32scripts_path = os.path.dirname(os.path.realpath(__file__))
33lib_path = scripts_path + '/lib'
34sys.path = sys.path + [lib_path]
35import scriptutils
Patrick Williamsd8c66bc2016-06-20 12:57:21 -050036import argparse_oe
Patrick Williamsc124f4f2015-09-15 14:41:29 -050037logger = scriptutils.logger_create('pkgdatautil')
38
39def tinfoil_init():
40 import bb.tinfoil
41 import logging
42 tinfoil = bb.tinfoil.Tinfoil()
Patrick Williamsc124f4f2015-09-15 14:41:29 -050043 tinfoil.logger.setLevel(logging.WARNING)
Brad Bishopd7bf8c12018-02-25 22:55:05 -050044 tinfoil.prepare(True)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050045 return tinfoil
46
47
48def glob(args):
49 # Handle both multiple arguments and multiple values within an arg (old syntax)
50 globs = []
51 for globitem in args.glob:
52 globs.extend(globitem.split())
53
54 if not os.path.exists(args.pkglistfile):
55 logger.error('Unable to find package list file %s' % args.pkglistfile)
56 sys.exit(1)
57
58 skipval = "-locale-|^locale-base-|-dev$|-doc$|-dbg$|-staticdev$|^kernel-module-"
59 if args.exclude:
60 skipval += "|" + args.exclude
61 skipregex = re.compile(skipval)
62
Patrick Williamsf1e5d692016-03-30 15:21:19 -050063 skippedpkgs = set()
Patrick Williamsc124f4f2015-09-15 14:41:29 -050064 mappedpkgs = set()
65 with open(args.pkglistfile, 'r') as f:
66 for line in f:
67 fields = line.rstrip().split()
68 if not fields:
69 continue
70 pkg = fields[0]
71 # We don't care about other args (used to need the package architecture but the
72 # new pkgdata structure avoids the need for that)
73
74 # Skip packages for which there is no point applying globs
75 if skipregex.search(pkg):
76 logger.debug("%s -> !!" % pkg)
Patrick Williamsf1e5d692016-03-30 15:21:19 -050077 skippedpkgs.add(pkg)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050078 continue
79
80 # Skip packages that already match the globs, so if e.g. a dev package
81 # is already installed and thus in the list, we don't process it any further
82 # Most of these will be caught by skipregex already, but just in case...
83 already = False
84 for g in globs:
85 if fnmatch.fnmatchcase(pkg, g):
86 already = True
87 break
88 if already:
Patrick Williamsf1e5d692016-03-30 15:21:19 -050089 skippedpkgs.add(pkg)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050090 logger.debug("%s -> !" % pkg)
91 continue
92
93 # Define some functions
94 def revpkgdata(pkgn):
95 return os.path.join(args.pkgdata_dir, "runtime-reverse", pkgn)
96 def fwdpkgdata(pkgn):
97 return os.path.join(args.pkgdata_dir, "runtime", pkgn)
98 def readpn(pkgdata_file):
99 pn = ""
100 with open(pkgdata_file, 'r') as f:
101 for line in f:
102 if line.startswith("PN:"):
103 pn = line.split(': ')[1].rstrip()
104 return pn
105 def readrenamed(pkgdata_file):
106 renamed = ""
107 pn = os.path.basename(pkgdata_file)
108 with open(pkgdata_file, 'r') as f:
109 for line in f:
110 if line.startswith("PKG_%s:" % pn):
111 renamed = line.split(': ')[1].rstrip()
112 return renamed
113
114 # Main processing loop
115 for g in globs:
116 mappedpkg = ""
117 # First just try substitution (i.e. packagename -> packagename-dev)
118 newpkg = g.replace("*", pkg)
119 revlink = revpkgdata(newpkg)
120 if os.path.exists(revlink):
121 mappedpkg = os.path.basename(os.readlink(revlink))
122 fwdfile = fwdpkgdata(mappedpkg)
123 if os.path.exists(fwdfile):
124 mappedpkg = readrenamed(fwdfile)
125 if not os.path.exists(fwdfile + ".packaged"):
126 mappedpkg = ""
127 else:
128 revlink = revpkgdata(pkg)
129 if os.path.exists(revlink):
130 # Check if we can map after undoing the package renaming (by resolving the symlink)
131 origpkg = os.path.basename(os.readlink(revlink))
132 newpkg = g.replace("*", origpkg)
133 fwdfile = fwdpkgdata(newpkg)
134 if os.path.exists(fwdfile):
135 mappedpkg = readrenamed(fwdfile)
136 else:
137 # That didn't work, so now get the PN, substitute that, then map in the other direction
138 pn = readpn(revlink)
139 newpkg = g.replace("*", pn)
140 fwdfile = fwdpkgdata(newpkg)
141 if os.path.exists(fwdfile):
142 mappedpkg = readrenamed(fwdfile)
143 if not os.path.exists(fwdfile + ".packaged"):
144 mappedpkg = ""
145 else:
146 # Package doesn't even exist...
147 logger.debug("%s is not a valid package!" % (pkg))
148 break
149
150 if mappedpkg:
151 logger.debug("%s (%s) -> %s" % (pkg, g, mappedpkg))
152 mappedpkgs.add(mappedpkg)
153 else:
154 logger.debug("%s (%s) -> ?" % (pkg, g))
155
156 logger.debug("------")
157
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500158 print("\n".join(mappedpkgs - skippedpkgs))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500159
160def read_value(args):
161 # Handle both multiple arguments and multiple values within an arg (old syntax)
162 packages = []
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500163 if args.file:
164 with open(args.file, 'r') as f:
165 for line in f:
166 splitline = line.split()
167 if splitline:
168 packages.append(splitline[0])
169 else:
170 for pkgitem in args.pkg:
171 packages.extend(pkgitem.split())
172 if not packages:
173 logger.error("No packages specified")
174 sys.exit(1)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500175
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500176 def readvar(pkgdata_file, valuename, mappedpkg):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500177 val = ""
178 with open(pkgdata_file, 'r') as f:
179 for line in f:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500180 if (line.startswith(valuename + ":") or
181 line.startswith(valuename + "_" + mappedpkg + ":")):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500182 val = line.split(': ', 1)[1].rstrip()
183 return val
184
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500185 logger.debug("read-value('%s', '%s' '%s')" % (args.pkgdata_dir, args.valuename, packages))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500186 for package in packages:
187 pkg_split = package.split('_')
188 pkg_name = pkg_split[0]
189 logger.debug("package: '%s'" % pkg_name)
190 revlink = os.path.join(args.pkgdata_dir, "runtime-reverse", pkg_name)
191 logger.debug(revlink)
192 if os.path.exists(revlink):
193 mappedpkg = os.path.basename(os.readlink(revlink))
194 qvar = args.valuename
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500195 value = readvar(revlink, qvar, mappedpkg)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500196 if qvar == "PKGSIZE":
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500197 # PKGSIZE is now in bytes, but we we want it in KB
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500198 pkgsize = (int(value) + 1024 // 2) // 1024
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500199 value = "%d" % pkgsize
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500200 if args.unescape:
201 import codecs
202 # escape_decode() unescapes backslash encodings in byte streams
203 value = codecs.escape_decode(bytes(value, "utf-8"))[0].decode("utf-8")
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500204 if args.prefix_name:
205 print('%s %s' % (pkg_name, value))
206 else:
207 print(value)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500208 else:
209 logger.debug("revlink %s does not exist", revlink)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500210
211def lookup_pkglist(pkgs, pkgdata_dir, reverse):
212 if reverse:
213 mappings = OrderedDict()
214 for pkg in pkgs:
215 revlink = os.path.join(pkgdata_dir, "runtime-reverse", pkg)
216 logger.debug(revlink)
217 if os.path.exists(revlink):
218 mappings[pkg] = os.path.basename(os.readlink(revlink))
219 else:
220 mappings = defaultdict(list)
221 for pkg in pkgs:
222 pkgfile = os.path.join(pkgdata_dir, 'runtime', pkg)
223 if os.path.exists(pkgfile):
224 with open(pkgfile, 'r') as f:
225 for line in f:
226 fields = line.rstrip().split(': ')
227 if fields[0] == 'PKG_%s' % pkg:
228 mappings[pkg].append(fields[1])
229 break
230 return mappings
231
232def lookup_pkg(args):
233 # Handle both multiple arguments and multiple values within an arg (old syntax)
234 pkgs = []
235 for pkgitem in args.pkg:
236 pkgs.extend(pkgitem.split())
237
238 mappings = lookup_pkglist(pkgs, args.pkgdata_dir, args.reverse)
239
240 if len(mappings) < len(pkgs):
241 missing = list(set(pkgs) - set(mappings.keys()))
242 logger.error("The following packages could not be found: %s" % ', '.join(missing))
243 sys.exit(1)
244
245 if args.reverse:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600246 items = list(mappings.values())
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500247 else:
248 items = []
249 for pkg in pkgs:
250 items.extend(mappings.get(pkg, []))
251
252 print('\n'.join(items))
253
254def lookup_recipe(args):
255 # Handle both multiple arguments and multiple values within an arg (old syntax)
256 pkgs = []
257 for pkgitem in args.pkg:
258 pkgs.extend(pkgitem.split())
259
260 mappings = defaultdict(list)
261 for pkg in pkgs:
262 pkgfile = os.path.join(args.pkgdata_dir, 'runtime-reverse', pkg)
263 if os.path.exists(pkgfile):
264 with open(pkgfile, 'r') as f:
265 for line in f:
266 fields = line.rstrip().split(': ')
267 if fields[0] == 'PN':
268 mappings[pkg].append(fields[1])
269 break
270 if len(mappings) < len(pkgs):
271 missing = list(set(pkgs) - set(mappings.keys()))
272 logger.error("The following packages could not be found: %s" % ', '.join(missing))
273 sys.exit(1)
274
275 items = []
276 for pkg in pkgs:
277 items.extend(mappings.get(pkg, []))
278 print('\n'.join(items))
279
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600280def package_info(args):
281 # Handle both multiple arguments and multiple values within an arg (old syntax)
282 packages = []
283 if args.file:
284 with open(args.file, 'r') as f:
285 for line in f:
286 splitline = line.split()
287 if splitline:
288 packages.append(splitline[0])
289 else:
290 for pkgitem in args.pkg:
291 packages.extend(pkgitem.split())
292 if not packages:
293 logger.error("No packages specified")
294 sys.exit(1)
295
296 mappings = defaultdict(lambda: defaultdict(str))
297 for pkg in packages:
298 pkgfile = os.path.join(args.pkgdata_dir, 'runtime-reverse', pkg)
299 if os.path.exists(pkgfile):
300 with open(pkgfile, 'r') as f:
301 for line in f:
302 fields = line.rstrip().split(': ')
303 if fields[0].endswith("_" + pkg):
304 k = fields[0][:len(fields[0]) - len(pkg) - 1]
305 else:
306 k = fields[0]
307 v = fields[1] if len(fields) == 2 else ""
308 mappings[pkg][k] = v
309
310 if len(mappings) < len(packages):
311 missing = list(set(packages) - set(mappings.keys()))
312 logger.error("The following packages could not be found: %s" %
313 ', '.join(missing))
314 sys.exit(1)
315
316 items = []
317 for pkg in packages:
318 pkg_version = mappings[pkg]['PKGV']
319 if mappings[pkg]['PKGE']:
320 pkg_version = mappings[pkg]['PKGE'] + ":" + pkg_version
321 if mappings[pkg]['PKGR']:
322 pkg_version = pkg_version + "-" + mappings[pkg]['PKGR']
323 recipe = mappings[pkg]['PN']
324 recipe_version = mappings[pkg]['PV']
325 if mappings[pkg]['PE']:
326 recipe_version = mappings[pkg]['PE'] + ":" + recipe_version
327 if mappings[pkg]['PR']:
328 recipe_version = recipe_version + "-" + mappings[pkg]['PR']
329 pkg_size = mappings[pkg]['PKGSIZE']
330
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500331 line = "%s %s %s %s %s" % (pkg, pkg_version, recipe, recipe_version, pkg_size)
332
333 if args.extra:
334 for var in args.extra:
335 val = mappings[pkg][var].strip()
336 val = re.sub(r'\s+', ' ', val)
337 line += ' "%s"' % val
338
339 items.append(line)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600340 print('\n'.join(items))
341
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500342def get_recipe_pkgs(pkgdata_dir, recipe, unpackaged):
343 recipedatafile = os.path.join(pkgdata_dir, recipe)
344 if not os.path.exists(recipedatafile):
345 logger.error("Unable to find packaged recipe with name %s" % recipe)
346 sys.exit(1)
347 packages = []
348 with open(recipedatafile, 'r') as f:
349 for line in f:
350 fields = line.rstrip().split(': ')
351 if fields[0] == 'PACKAGES':
352 packages = fields[1].split()
353 break
354
355 if not unpackaged:
356 pkglist = []
357 for pkg in packages:
358 if os.path.exists(os.path.join(pkgdata_dir, 'runtime', '%s.packaged' % pkg)):
359 pkglist.append(pkg)
360 return pkglist
361 else:
362 return packages
363
364def list_pkgs(args):
365 found = False
366
367 def matchpkg(pkg):
368 if args.pkgspec:
369 matched = False
370 for pkgspec in args.pkgspec:
371 if fnmatch.fnmatchcase(pkg, pkgspec):
372 matched = True
373 break
374 if not matched:
375 return False
376 if not args.unpackaged:
377 if args.runtime:
378 revlink = os.path.join(args.pkgdata_dir, "runtime-reverse", pkg)
379 if os.path.exists(revlink):
380 # We're unlikely to get here if the package was not packaged, but just in case
381 # we add the symlinks for unpackaged files in the future
382 mappedpkg = os.path.basename(os.readlink(revlink))
383 if not os.path.exists(os.path.join(args.pkgdata_dir, 'runtime', '%s.packaged' % mappedpkg)):
384 return False
385 else:
386 return False
387 else:
388 if not os.path.exists(os.path.join(args.pkgdata_dir, 'runtime', '%s.packaged' % pkg)):
389 return False
390 return True
391
392 if args.recipe:
393 packages = get_recipe_pkgs(args.pkgdata_dir, args.recipe, args.unpackaged)
394
395 if args.runtime:
396 pkglist = []
397 runtime_pkgs = lookup_pkglist(packages, args.pkgdata_dir, False)
398 for rtpkgs in runtime_pkgs.values():
399 pkglist.extend(rtpkgs)
400 else:
401 pkglist = packages
402
403 for pkg in pkglist:
404 if matchpkg(pkg):
405 found = True
406 print("%s" % pkg)
407 else:
408 if args.runtime:
409 searchdir = 'runtime-reverse'
410 else:
411 searchdir = 'runtime'
412
413 for root, dirs, files in os.walk(os.path.join(args.pkgdata_dir, searchdir)):
414 for fn in files:
415 if fn.endswith('.packaged'):
416 continue
417 if matchpkg(fn):
418 found = True
419 print("%s" % fn)
420 if not found:
421 if args.pkgspec:
422 logger.error("Unable to find any package matching %s" % args.pkgspec)
423 else:
424 logger.error("No packages found")
425 sys.exit(1)
426
427def list_pkg_files(args):
428 import json
429
430 if args.recipe:
431 if args.pkg:
432 logger.error("list-pkg-files: If -p/--recipe is specified then a package name cannot be specified")
433 sys.exit(1)
434 recipepkglist = get_recipe_pkgs(args.pkgdata_dir, args.recipe, args.unpackaged)
435 if args.runtime:
436 pkglist = []
437 runtime_pkgs = lookup_pkglist(recipepkglist, args.pkgdata_dir, False)
438 for rtpkgs in runtime_pkgs.values():
439 pkglist.extend(rtpkgs)
440 else:
441 pkglist = recipepkglist
442 else:
443 if not args.pkg:
444 logger.error("list-pkg-files: If -p/--recipe is not specified then at least one package name must be specified")
445 sys.exit(1)
446 pkglist = args.pkg
447
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500448 for pkg in sorted(pkglist):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500449 print("%s:" % pkg)
450 if args.runtime:
451 pkgdatafile = os.path.join(args.pkgdata_dir, "runtime-reverse", pkg)
452 if not os.path.exists(pkgdatafile):
453 if args.recipe:
454 # This package was empty and thus never packaged, ignore
455 continue
456 logger.error("Unable to find any built runtime package named %s" % pkg)
457 sys.exit(1)
458 else:
459 pkgdatafile = os.path.join(args.pkgdata_dir, "runtime", pkg)
460 if not os.path.exists(pkgdatafile):
461 logger.error("Unable to find any built recipe-space package named %s" % pkg)
462 sys.exit(1)
463
464 with open(pkgdatafile, 'r') as f:
465 found = False
466 for line in f:
467 if line.startswith('FILES_INFO:'):
468 found = True
469 val = line.split(':', 1)[1].strip()
470 dictval = json.loads(val)
471 for fullpth in sorted(dictval):
472 print("\t%s" % fullpth)
473 break
474 if not found:
475 logger.error("Unable to find FILES_INFO entry in %s" % pkgdatafile)
476 sys.exit(1)
477
478def find_path(args):
479 import json
480
481 found = False
482 for root, dirs, files in os.walk(os.path.join(args.pkgdata_dir, 'runtime')):
483 for fn in files:
484 with open(os.path.join(root,fn)) as f:
485 for line in f:
486 if line.startswith('FILES_INFO:'):
487 val = line.split(':', 1)[1].strip()
488 dictval = json.loads(val)
489 for fullpth in dictval.keys():
490 if fnmatch.fnmatchcase(fullpth, args.targetpath):
491 found = True
492 print("%s: %s" % (fn, fullpth))
493 break
494 if not found:
495 logger.error("Unable to find any package producing path %s" % args.targetpath)
496 sys.exit(1)
497
498
499def main():
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500500 parser = argparse_oe.ArgumentParser(description="OpenEmbedded pkgdata tool - queries the pkgdata files written out during do_package",
501 epilog="Use %(prog)s <subcommand> --help to get help on a specific command")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500502 parser.add_argument('-d', '--debug', help='Enable debug output', action='store_true')
503 parser.add_argument('-p', '--pkgdata-dir', help='Path to pkgdata directory (determined automatically if not specified)')
504 subparsers = parser.add_subparsers(title='subcommands', metavar='<subcommand>')
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600505 subparsers.required = True
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500506
507 parser_lookup_pkg = subparsers.add_parser('lookup-pkg',
508 help='Translate between recipe-space package names and runtime package names',
509 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.')
510 parser_lookup_pkg.add_argument('pkg', nargs='+', help='Package name to look up')
511 parser_lookup_pkg.add_argument('-r', '--reverse', help='Switch to looking up recipe-space package names from runtime package names', action='store_true')
512 parser_lookup_pkg.set_defaults(func=lookup_pkg)
513
514 parser_list_pkgs = subparsers.add_parser('list-pkgs',
515 help='List packages',
516 description='Lists packages that have been built')
517 parser_list_pkgs.add_argument('pkgspec', nargs='*', help='Package name to search for (wildcards * ? allowed, use quotes to avoid shell expansion)')
518 parser_list_pkgs.add_argument('-r', '--runtime', help='Show runtime package names instead of recipe-space package names', action='store_true')
519 parser_list_pkgs.add_argument('-p', '--recipe', help='Limit to packages produced by the specified recipe')
520 parser_list_pkgs.add_argument('-u', '--unpackaged', help='Include unpackaged (i.e. empty) packages', action='store_true')
521 parser_list_pkgs.set_defaults(func=list_pkgs)
522
523 parser_list_pkg_files = subparsers.add_parser('list-pkg-files',
524 help='List files within a package',
525 description='Lists files included in one or more packages')
526 parser_list_pkg_files.add_argument('pkg', nargs='*', help='Package name to report on (if -p/--recipe is not specified)')
527 parser_list_pkg_files.add_argument('-r', '--runtime', help='Specified package(s) are runtime package names instead of recipe-space package names', action='store_true')
528 parser_list_pkg_files.add_argument('-p', '--recipe', help='Report on all packages produced by the specified recipe')
529 parser_list_pkg_files.add_argument('-u', '--unpackaged', help='Include unpackaged (i.e. empty) packages (only useful with -p/--recipe)', action='store_true')
530 parser_list_pkg_files.set_defaults(func=list_pkg_files)
531
532 parser_lookup_recipe = subparsers.add_parser('lookup-recipe',
533 help='Find recipe producing one or more packages',
534 description='Looks up the specified runtime package(s) to see which recipe they were produced by')
535 parser_lookup_recipe.add_argument('pkg', nargs='+', help='Runtime package name to look up')
536 parser_lookup_recipe.set_defaults(func=lookup_recipe)
537
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600538 parser_package_info = subparsers.add_parser('package-info',
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500539 help='Show version, recipe and size information for one or more packages',
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600540 description='Looks up the specified runtime package(s) and display information')
541 parser_package_info.add_argument('pkg', nargs='*', help='Runtime package name to look up')
542 parser_package_info.add_argument('-f', '--file', help='Read package names from the specified file (one per line, first field only)')
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500543 parser_package_info.add_argument('-e', '--extra', help='Extra variables to display, e.g., LICENSE (can be specified multiple times)', action='append')
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600544 parser_package_info.set_defaults(func=package_info)
545
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500546 parser_find_path = subparsers.add_parser('find-path',
547 help='Find package providing a target path',
548 description='Finds the recipe-space package providing the specified target path')
549 parser_find_path.add_argument('targetpath', help='Path to find (wildcards * ? allowed, use quotes to avoid shell expansion)')
550 parser_find_path.set_defaults(func=find_path)
551
552 parser_read_value = subparsers.add_parser('read-value',
553 help='Read any pkgdata value for one or more packages',
554 description='Reads the named value from the pkgdata files for the specified packages')
555 parser_read_value.add_argument('valuename', help='Name of the value to look up')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500556 parser_read_value.add_argument('pkg', nargs='*', help='Runtime package name to look up')
557 parser_read_value.add_argument('-f', '--file', help='Read package names from the specified file (one per line, first field only)')
558 parser_read_value.add_argument('-n', '--prefix-name', help='Prefix output with package name', action='store_true')
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500559 parser_read_value.add_argument('-u', '--unescape', help='Expand escapes such as \\n', action='store_true')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500560 parser_read_value.set_defaults(func=read_value)
561
562 parser_glob = subparsers.add_parser('glob',
563 help='Expand package name glob expression',
564 description='Expands one or more glob expressions over the packages listed in pkglistfile')
565 parser_glob.add_argument('pkglistfile', help='File listing packages (one package name per line)')
566 parser_glob.add_argument('glob', nargs="+", help='Glob expression for package names, e.g. *-dev')
567 parser_glob.add_argument('-x', '--exclude', help='Exclude packages matching specified regex from the glob operation')
568 parser_glob.set_defaults(func=glob)
569
570
571 args = parser.parse_args()
572
573 if args.debug:
574 logger.setLevel(logging.DEBUG)
575
576 if not args.pkgdata_dir:
577 import scriptpath
578 bitbakepath = scriptpath.add_bitbake_lib_path()
579 if not bitbakepath:
580 logger.error("Unable to find bitbake by searching parent directory of this script or PATH")
581 sys.exit(1)
582 logger.debug('Found bitbake path: %s' % bitbakepath)
583 tinfoil = tinfoil_init()
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600584 try:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500585 args.pkgdata_dir = tinfoil.config_data.getVar('PKGDATA_DIR')
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600586 finally:
587 tinfoil.shutdown()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500588 logger.debug('Value of PKGDATA_DIR is "%s"' % args.pkgdata_dir)
589 if not args.pkgdata_dir:
590 logger.error('Unable to determine pkgdata directory from PKGDATA_DIR')
591 sys.exit(1)
592
593 if not os.path.exists(args.pkgdata_dir):
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500594 logger.error('Unable to find pkgdata directory %s' % args.pkgdata_dir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500595 sys.exit(1)
596
597 ret = args.func(args)
598
599 return ret
600
601
602if __name__ == "__main__":
603 main()