blob: 677effeef6e864f02113b3db090f0abbe8fd4ecb [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()
43 tinfoil.prepare(True)
44
45 tinfoil.logger.setLevel(logging.WARNING)
46 return tinfoil
47
48
49def glob(args):
50 # Handle both multiple arguments and multiple values within an arg (old syntax)
51 globs = []
52 for globitem in args.glob:
53 globs.extend(globitem.split())
54
55 if not os.path.exists(args.pkglistfile):
56 logger.error('Unable to find package list file %s' % args.pkglistfile)
57 sys.exit(1)
58
59 skipval = "-locale-|^locale-base-|-dev$|-doc$|-dbg$|-staticdev$|^kernel-module-"
60 if args.exclude:
61 skipval += "|" + args.exclude
62 skipregex = re.compile(skipval)
63
Patrick Williamsf1e5d692016-03-30 15:21:19 -050064 skippedpkgs = set()
Patrick Williamsc124f4f2015-09-15 14:41:29 -050065 mappedpkgs = set()
66 with open(args.pkglistfile, 'r') as f:
67 for line in f:
68 fields = line.rstrip().split()
69 if not fields:
70 continue
71 pkg = fields[0]
72 # We don't care about other args (used to need the package architecture but the
73 # new pkgdata structure avoids the need for that)
74
75 # Skip packages for which there is no point applying globs
76 if skipregex.search(pkg):
77 logger.debug("%s -> !!" % pkg)
Patrick Williamsf1e5d692016-03-30 15:21:19 -050078 skippedpkgs.add(pkg)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050079 continue
80
81 # Skip packages that already match the globs, so if e.g. a dev package
82 # is already installed and thus in the list, we don't process it any further
83 # Most of these will be caught by skipregex already, but just in case...
84 already = False
85 for g in globs:
86 if fnmatch.fnmatchcase(pkg, g):
87 already = True
88 break
89 if already:
Patrick Williamsf1e5d692016-03-30 15:21:19 -050090 skippedpkgs.add(pkg)
Patrick Williamsc124f4f2015-09-15 14:41:29 -050091 logger.debug("%s -> !" % pkg)
92 continue
93
94 # Define some functions
95 def revpkgdata(pkgn):
96 return os.path.join(args.pkgdata_dir, "runtime-reverse", pkgn)
97 def fwdpkgdata(pkgn):
98 return os.path.join(args.pkgdata_dir, "runtime", pkgn)
99 def readpn(pkgdata_file):
100 pn = ""
101 with open(pkgdata_file, 'r') as f:
102 for line in f:
103 if line.startswith("PN:"):
104 pn = line.split(': ')[1].rstrip()
105 return pn
106 def readrenamed(pkgdata_file):
107 renamed = ""
108 pn = os.path.basename(pkgdata_file)
109 with open(pkgdata_file, 'r') as f:
110 for line in f:
111 if line.startswith("PKG_%s:" % pn):
112 renamed = line.split(': ')[1].rstrip()
113 return renamed
114
115 # Main processing loop
116 for g in globs:
117 mappedpkg = ""
118 # First just try substitution (i.e. packagename -> packagename-dev)
119 newpkg = g.replace("*", pkg)
120 revlink = revpkgdata(newpkg)
121 if os.path.exists(revlink):
122 mappedpkg = os.path.basename(os.readlink(revlink))
123 fwdfile = fwdpkgdata(mappedpkg)
124 if os.path.exists(fwdfile):
125 mappedpkg = readrenamed(fwdfile)
126 if not os.path.exists(fwdfile + ".packaged"):
127 mappedpkg = ""
128 else:
129 revlink = revpkgdata(pkg)
130 if os.path.exists(revlink):
131 # Check if we can map after undoing the package renaming (by resolving the symlink)
132 origpkg = os.path.basename(os.readlink(revlink))
133 newpkg = g.replace("*", origpkg)
134 fwdfile = fwdpkgdata(newpkg)
135 if os.path.exists(fwdfile):
136 mappedpkg = readrenamed(fwdfile)
137 else:
138 # That didn't work, so now get the PN, substitute that, then map in the other direction
139 pn = readpn(revlink)
140 newpkg = g.replace("*", pn)
141 fwdfile = fwdpkgdata(newpkg)
142 if os.path.exists(fwdfile):
143 mappedpkg = readrenamed(fwdfile)
144 if not os.path.exists(fwdfile + ".packaged"):
145 mappedpkg = ""
146 else:
147 # Package doesn't even exist...
148 logger.debug("%s is not a valid package!" % (pkg))
149 break
150
151 if mappedpkg:
152 logger.debug("%s (%s) -> %s" % (pkg, g, mappedpkg))
153 mappedpkgs.add(mappedpkg)
154 else:
155 logger.debug("%s (%s) -> ?" % (pkg, g))
156
157 logger.debug("------")
158
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500159 print("\n".join(mappedpkgs - skippedpkgs))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500160
161def read_value(args):
162 # Handle both multiple arguments and multiple values within an arg (old syntax)
163 packages = []
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500164 if args.file:
165 with open(args.file, 'r') as f:
166 for line in f:
167 splitline = line.split()
168 if splitline:
169 packages.append(splitline[0])
170 else:
171 for pkgitem in args.pkg:
172 packages.extend(pkgitem.split())
173 if not packages:
174 logger.error("No packages specified")
175 sys.exit(1)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500176
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500177 def readvar(pkgdata_file, valuename, mappedpkg):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500178 val = ""
179 with open(pkgdata_file, 'r') as f:
180 for line in f:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500181 if (line.startswith(valuename + ":") or
182 line.startswith(valuename + "_" + mappedpkg + ":")):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500183 val = line.split(': ', 1)[1].rstrip()
184 return val
185
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500186 logger.debug("read-value('%s', '%s' '%s')" % (args.pkgdata_dir, args.valuename, packages))
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500187 for package in packages:
188 pkg_split = package.split('_')
189 pkg_name = pkg_split[0]
190 logger.debug("package: '%s'" % pkg_name)
191 revlink = os.path.join(args.pkgdata_dir, "runtime-reverse", pkg_name)
192 logger.debug(revlink)
193 if os.path.exists(revlink):
194 mappedpkg = os.path.basename(os.readlink(revlink))
195 qvar = args.valuename
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500196 value = readvar(revlink, qvar, mappedpkg)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500197 if qvar == "PKGSIZE":
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500198 # PKGSIZE is now in bytes, but we we want it in KB
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500199 pkgsize = (int(value) + 1024 // 2) // 1024
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500200 value = "%d" % pkgsize
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500201 if args.prefix_name:
202 print('%s %s' % (pkg_name, value))
203 else:
204 print(value)
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500205 else:
206 logger.debug("revlink %s does not exist", revlink)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500207
208def lookup_pkglist(pkgs, pkgdata_dir, reverse):
209 if reverse:
210 mappings = OrderedDict()
211 for pkg in pkgs:
212 revlink = os.path.join(pkgdata_dir, "runtime-reverse", pkg)
213 logger.debug(revlink)
214 if os.path.exists(revlink):
215 mappings[pkg] = os.path.basename(os.readlink(revlink))
216 else:
217 mappings = defaultdict(list)
218 for pkg in pkgs:
219 pkgfile = os.path.join(pkgdata_dir, 'runtime', pkg)
220 if os.path.exists(pkgfile):
221 with open(pkgfile, 'r') as f:
222 for line in f:
223 fields = line.rstrip().split(': ')
224 if fields[0] == 'PKG_%s' % pkg:
225 mappings[pkg].append(fields[1])
226 break
227 return mappings
228
229def lookup_pkg(args):
230 # Handle both multiple arguments and multiple values within an arg (old syntax)
231 pkgs = []
232 for pkgitem in args.pkg:
233 pkgs.extend(pkgitem.split())
234
235 mappings = lookup_pkglist(pkgs, args.pkgdata_dir, args.reverse)
236
237 if len(mappings) < len(pkgs):
238 missing = list(set(pkgs) - set(mappings.keys()))
239 logger.error("The following packages could not be found: %s" % ', '.join(missing))
240 sys.exit(1)
241
242 if args.reverse:
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600243 items = list(mappings.values())
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500244 else:
245 items = []
246 for pkg in pkgs:
247 items.extend(mappings.get(pkg, []))
248
249 print('\n'.join(items))
250
251def lookup_recipe(args):
252 # Handle both multiple arguments and multiple values within an arg (old syntax)
253 pkgs = []
254 for pkgitem in args.pkg:
255 pkgs.extend(pkgitem.split())
256
257 mappings = defaultdict(list)
258 for pkg in pkgs:
259 pkgfile = os.path.join(args.pkgdata_dir, 'runtime-reverse', pkg)
260 if os.path.exists(pkgfile):
261 with open(pkgfile, 'r') as f:
262 for line in f:
263 fields = line.rstrip().split(': ')
264 if fields[0] == 'PN':
265 mappings[pkg].append(fields[1])
266 break
267 if len(mappings) < len(pkgs):
268 missing = list(set(pkgs) - set(mappings.keys()))
269 logger.error("The following packages could not be found: %s" % ', '.join(missing))
270 sys.exit(1)
271
272 items = []
273 for pkg in pkgs:
274 items.extend(mappings.get(pkg, []))
275 print('\n'.join(items))
276
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600277def package_info(args):
278 # Handle both multiple arguments and multiple values within an arg (old syntax)
279 packages = []
280 if args.file:
281 with open(args.file, 'r') as f:
282 for line in f:
283 splitline = line.split()
284 if splitline:
285 packages.append(splitline[0])
286 else:
287 for pkgitem in args.pkg:
288 packages.extend(pkgitem.split())
289 if not packages:
290 logger.error("No packages specified")
291 sys.exit(1)
292
293 mappings = defaultdict(lambda: defaultdict(str))
294 for pkg in packages:
295 pkgfile = os.path.join(args.pkgdata_dir, 'runtime-reverse', pkg)
296 if os.path.exists(pkgfile):
297 with open(pkgfile, 'r') as f:
298 for line in f:
299 fields = line.rstrip().split(': ')
300 if fields[0].endswith("_" + pkg):
301 k = fields[0][:len(fields[0]) - len(pkg) - 1]
302 else:
303 k = fields[0]
304 v = fields[1] if len(fields) == 2 else ""
305 mappings[pkg][k] = v
306
307 if len(mappings) < len(packages):
308 missing = list(set(packages) - set(mappings.keys()))
309 logger.error("The following packages could not be found: %s" %
310 ', '.join(missing))
311 sys.exit(1)
312
313 items = []
314 for pkg in packages:
315 pkg_version = mappings[pkg]['PKGV']
316 if mappings[pkg]['PKGE']:
317 pkg_version = mappings[pkg]['PKGE'] + ":" + pkg_version
318 if mappings[pkg]['PKGR']:
319 pkg_version = pkg_version + "-" + mappings[pkg]['PKGR']
320 recipe = mappings[pkg]['PN']
321 recipe_version = mappings[pkg]['PV']
322 if mappings[pkg]['PE']:
323 recipe_version = mappings[pkg]['PE'] + ":" + recipe_version
324 if mappings[pkg]['PR']:
325 recipe_version = recipe_version + "-" + mappings[pkg]['PR']
326 pkg_size = mappings[pkg]['PKGSIZE']
327
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500328 line = "%s %s %s %s %s" % (pkg, pkg_version, recipe, recipe_version, pkg_size)
329
330 if args.extra:
331 for var in args.extra:
332 val = mappings[pkg][var].strip()
333 val = re.sub(r'\s+', ' ', val)
334 line += ' "%s"' % val
335
336 items.append(line)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600337 print('\n'.join(items))
338
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500339def get_recipe_pkgs(pkgdata_dir, recipe, unpackaged):
340 recipedatafile = os.path.join(pkgdata_dir, recipe)
341 if not os.path.exists(recipedatafile):
342 logger.error("Unable to find packaged recipe with name %s" % recipe)
343 sys.exit(1)
344 packages = []
345 with open(recipedatafile, 'r') as f:
346 for line in f:
347 fields = line.rstrip().split(': ')
348 if fields[0] == 'PACKAGES':
349 packages = fields[1].split()
350 break
351
352 if not unpackaged:
353 pkglist = []
354 for pkg in packages:
355 if os.path.exists(os.path.join(pkgdata_dir, 'runtime', '%s.packaged' % pkg)):
356 pkglist.append(pkg)
357 return pkglist
358 else:
359 return packages
360
361def list_pkgs(args):
362 found = False
363
364 def matchpkg(pkg):
365 if args.pkgspec:
366 matched = False
367 for pkgspec in args.pkgspec:
368 if fnmatch.fnmatchcase(pkg, pkgspec):
369 matched = True
370 break
371 if not matched:
372 return False
373 if not args.unpackaged:
374 if args.runtime:
375 revlink = os.path.join(args.pkgdata_dir, "runtime-reverse", pkg)
376 if os.path.exists(revlink):
377 # We're unlikely to get here if the package was not packaged, but just in case
378 # we add the symlinks for unpackaged files in the future
379 mappedpkg = os.path.basename(os.readlink(revlink))
380 if not os.path.exists(os.path.join(args.pkgdata_dir, 'runtime', '%s.packaged' % mappedpkg)):
381 return False
382 else:
383 return False
384 else:
385 if not os.path.exists(os.path.join(args.pkgdata_dir, 'runtime', '%s.packaged' % pkg)):
386 return False
387 return True
388
389 if args.recipe:
390 packages = get_recipe_pkgs(args.pkgdata_dir, args.recipe, args.unpackaged)
391
392 if args.runtime:
393 pkglist = []
394 runtime_pkgs = lookup_pkglist(packages, args.pkgdata_dir, False)
395 for rtpkgs in runtime_pkgs.values():
396 pkglist.extend(rtpkgs)
397 else:
398 pkglist = packages
399
400 for pkg in pkglist:
401 if matchpkg(pkg):
402 found = True
403 print("%s" % pkg)
404 else:
405 if args.runtime:
406 searchdir = 'runtime-reverse'
407 else:
408 searchdir = 'runtime'
409
410 for root, dirs, files in os.walk(os.path.join(args.pkgdata_dir, searchdir)):
411 for fn in files:
412 if fn.endswith('.packaged'):
413 continue
414 if matchpkg(fn):
415 found = True
416 print("%s" % fn)
417 if not found:
418 if args.pkgspec:
419 logger.error("Unable to find any package matching %s" % args.pkgspec)
420 else:
421 logger.error("No packages found")
422 sys.exit(1)
423
424def list_pkg_files(args):
425 import json
426
427 if args.recipe:
428 if args.pkg:
429 logger.error("list-pkg-files: If -p/--recipe is specified then a package name cannot be specified")
430 sys.exit(1)
431 recipepkglist = get_recipe_pkgs(args.pkgdata_dir, args.recipe, args.unpackaged)
432 if args.runtime:
433 pkglist = []
434 runtime_pkgs = lookup_pkglist(recipepkglist, args.pkgdata_dir, False)
435 for rtpkgs in runtime_pkgs.values():
436 pkglist.extend(rtpkgs)
437 else:
438 pkglist = recipepkglist
439 else:
440 if not args.pkg:
441 logger.error("list-pkg-files: If -p/--recipe is not specified then at least one package name must be specified")
442 sys.exit(1)
443 pkglist = args.pkg
444
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500445 for pkg in sorted(pkglist):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500446 print("%s:" % pkg)
447 if args.runtime:
448 pkgdatafile = os.path.join(args.pkgdata_dir, "runtime-reverse", pkg)
449 if not os.path.exists(pkgdatafile):
450 if args.recipe:
451 # This package was empty and thus never packaged, ignore
452 continue
453 logger.error("Unable to find any built runtime package named %s" % pkg)
454 sys.exit(1)
455 else:
456 pkgdatafile = os.path.join(args.pkgdata_dir, "runtime", pkg)
457 if not os.path.exists(pkgdatafile):
458 logger.error("Unable to find any built recipe-space package named %s" % pkg)
459 sys.exit(1)
460
461 with open(pkgdatafile, 'r') as f:
462 found = False
463 for line in f:
464 if line.startswith('FILES_INFO:'):
465 found = True
466 val = line.split(':', 1)[1].strip()
467 dictval = json.loads(val)
468 for fullpth in sorted(dictval):
469 print("\t%s" % fullpth)
470 break
471 if not found:
472 logger.error("Unable to find FILES_INFO entry in %s" % pkgdatafile)
473 sys.exit(1)
474
475def find_path(args):
476 import json
477
478 found = False
479 for root, dirs, files in os.walk(os.path.join(args.pkgdata_dir, 'runtime')):
480 for fn in files:
481 with open(os.path.join(root,fn)) as f:
482 for line in f:
483 if line.startswith('FILES_INFO:'):
484 val = line.split(':', 1)[1].strip()
485 dictval = json.loads(val)
486 for fullpth in dictval.keys():
487 if fnmatch.fnmatchcase(fullpth, args.targetpath):
488 found = True
489 print("%s: %s" % (fn, fullpth))
490 break
491 if not found:
492 logger.error("Unable to find any package producing path %s" % args.targetpath)
493 sys.exit(1)
494
495
496def main():
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500497 parser = argparse_oe.ArgumentParser(description="OpenEmbedded pkgdata tool - queries the pkgdata files written out during do_package",
498 epilog="Use %(prog)s <subcommand> --help to get help on a specific command")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500499 parser.add_argument('-d', '--debug', help='Enable debug output', action='store_true')
500 parser.add_argument('-p', '--pkgdata-dir', help='Path to pkgdata directory (determined automatically if not specified)')
501 subparsers = parser.add_subparsers(title='subcommands', metavar='<subcommand>')
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600502 subparsers.required = True
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500503
504 parser_lookup_pkg = subparsers.add_parser('lookup-pkg',
505 help='Translate between recipe-space package names and runtime package names',
506 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.')
507 parser_lookup_pkg.add_argument('pkg', nargs='+', help='Package name to look up')
508 parser_lookup_pkg.add_argument('-r', '--reverse', help='Switch to looking up recipe-space package names from runtime package names', action='store_true')
509 parser_lookup_pkg.set_defaults(func=lookup_pkg)
510
511 parser_list_pkgs = subparsers.add_parser('list-pkgs',
512 help='List packages',
513 description='Lists packages that have been built')
514 parser_list_pkgs.add_argument('pkgspec', nargs='*', help='Package name to search for (wildcards * ? allowed, use quotes to avoid shell expansion)')
515 parser_list_pkgs.add_argument('-r', '--runtime', help='Show runtime package names instead of recipe-space package names', action='store_true')
516 parser_list_pkgs.add_argument('-p', '--recipe', help='Limit to packages produced by the specified recipe')
517 parser_list_pkgs.add_argument('-u', '--unpackaged', help='Include unpackaged (i.e. empty) packages', action='store_true')
518 parser_list_pkgs.set_defaults(func=list_pkgs)
519
520 parser_list_pkg_files = subparsers.add_parser('list-pkg-files',
521 help='List files within a package',
522 description='Lists files included in one or more packages')
523 parser_list_pkg_files.add_argument('pkg', nargs='*', help='Package name to report on (if -p/--recipe is not specified)')
524 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')
525 parser_list_pkg_files.add_argument('-p', '--recipe', help='Report on all packages produced by the specified recipe')
526 parser_list_pkg_files.add_argument('-u', '--unpackaged', help='Include unpackaged (i.e. empty) packages (only useful with -p/--recipe)', action='store_true')
527 parser_list_pkg_files.set_defaults(func=list_pkg_files)
528
529 parser_lookup_recipe = subparsers.add_parser('lookup-recipe',
530 help='Find recipe producing one or more packages',
531 description='Looks up the specified runtime package(s) to see which recipe they were produced by')
532 parser_lookup_recipe.add_argument('pkg', nargs='+', help='Runtime package name to look up')
533 parser_lookup_recipe.set_defaults(func=lookup_recipe)
534
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600535 parser_package_info = subparsers.add_parser('package-info',
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500536 help='Show version, recipe and size information for one or more packages',
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600537 description='Looks up the specified runtime package(s) and display information')
538 parser_package_info.add_argument('pkg', nargs='*', help='Runtime package name to look up')
539 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 -0500540 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 -0600541 parser_package_info.set_defaults(func=package_info)
542
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500543 parser_find_path = subparsers.add_parser('find-path',
544 help='Find package providing a target path',
545 description='Finds the recipe-space package providing the specified target path')
546 parser_find_path.add_argument('targetpath', help='Path to find (wildcards * ? allowed, use quotes to avoid shell expansion)')
547 parser_find_path.set_defaults(func=find_path)
548
549 parser_read_value = subparsers.add_parser('read-value',
550 help='Read any pkgdata value for one or more packages',
551 description='Reads the named value from the pkgdata files for the specified packages')
552 parser_read_value.add_argument('valuename', help='Name of the value to look up')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500553 parser_read_value.add_argument('pkg', nargs='*', help='Runtime package name to look up')
554 parser_read_value.add_argument('-f', '--file', help='Read package names from the specified file (one per line, first field only)')
555 parser_read_value.add_argument('-n', '--prefix-name', help='Prefix output with package name', action='store_true')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500556 parser_read_value.set_defaults(func=read_value)
557
558 parser_glob = subparsers.add_parser('glob',
559 help='Expand package name glob expression',
560 description='Expands one or more glob expressions over the packages listed in pkglistfile')
561 parser_glob.add_argument('pkglistfile', help='File listing packages (one package name per line)')
562 parser_glob.add_argument('glob', nargs="+", help='Glob expression for package names, e.g. *-dev')
563 parser_glob.add_argument('-x', '--exclude', help='Exclude packages matching specified regex from the glob operation')
564 parser_glob.set_defaults(func=glob)
565
566
567 args = parser.parse_args()
568
569 if args.debug:
570 logger.setLevel(logging.DEBUG)
571
572 if not args.pkgdata_dir:
573 import scriptpath
574 bitbakepath = scriptpath.add_bitbake_lib_path()
575 if not bitbakepath:
576 logger.error("Unable to find bitbake by searching parent directory of this script or PATH")
577 sys.exit(1)
578 logger.debug('Found bitbake path: %s' % bitbakepath)
579 tinfoil = tinfoil_init()
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600580 try:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500581 args.pkgdata_dir = tinfoil.config_data.getVar('PKGDATA_DIR')
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600582 finally:
583 tinfoil.shutdown()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500584 logger.debug('Value of PKGDATA_DIR is "%s"' % args.pkgdata_dir)
585 if not args.pkgdata_dir:
586 logger.error('Unable to determine pkgdata directory from PKGDATA_DIR')
587 sys.exit(1)
588
589 if not os.path.exists(args.pkgdata_dir):
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500590 logger.error('Unable to find pkgdata directory %s' % args.pkgdata_dir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500591 sys.exit(1)
592
593 ret = args.func(args)
594
595 return ret
596
597
598if __name__ == "__main__":
599 main()