oe-pkgdata-util 27 KB

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