blob: 53739b0bfc504ff558e83f374581fc5a0b68110d [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)
Brad Bishopd5ae7d92018-06-14 09:52:03 -0700280 continue
Brad Bishop316dfdd2018-06-25 12:45:53 -0400281 pkgdatafile = os.path.join(args.pkgdata_dir, 'runtime-reverse', pkg)
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800282 if os.path.exists(pkgdatafile):
283 parse_pkgdatafile(pkgdatafile)
284 else:
285 if args.carryon:
286 print("The following packages could not be found: %s" % pkg)
287 else:
288 logger.error("The following packages could not be found: %s" % pkg)
289 sys.exit(1)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500290
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600291def package_info(args):
Brad Bishop316dfdd2018-06-25 12:45:53 -0400292 def parse_pkgdatafile(pkgdatafile):
Brad Bishopd5ae7d92018-06-14 09:52:03 -0700293 vars = ['PKGV', 'PKGE', 'PKGR', 'PN', 'PV', 'PE', 'PR', 'PKGSIZE']
294 if args.extra:
295 vars += args.extra
Brad Bishop316dfdd2018-06-25 12:45:53 -0400296 with open(pkgdatafile, 'r') as f:
Brad Bishopd5ae7d92018-06-14 09:52:03 -0700297 vals = dict()
298 extra = ''
Brad Bishop316dfdd2018-06-25 12:45:53 -0400299 for line in f:
Brad Bishopd5ae7d92018-06-14 09:52:03 -0700300 for var in vars:
301 m = re.match(var + '(?:_\S+)?:\s*(.+?)\s*$', line)
302 if m:
303 vals[var] = m.group(1)
304 pkg_version = vals['PKGV'] or ''
305 recipe = vals['PN'] or ''
306 recipe_version = vals['PV'] or ''
307 pkg_size = vals['PKGSIZE'] or ''
308 if 'PKGE' in vals:
309 pkg_version = vals['PKGE'] + ":" + pkg_version
310 if 'PKGR' in vals:
311 pkg_version = pkg_version + "-" + vals['PKGR']
312 if 'PE' in vals:
313 recipe_version = vals['PE'] + ":" + recipe_version
314 if 'PR' in vals:
315 recipe_version = recipe_version + "-" + vals['PR']
316 if args.extra:
317 for var in args.extra:
318 if var in vals:
319 val = re.sub(r'\s+', ' ', vals[var])
320 extra += ' "%s"' % val
321 print("%s %s %s %s %s%s" % (pkg, pkg_version, recipe, recipe_version, pkg_size, extra))
Brad Bishop316dfdd2018-06-25 12:45:53 -0400322
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600323 # Handle both multiple arguments and multiple values within an arg (old syntax)
324 packages = []
325 if args.file:
326 with open(args.file, 'r') as f:
327 for line in f:
328 splitline = line.split()
329 if splitline:
330 packages.append(splitline[0])
331 else:
332 for pkgitem in args.pkg:
333 packages.extend(pkgitem.split())
334 if not packages:
335 logger.error("No packages specified")
336 sys.exit(1)
337
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600338 for pkg in packages:
Brad Bishop316dfdd2018-06-25 12:45:53 -0400339 providepkgpath = os.path.join(args.pkgdata_dir, "runtime-rprovides", pkg)
340 if os.path.exists(providepkgpath):
341 for f in os.listdir(providepkgpath):
342 if f != pkg:
343 print("%s is in the RPROVIDES of %s:" % (pkg, f))
344 pkgdatafile = os.path.join(args.pkgdata_dir, "runtime", f)
345 parse_pkgdatafile(pkgdatafile)
Brad Bishopd5ae7d92018-06-14 09:52:03 -0700346 continue
Brad Bishop316dfdd2018-06-25 12:45:53 -0400347 pkgdatafile = os.path.join(args.pkgdata_dir, "runtime-reverse", pkg)
348 if not os.path.exists(pkgdatafile):
349 logger.error("Unable to find any built runtime package named %s" % pkg)
350 sys.exit(1)
351 parse_pkgdatafile(pkgdatafile)
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600352
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500353def get_recipe_pkgs(pkgdata_dir, recipe, unpackaged):
354 recipedatafile = os.path.join(pkgdata_dir, recipe)
355 if not os.path.exists(recipedatafile):
356 logger.error("Unable to find packaged recipe with name %s" % recipe)
357 sys.exit(1)
358 packages = []
359 with open(recipedatafile, 'r') as f:
360 for line in f:
361 fields = line.rstrip().split(': ')
362 if fields[0] == 'PACKAGES':
363 packages = fields[1].split()
364 break
365
366 if not unpackaged:
367 pkglist = []
368 for pkg in packages:
369 if os.path.exists(os.path.join(pkgdata_dir, 'runtime', '%s.packaged' % pkg)):
370 pkglist.append(pkg)
371 return pkglist
372 else:
373 return packages
374
375def list_pkgs(args):
376 found = False
377
378 def matchpkg(pkg):
379 if args.pkgspec:
380 matched = False
381 for pkgspec in args.pkgspec:
382 if fnmatch.fnmatchcase(pkg, pkgspec):
383 matched = True
384 break
385 if not matched:
386 return False
387 if not args.unpackaged:
388 if args.runtime:
389 revlink = os.path.join(args.pkgdata_dir, "runtime-reverse", pkg)
390 if os.path.exists(revlink):
391 # We're unlikely to get here if the package was not packaged, but just in case
392 # we add the symlinks for unpackaged files in the future
393 mappedpkg = os.path.basename(os.readlink(revlink))
394 if not os.path.exists(os.path.join(args.pkgdata_dir, 'runtime', '%s.packaged' % mappedpkg)):
395 return False
396 else:
397 return False
398 else:
399 if not os.path.exists(os.path.join(args.pkgdata_dir, 'runtime', '%s.packaged' % pkg)):
400 return False
401 return True
402
403 if args.recipe:
404 packages = get_recipe_pkgs(args.pkgdata_dir, args.recipe, args.unpackaged)
405
406 if args.runtime:
407 pkglist = []
408 runtime_pkgs = lookup_pkglist(packages, args.pkgdata_dir, False)
409 for rtpkgs in runtime_pkgs.values():
410 pkglist.extend(rtpkgs)
411 else:
412 pkglist = packages
413
414 for pkg in pkglist:
415 if matchpkg(pkg):
416 found = True
417 print("%s" % pkg)
418 else:
419 if args.runtime:
420 searchdir = 'runtime-reverse'
421 else:
422 searchdir = 'runtime'
423
424 for root, dirs, files in os.walk(os.path.join(args.pkgdata_dir, searchdir)):
425 for fn in files:
426 if fn.endswith('.packaged'):
427 continue
428 if matchpkg(fn):
429 found = True
430 print("%s" % fn)
431 if not found:
432 if args.pkgspec:
433 logger.error("Unable to find any package matching %s" % args.pkgspec)
434 else:
435 logger.error("No packages found")
436 sys.exit(1)
437
438def list_pkg_files(args):
439 import json
Brad Bishop316dfdd2018-06-25 12:45:53 -0400440 def parse_pkgdatafile(pkgdatafile, long=False):
441 with open(pkgdatafile, 'r') as f:
442 found = False
443 for line in f:
444 if line.startswith('FILES_INFO:'):
445 found = True
446 val = line.split(':', 1)[1].strip()
447 dictval = json.loads(val)
448 if long:
449 width = max(map(len, dictval), default=0)
450 for fullpth in sorted(dictval):
451 print("\t{:{width}}\t{}".format(fullpth, dictval[fullpth], width=width))
452 else:
453 for fullpth in sorted(dictval):
454 print("\t%s" % fullpth)
455 break
456 if not found:
457 logger.error("Unable to find FILES_INFO entry in %s" % pkgdatafile)
458 sys.exit(1)
459
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500460
461 if args.recipe:
462 if args.pkg:
463 logger.error("list-pkg-files: If -p/--recipe is specified then a package name cannot be specified")
464 sys.exit(1)
465 recipepkglist = get_recipe_pkgs(args.pkgdata_dir, args.recipe, args.unpackaged)
466 if args.runtime:
467 pkglist = []
468 runtime_pkgs = lookup_pkglist(recipepkglist, args.pkgdata_dir, False)
469 for rtpkgs in runtime_pkgs.values():
470 pkglist.extend(rtpkgs)
471 else:
472 pkglist = recipepkglist
473 else:
474 if not args.pkg:
475 logger.error("list-pkg-files: If -p/--recipe is not specified then at least one package name must be specified")
476 sys.exit(1)
477 pkglist = args.pkg
478
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500479 for pkg in sorted(pkglist):
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500480 print("%s:" % pkg)
481 if args.runtime:
482 pkgdatafile = os.path.join(args.pkgdata_dir, "runtime-reverse", pkg)
483 if not os.path.exists(pkgdatafile):
484 if args.recipe:
485 # This package was empty and thus never packaged, ignore
486 continue
487 logger.error("Unable to find any built runtime package named %s" % pkg)
488 sys.exit(1)
Brad Bishop316dfdd2018-06-25 12:45:53 -0400489 parse_pkgdatafile(pkgdatafile, args.long)
490
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500491 else:
Brad Bishop316dfdd2018-06-25 12:45:53 -0400492 providepkgpath = os.path.join(args.pkgdata_dir, "runtime-rprovides", pkg)
493 if os.path.exists(providepkgpath):
494 for f in os.listdir(providepkgpath):
495 if f != pkg:
496 print("%s is in the RPROVIDES of %s:" % (pkg, f))
497 pkgdatafile = os.path.join(args.pkgdata_dir, "runtime", f)
498 parse_pkgdatafile(pkgdatafile, args.long)
499 continue
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500500 pkgdatafile = os.path.join(args.pkgdata_dir, "runtime", pkg)
501 if not os.path.exists(pkgdatafile):
502 logger.error("Unable to find any built recipe-space package named %s" % pkg)
503 sys.exit(1)
Brad Bishop316dfdd2018-06-25 12:45:53 -0400504 parse_pkgdatafile(pkgdatafile, args.long)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500505
506def find_path(args):
507 import json
508
509 found = False
510 for root, dirs, files in os.walk(os.path.join(args.pkgdata_dir, 'runtime')):
511 for fn in files:
512 with open(os.path.join(root,fn)) as f:
513 for line in f:
514 if line.startswith('FILES_INFO:'):
515 val = line.split(':', 1)[1].strip()
516 dictval = json.loads(val)
517 for fullpth in dictval.keys():
518 if fnmatch.fnmatchcase(fullpth, args.targetpath):
519 found = True
520 print("%s: %s" % (fn, fullpth))
521 break
522 if not found:
523 logger.error("Unable to find any package producing path %s" % args.targetpath)
524 sys.exit(1)
525
526
527def main():
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500528 parser = argparse_oe.ArgumentParser(description="OpenEmbedded pkgdata tool - queries the pkgdata files written out during do_package",
529 epilog="Use %(prog)s <subcommand> --help to get help on a specific command")
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500530 parser.add_argument('-d', '--debug', help='Enable debug output', action='store_true')
531 parser.add_argument('-p', '--pkgdata-dir', help='Path to pkgdata directory (determined automatically if not specified)')
532 subparsers = parser.add_subparsers(title='subcommands', metavar='<subcommand>')
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600533 subparsers.required = True
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500534
535 parser_lookup_pkg = subparsers.add_parser('lookup-pkg',
536 help='Translate between recipe-space package names and runtime package names',
537 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.')
538 parser_lookup_pkg.add_argument('pkg', nargs='+', help='Package name to look up')
539 parser_lookup_pkg.add_argument('-r', '--reverse', help='Switch to looking up recipe-space package names from runtime package names', action='store_true')
540 parser_lookup_pkg.set_defaults(func=lookup_pkg)
541
542 parser_list_pkgs = subparsers.add_parser('list-pkgs',
543 help='List packages',
544 description='Lists packages that have been built')
545 parser_list_pkgs.add_argument('pkgspec', nargs='*', help='Package name to search for (wildcards * ? allowed, use quotes to avoid shell expansion)')
546 parser_list_pkgs.add_argument('-r', '--runtime', help='Show runtime package names instead of recipe-space package names', action='store_true')
547 parser_list_pkgs.add_argument('-p', '--recipe', help='Limit to packages produced by the specified recipe')
548 parser_list_pkgs.add_argument('-u', '--unpackaged', help='Include unpackaged (i.e. empty) packages', action='store_true')
549 parser_list_pkgs.set_defaults(func=list_pkgs)
550
551 parser_list_pkg_files = subparsers.add_parser('list-pkg-files',
552 help='List files within a package',
553 description='Lists files included in one or more packages')
554 parser_list_pkg_files.add_argument('pkg', nargs='*', help='Package name to report on (if -p/--recipe is not specified)')
555 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')
556 parser_list_pkg_files.add_argument('-p', '--recipe', help='Report on all packages produced by the specified recipe')
557 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 -0400558 parser_list_pkg_files.add_argument('-l', '--long', help='Show more information per file', action='store_true')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500559 parser_list_pkg_files.set_defaults(func=list_pkg_files)
560
561 parser_lookup_recipe = subparsers.add_parser('lookup-recipe',
562 help='Find recipe producing one or more packages',
563 description='Looks up the specified runtime package(s) to see which recipe they were produced by')
564 parser_lookup_recipe.add_argument('pkg', nargs='+', help='Runtime package name to look up')
Brad Bishop1a4b7ee2018-12-16 17:11:34 -0800565 parser_lookup_recipe.add_argument('-c', '--continue', dest="carryon", help='Continue looking up recipes even if we can not find one', action='store_true')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500566 parser_lookup_recipe.set_defaults(func=lookup_recipe)
567
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600568 parser_package_info = subparsers.add_parser('package-info',
Brad Bishop37a0e4d2017-12-04 01:01:44 -0500569 help='Show version, recipe and size information for one or more packages',
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600570 description='Looks up the specified runtime package(s) and display information')
571 parser_package_info.add_argument('pkg', nargs='*', help='Runtime package name to look up')
572 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 -0500573 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 -0600574 parser_package_info.set_defaults(func=package_info)
575
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500576 parser_find_path = subparsers.add_parser('find-path',
577 help='Find package providing a target path',
578 description='Finds the recipe-space package providing the specified target path')
579 parser_find_path.add_argument('targetpath', help='Path to find (wildcards * ? allowed, use quotes to avoid shell expansion)')
580 parser_find_path.set_defaults(func=find_path)
581
582 parser_read_value = subparsers.add_parser('read-value',
583 help='Read any pkgdata value for one or more packages',
584 description='Reads the named value from the pkgdata files for the specified packages')
585 parser_read_value.add_argument('valuename', help='Name of the value to look up')
Patrick Williamsd8c66bc2016-06-20 12:57:21 -0500586 parser_read_value.add_argument('pkg', nargs='*', help='Runtime package name to look up')
587 parser_read_value.add_argument('-f', '--file', help='Read package names from the specified file (one per line, first field only)')
588 parser_read_value.add_argument('-n', '--prefix-name', help='Prefix output with package name', action='store_true')
Brad Bishopd7bf8c12018-02-25 22:55:05 -0500589 parser_read_value.add_argument('-u', '--unescape', help='Expand escapes such as \\n', action='store_true')
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500590 parser_read_value.set_defaults(func=read_value)
591
592 parser_glob = subparsers.add_parser('glob',
593 help='Expand package name glob expression',
594 description='Expands one or more glob expressions over the packages listed in pkglistfile')
595 parser_glob.add_argument('pkglistfile', help='File listing packages (one package name per line)')
596 parser_glob.add_argument('glob', nargs="+", help='Glob expression for package names, e.g. *-dev')
597 parser_glob.add_argument('-x', '--exclude', help='Exclude packages matching specified regex from the glob operation')
598 parser_glob.set_defaults(func=glob)
599
600
601 args = parser.parse_args()
602
603 if args.debug:
604 logger.setLevel(logging.DEBUG)
605
606 if not args.pkgdata_dir:
607 import scriptpath
608 bitbakepath = scriptpath.add_bitbake_lib_path()
609 if not bitbakepath:
610 logger.error("Unable to find bitbake by searching parent directory of this script or PATH")
611 sys.exit(1)
612 logger.debug('Found bitbake path: %s' % bitbakepath)
613 tinfoil = tinfoil_init()
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600614 try:
Brad Bishop6e60e8b2018-02-01 10:27:11 -0500615 args.pkgdata_dir = tinfoil.config_data.getVar('PKGDATA_DIR')
Patrick Williamsc0f7c042017-02-23 20:41:17 -0600616 finally:
617 tinfoil.shutdown()
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500618 logger.debug('Value of PKGDATA_DIR is "%s"' % args.pkgdata_dir)
619 if not args.pkgdata_dir:
620 logger.error('Unable to determine pkgdata directory from PKGDATA_DIR')
621 sys.exit(1)
622
623 if not os.path.exists(args.pkgdata_dir):
Patrick Williamsf1e5d692016-03-30 15:21:19 -0500624 logger.error('Unable to find pkgdata directory %s' % args.pkgdata_dir)
Patrick Williamsc124f4f2015-09-15 14:41:29 -0500625 sys.exit(1)
626
627 ret = args.func(args)
628
629 return ret
630
631
632if __name__ == "__main__":
633 main()