blob: aea8a5751662086003ee104f5e4c4cffad8978d7 [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):
Brad Bishop316dfdd2018-06-25 12:45:53 -0400255 def parse_pkgdatafile(pkgdatafile):
256 with open(pkgdatafile, 'r') as f:
257 found = False
258 for line in f:
259 if line.startswith('PN:'):
260 print("%s" % line.split(':', 1)[1].strip())
261 found = True
262 break
263 if not found:
264 logger.error("Unable to find PN entry in %s" % pkgdatafile)
265 sys.exit(1)
266
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500267 # Handle both multiple arguments and multiple values within an arg (old syntax)
268 pkgs = []
269 for pkgitem in args.pkg:
270 pkgs.extend(pkgitem.split())
271
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500272 for pkg in pkgs:
Brad Bishop316dfdd2018-06-25 12:45:53 -0400273 providepkgpath = os.path.join(args.pkgdata_dir, "runtime-rprovides", pkg)
274 if os.path.exists(providepkgpath):
275 for f in os.listdir(providepkgpath):
276 if f != pkg:
277 print("%s is in the RPROVIDES of %s:" % (pkg, f))
278 pkgdatafile = os.path.join(args.pkgdata_dir, "runtime", f)
279 parse_pkgdatafile(pkgdatafile)
280 break
281 pkgdatafile = os.path.join(args.pkgdata_dir, 'runtime-reverse', pkg)
282 if not os.path.exists(pkgdatafile):
283 logger.error("The following packages could not be found: %s" % pkg)
284 sys.exit(1)
285 parse_pkgdatafile(pkgdatafile)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500286
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600287def package_info(args):
Brad Bishop316dfdd2018-06-25 12:45:53 -0400288 def parse_pkgdatafile(pkgdatafile):
289 with open(pkgdatafile, 'r') as f:
290 pkge = ''
291 pkgr = ''
292 pe = ''
293 pr = ''
294 for line in f:
295 if line.startswith('PKGV:'):
296 pkg_version = line.split(':', 1)[1].strip()
297 elif line.startswith('PKGE:'):
298 pkge = line.split(':', 1)[1].strip()
299 elif line.startswith('PKGR:'):
300 pkgr = line.split(':', 1)[1].strip()
301 elif line.startswith('PN:'):
302 recipe = line.split(':', 1)[1].strip()
303 elif line.startswith('PV:'):
304 recipe_version = line.split(':', 1)[1].strip()
305 elif line.startswith('PE:'):
306 pe = line.split(':', 1)[1].strip()
307 elif line.startswith('PR:'):
308 pr = line.split(':', 1)[1].strip()
309 elif line.startswith('PKGSIZE'):
310 pkg_size = line.split(':', 1)[1].strip()
311 if pkge:
312 pkg_version = pkge + ":" + pkg_version
313 if pkgr:
314 pkg_version = pkg_version + "-" + pkgr
315 if pe:
316 recipe_version = pe + ":" + recipe_version
317 if pr:
318 recipe_version = recipe_version + "-" + pr
319 print("%s %s %s %s %s" % (pkg, pkg_version, recipe, recipe_version, pkg_size))
320
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600321 # Handle both multiple arguments and multiple values within an arg (old syntax)
322 packages = []
323 if args.file:
324 with open(args.file, 'r') as f:
325 for line in f:
326 splitline = line.split()
327 if splitline:
328 packages.append(splitline[0])
329 else:
330 for pkgitem in args.pkg:
331 packages.extend(pkgitem.split())
332 if not packages:
333 logger.error("No packages specified")
334 sys.exit(1)
335
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600336 for pkg in packages:
Brad Bishop316dfdd2018-06-25 12:45:53 -0400337 providepkgpath = os.path.join(args.pkgdata_dir, "runtime-rprovides", pkg)
338 if os.path.exists(providepkgpath):
339 for f in os.listdir(providepkgpath):
340 if f != pkg:
341 print("%s is in the RPROVIDES of %s:" % (pkg, f))
342 pkgdatafile = os.path.join(args.pkgdata_dir, "runtime", f)
343 parse_pkgdatafile(pkgdatafile)
344 break
345 pkgdatafile = os.path.join(args.pkgdata_dir, "runtime-reverse", pkg)
346 if not os.path.exists(pkgdatafile):
347 logger.error("Unable to find any built runtime package named %s" % pkg)
348 sys.exit(1)
349 parse_pkgdatafile(pkgdatafile)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600350
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500351def get_recipe_pkgs(pkgdata_dir, recipe, unpackaged):
352 recipedatafile = os.path.join(pkgdata_dir, recipe)
353 if not os.path.exists(recipedatafile):
354 logger.error("Unable to find packaged recipe with name %s" % recipe)
355 sys.exit(1)
356 packages = []
357 with open(recipedatafile, 'r') as f:
358 for line in f:
359 fields = line.rstrip().split(': ')
360 if fields[0] == 'PACKAGES':
361 packages = fields[1].split()
362 break
363
364 if not unpackaged:
365 pkglist = []
366 for pkg in packages:
367 if os.path.exists(os.path.join(pkgdata_dir, 'runtime', '%s.packaged' % pkg)):
368 pkglist.append(pkg)
369 return pkglist
370 else:
371 return packages
372
373def list_pkgs(args):
374 found = False
375
376 def matchpkg(pkg):
377 if args.pkgspec:
378 matched = False
379 for pkgspec in args.pkgspec:
380 if fnmatch.fnmatchcase(pkg, pkgspec):
381 matched = True
382 break
383 if not matched:
384 return False
385 if not args.unpackaged:
386 if args.runtime:
387 revlink = os.path.join(args.pkgdata_dir, "runtime-reverse", pkg)
388 if os.path.exists(revlink):
389 # We're unlikely to get here if the package was not packaged, but just in case
390 # we add the symlinks for unpackaged files in the future
391 mappedpkg = os.path.basename(os.readlink(revlink))
392 if not os.path.exists(os.path.join(args.pkgdata_dir, 'runtime', '%s.packaged' % mappedpkg)):
393 return False
394 else:
395 return False
396 else:
397 if not os.path.exists(os.path.join(args.pkgdata_dir, 'runtime', '%s.packaged' % pkg)):
398 return False
399 return True
400
401 if args.recipe:
402 packages = get_recipe_pkgs(args.pkgdata_dir, args.recipe, args.unpackaged)
403
404 if args.runtime:
405 pkglist = []
406 runtime_pkgs = lookup_pkglist(packages, args.pkgdata_dir, False)
407 for rtpkgs in runtime_pkgs.values():
408 pkglist.extend(rtpkgs)
409 else:
410 pkglist = packages
411
412 for pkg in pkglist:
413 if matchpkg(pkg):
414 found = True
415 print("%s" % pkg)
416 else:
417 if args.runtime:
418 searchdir = 'runtime-reverse'
419 else:
420 searchdir = 'runtime'
421
422 for root, dirs, files in os.walk(os.path.join(args.pkgdata_dir, searchdir)):
423 for fn in files:
424 if fn.endswith('.packaged'):
425 continue
426 if matchpkg(fn):
427 found = True
428 print("%s" % fn)
429 if not found:
430 if args.pkgspec:
431 logger.error("Unable to find any package matching %s" % args.pkgspec)
432 else:
433 logger.error("No packages found")
434 sys.exit(1)
435
436def list_pkg_files(args):
437 import json
Brad Bishop316dfdd2018-06-25 12:45:53 -0400438 def parse_pkgdatafile(pkgdatafile, long=False):
439 with open(pkgdatafile, 'r') as f:
440 found = False
441 for line in f:
442 if line.startswith('FILES_INFO:'):
443 found = True
444 val = line.split(':', 1)[1].strip()
445 dictval = json.loads(val)
446 if long:
447 width = max(map(len, dictval), default=0)
448 for fullpth in sorted(dictval):
449 print("\t{:{width}}\t{}".format(fullpth, dictval[fullpth], width=width))
450 else:
451 for fullpth in sorted(dictval):
452 print("\t%s" % fullpth)
453 break
454 if not found:
455 logger.error("Unable to find FILES_INFO entry in %s" % pkgdatafile)
456 sys.exit(1)
457
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500458
459 if args.recipe:
460 if args.pkg:
461 logger.error("list-pkg-files: If -p/--recipe is specified then a package name cannot be specified")
462 sys.exit(1)
463 recipepkglist = get_recipe_pkgs(args.pkgdata_dir, args.recipe, args.unpackaged)
464 if args.runtime:
465 pkglist = []
466 runtime_pkgs = lookup_pkglist(recipepkglist, args.pkgdata_dir, False)
467 for rtpkgs in runtime_pkgs.values():
468 pkglist.extend(rtpkgs)
469 else:
470 pkglist = recipepkglist
471 else:
472 if not args.pkg:
473 logger.error("list-pkg-files: If -p/--recipe is not specified then at least one package name must be specified")
474 sys.exit(1)
475 pkglist = args.pkg
476
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500477 for pkg in sorted(pkglist):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500478 print("%s:" % pkg)
479 if args.runtime:
480 pkgdatafile = os.path.join(args.pkgdata_dir, "runtime-reverse", pkg)
481 if not os.path.exists(pkgdatafile):
482 if args.recipe:
483 # This package was empty and thus never packaged, ignore
484 continue
485 logger.error("Unable to find any built runtime package named %s" % pkg)
486 sys.exit(1)
Brad Bishop316dfdd2018-06-25 12:45:53 -0400487 parse_pkgdatafile(pkgdatafile, args.long)
488
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500489 else:
Brad Bishop316dfdd2018-06-25 12:45:53 -0400490 providepkgpath = os.path.join(args.pkgdata_dir, "runtime-rprovides", pkg)
491 if os.path.exists(providepkgpath):
492 for f in os.listdir(providepkgpath):
493 if f != pkg:
494 print("%s is in the RPROVIDES of %s:" % (pkg, f))
495 pkgdatafile = os.path.join(args.pkgdata_dir, "runtime", f)
496 parse_pkgdatafile(pkgdatafile, args.long)
497 continue
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500498 pkgdatafile = os.path.join(args.pkgdata_dir, "runtime", pkg)
499 if not os.path.exists(pkgdatafile):
500 logger.error("Unable to find any built recipe-space package named %s" % pkg)
501 sys.exit(1)
Brad Bishop316dfdd2018-06-25 12:45:53 -0400502 parse_pkgdatafile(pkgdatafile, args.long)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500503
504def find_path(args):
505 import json
506
507 found = False
508 for root, dirs, files in os.walk(os.path.join(args.pkgdata_dir, 'runtime')):
509 for fn in files:
510 with open(os.path.join(root,fn)) as f:
511 for line in f:
512 if line.startswith('FILES_INFO:'):
513 val = line.split(':', 1)[1].strip()
514 dictval = json.loads(val)
515 for fullpth in dictval.keys():
516 if fnmatch.fnmatchcase(fullpth, args.targetpath):
517 found = True
518 print("%s: %s" % (fn, fullpth))
519 break
520 if not found:
521 logger.error("Unable to find any package producing path %s" % args.targetpath)
522 sys.exit(1)
523
524
525def main():
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500526 parser = argparse_oe.ArgumentParser(description="OpenEmbedded pkgdata tool - queries the pkgdata files written out during do_package",
527 epilog="Use %(prog)s <subcommand> --help to get help on a specific command")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500528 parser.add_argument('-d', '--debug', help='Enable debug output', action='store_true')
529 parser.add_argument('-p', '--pkgdata-dir', help='Path to pkgdata directory (determined automatically if not specified)')
530 subparsers = parser.add_subparsers(title='subcommands', metavar='<subcommand>')
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600531 subparsers.required = True
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500532
533 parser_lookup_pkg = subparsers.add_parser('lookup-pkg',
534 help='Translate between recipe-space package names and runtime package names',
535 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.')
536 parser_lookup_pkg.add_argument('pkg', nargs='+', help='Package name to look up')
537 parser_lookup_pkg.add_argument('-r', '--reverse', help='Switch to looking up recipe-space package names from runtime package names', action='store_true')
538 parser_lookup_pkg.set_defaults(func=lookup_pkg)
539
540 parser_list_pkgs = subparsers.add_parser('list-pkgs',
541 help='List packages',
542 description='Lists packages that have been built')
543 parser_list_pkgs.add_argument('pkgspec', nargs='*', help='Package name to search for (wildcards * ? allowed, use quotes to avoid shell expansion)')
544 parser_list_pkgs.add_argument('-r', '--runtime', help='Show runtime package names instead of recipe-space package names', action='store_true')
545 parser_list_pkgs.add_argument('-p', '--recipe', help='Limit to packages produced by the specified recipe')
546 parser_list_pkgs.add_argument('-u', '--unpackaged', help='Include unpackaged (i.e. empty) packages', action='store_true')
547 parser_list_pkgs.set_defaults(func=list_pkgs)
548
549 parser_list_pkg_files = subparsers.add_parser('list-pkg-files',
550 help='List files within a package',
551 description='Lists files included in one or more packages')
552 parser_list_pkg_files.add_argument('pkg', nargs='*', help='Package name to report on (if -p/--recipe is not specified)')
553 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')
554 parser_list_pkg_files.add_argument('-p', '--recipe', help='Report on all packages produced by the specified recipe')
555 parser_list_pkg_files.add_argument('-u', '--unpackaged', help='Include unpackaged (i.e. empty) packages (only useful with -p/--recipe)', action='store_true')
Brad Bishop316dfdd2018-06-25 12:45:53 -0400556 parser_list_pkg_files.add_argument('-l', '--long', help='Show more information per file', action='store_true')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500557 parser_list_pkg_files.set_defaults(func=list_pkg_files)
558
559 parser_lookup_recipe = subparsers.add_parser('lookup-recipe',
560 help='Find recipe producing one or more packages',
561 description='Looks up the specified runtime package(s) to see which recipe they were produced by')
562 parser_lookup_recipe.add_argument('pkg', nargs='+', help='Runtime package name to look up')
563 parser_lookup_recipe.set_defaults(func=lookup_recipe)
564
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600565 parser_package_info = subparsers.add_parser('package-info',
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500566 help='Show version, recipe and size information for one or more packages',
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600567 description='Looks up the specified runtime package(s) and display information')
568 parser_package_info.add_argument('pkg', nargs='*', help='Runtime package name to look up')
569 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 -0500570 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 -0600571 parser_package_info.set_defaults(func=package_info)
572
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500573 parser_find_path = subparsers.add_parser('find-path',
574 help='Find package providing a target path',
575 description='Finds the recipe-space package providing the specified target path')
576 parser_find_path.add_argument('targetpath', help='Path to find (wildcards * ? allowed, use quotes to avoid shell expansion)')
577 parser_find_path.set_defaults(func=find_path)
578
579 parser_read_value = subparsers.add_parser('read-value',
580 help='Read any pkgdata value for one or more packages',
581 description='Reads the named value from the pkgdata files for the specified packages')
582 parser_read_value.add_argument('valuename', help='Name of the value to look up')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500583 parser_read_value.add_argument('pkg', nargs='*', help='Runtime package name to look up')
584 parser_read_value.add_argument('-f', '--file', help='Read package names from the specified file (one per line, first field only)')
585 parser_read_value.add_argument('-n', '--prefix-name', help='Prefix output with package name', action='store_true')
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500586 parser_read_value.add_argument('-u', '--unescape', help='Expand escapes such as \\n', action='store_true')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500587 parser_read_value.set_defaults(func=read_value)
588
589 parser_glob = subparsers.add_parser('glob',
590 help='Expand package name glob expression',
591 description='Expands one or more glob expressions over the packages listed in pkglistfile')
592 parser_glob.add_argument('pkglistfile', help='File listing packages (one package name per line)')
593 parser_glob.add_argument('glob', nargs="+", help='Glob expression for package names, e.g. *-dev')
594 parser_glob.add_argument('-x', '--exclude', help='Exclude packages matching specified regex from the glob operation')
595 parser_glob.set_defaults(func=glob)
596
597
598 args = parser.parse_args()
599
600 if args.debug:
601 logger.setLevel(logging.DEBUG)
602
603 if not args.pkgdata_dir:
604 import scriptpath
605 bitbakepath = scriptpath.add_bitbake_lib_path()
606 if not bitbakepath:
607 logger.error("Unable to find bitbake by searching parent directory of this script or PATH")
608 sys.exit(1)
609 logger.debug('Found bitbake path: %s' % bitbakepath)
610 tinfoil = tinfoil_init()
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600611 try:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500612 args.pkgdata_dir = tinfoil.config_data.getVar('PKGDATA_DIR')
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600613 finally:
614 tinfoil.shutdown()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500615 logger.debug('Value of PKGDATA_DIR is "%s"' % args.pkgdata_dir)
616 if not args.pkgdata_dir:
617 logger.error('Unable to determine pkgdata directory from PKGDATA_DIR')
618 sys.exit(1)
619
620 if not os.path.exists(args.pkgdata_dir):
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500621 logger.error('Unable to find pkgdata directory %s' % args.pkgdata_dir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500622 sys.exit(1)
623
624 ret = args.func(args)
625
626 return ret
627
628
629if __name__ == "__main__":
630 main()