oe-pkgdata-util 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633
  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.valuenames, 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. qvars = args.valuenames
  165. val_names = qvars.split(',')
  166. values = []
  167. for qvar in val_names:
  168. if qvar == "PACKAGE":
  169. value = mappedpkg
  170. else:
  171. value = readvar(revlink, qvar, mappedpkg)
  172. if qvar == "PKGSIZE":
  173. # PKGSIZE is now in bytes, but we we want it in KB
  174. pkgsize = (int(value) + 1024 // 2) // 1024
  175. value = "%d" % pkgsize
  176. if args.unescape:
  177. import codecs
  178. # escape_decode() unescapes backslash encodings in byte streams
  179. value = codecs.escape_decode(bytes(value, "utf-8"))[0].decode("utf-8")
  180. values.append(value)
  181. values_str = ' '.join(values)
  182. if args.prefix_name:
  183. print('%s %s' % (pkg_name, values_str))
  184. else:
  185. print(values_str)
  186. else:
  187. logger.debug("revlink %s does not exist", revlink)
  188. def lookup_pkglist(pkgs, pkgdata_dir, reverse):
  189. if reverse:
  190. mappings = OrderedDict()
  191. for pkg in pkgs:
  192. revlink = os.path.join(pkgdata_dir, "runtime-reverse", pkg)
  193. logger.debug(revlink)
  194. if os.path.exists(revlink):
  195. mappings[pkg] = os.path.basename(os.readlink(revlink))
  196. else:
  197. mappings = defaultdict(list)
  198. for pkg in pkgs:
  199. pkgfile = os.path.join(pkgdata_dir, 'runtime', pkg)
  200. if os.path.exists(pkgfile):
  201. with open(pkgfile, 'r') as f:
  202. for line in f:
  203. fields = line.rstrip().split(': ')
  204. if fields[0] == 'PKG:%s' % pkg:
  205. mappings[pkg].append(fields[1])
  206. break
  207. return mappings
  208. def lookup_pkg(args):
  209. # Handle both multiple arguments and multiple values within an arg (old syntax)
  210. pkgs = []
  211. for pkgitem in args.pkg:
  212. pkgs.extend(pkgitem.split())
  213. mappings = lookup_pkglist(pkgs, args.pkgdata_dir, args.reverse)
  214. if len(mappings) < len(pkgs):
  215. missing = list(set(pkgs) - set(mappings.keys()))
  216. logger.error("The following packages could not be found: %s" % ', '.join(missing))
  217. sys.exit(1)
  218. if args.reverse:
  219. items = list(mappings.values())
  220. else:
  221. items = []
  222. for pkg in pkgs:
  223. items.extend(mappings.get(pkg, []))
  224. print('\n'.join(items))
  225. def lookup_recipe(args):
  226. def parse_pkgdatafile(pkgdatafile):
  227. with open(pkgdatafile, 'r') as f:
  228. found = False
  229. for line in f:
  230. if line.startswith('PN:'):
  231. print("%s" % line.split(':', 1)[1].strip())
  232. found = True
  233. break
  234. if not found:
  235. logger.error("Unable to find PN entry in %s" % pkgdatafile)
  236. sys.exit(1)
  237. # Handle both multiple arguments and multiple values within an arg (old syntax)
  238. pkgs = []
  239. for pkgitem in args.pkg:
  240. pkgs.extend(pkgitem.split())
  241. for pkg in pkgs:
  242. providepkgpath = os.path.join(args.pkgdata_dir, "runtime-rprovides", pkg)
  243. if os.path.exists(providepkgpath):
  244. for f in os.listdir(providepkgpath):
  245. if f != pkg:
  246. print("%s is in the RPROVIDES of %s:" % (pkg, f))
  247. pkgdatafile = os.path.join(args.pkgdata_dir, "runtime", f)
  248. parse_pkgdatafile(pkgdatafile)
  249. continue
  250. pkgdatafile = os.path.join(args.pkgdata_dir, 'runtime-reverse', pkg)
  251. if os.path.exists(pkgdatafile):
  252. parse_pkgdatafile(pkgdatafile)
  253. else:
  254. if args.carryon:
  255. print("The following packages could not be found: %s" % pkg)
  256. else:
  257. logger.error("The following packages could not be found: %s" % pkg)
  258. sys.exit(1)
  259. def package_info(args):
  260. def parse_pkgdatafile(pkgdatafile):
  261. vars = ['PKGV', 'PKGE', 'PKGR', 'PN', 'PV', 'PE', 'PR', 'PKGSIZE']
  262. if args.extra:
  263. vars += args.extra
  264. with open(pkgdatafile, 'r') as f:
  265. vals = dict()
  266. extra = ''
  267. for line in f:
  268. for var in vars:
  269. m = re.match(var + '(?::\S+)?:\s*(.+?)\s*$', line)
  270. if m:
  271. vals[var] = m.group(1)
  272. pkg_version = vals['PKGV'] or ''
  273. recipe = vals['PN'] or ''
  274. recipe_version = vals['PV'] or ''
  275. pkg_size = vals['PKGSIZE'] or ''
  276. if 'PKGE' in vals:
  277. pkg_version = vals['PKGE'] + ":" + pkg_version
  278. if 'PKGR' in vals:
  279. pkg_version = pkg_version + "-" + vals['PKGR']
  280. if 'PE' in vals:
  281. recipe_version = vals['PE'] + ":" + recipe_version
  282. if 'PR' in vals:
  283. recipe_version = recipe_version + "-" + vals['PR']
  284. if args.extra:
  285. for var in args.extra:
  286. if var in vals:
  287. val = re.sub(r'\s+', ' ', vals[var])
  288. extra += ' "%s"' % val
  289. print("%s %s %s %s %s%s" % (pkg, pkg_version, recipe, recipe_version, pkg_size, extra))
  290. # Handle both multiple arguments and multiple values within an arg (old syntax)
  291. packages = []
  292. if args.file:
  293. with open(args.file, 'r') as f:
  294. for line in f:
  295. splitline = line.split()
  296. if splitline:
  297. packages.append(splitline[0])
  298. else:
  299. for pkgitem in args.pkg:
  300. packages.extend(pkgitem.split())
  301. if not packages:
  302. logger.error("No packages specified")
  303. sys.exit(1)
  304. for pkg in packages:
  305. providepkgpath = os.path.join(args.pkgdata_dir, "runtime-rprovides", pkg)
  306. if os.path.exists(providepkgpath):
  307. for f in os.listdir(providepkgpath):
  308. if f != pkg:
  309. print("%s is in the RPROVIDES of %s:" % (pkg, f))
  310. pkgdatafile = os.path.join(args.pkgdata_dir, "runtime", f)
  311. parse_pkgdatafile(pkgdatafile)
  312. continue
  313. pkgdatafile = os.path.join(args.pkgdata_dir, "runtime-reverse", pkg)
  314. if not os.path.exists(pkgdatafile):
  315. logger.error("Unable to find any built runtime package named %s" % pkg)
  316. sys.exit(1)
  317. parse_pkgdatafile(pkgdatafile)
  318. def get_recipe_pkgs(pkgdata_dir, recipe, unpackaged):
  319. recipedatafile = os.path.join(pkgdata_dir, recipe)
  320. if not os.path.exists(recipedatafile):
  321. logger.error("Unable to find packaged recipe with name %s" % recipe)
  322. sys.exit(1)
  323. packages = []
  324. with open(recipedatafile, 'r') as f:
  325. for line in f:
  326. fields = line.rstrip().split(': ')
  327. if fields[0] == 'PACKAGES':
  328. packages = fields[1].split()
  329. break
  330. if not unpackaged:
  331. pkglist = []
  332. for pkg in packages:
  333. if os.path.exists(os.path.join(pkgdata_dir, 'runtime', '%s.packaged' % pkg)):
  334. pkglist.append(pkg)
  335. return pkglist
  336. else:
  337. return packages
  338. def list_pkgs(args):
  339. found = False
  340. def matchpkg(pkg):
  341. if args.pkgspec:
  342. matched = False
  343. for pkgspec in args.pkgspec:
  344. if fnmatch.fnmatchcase(pkg, pkgspec):
  345. matched = True
  346. break
  347. if not matched:
  348. return False
  349. if not args.unpackaged:
  350. if args.runtime:
  351. revlink = os.path.join(args.pkgdata_dir, "runtime-reverse", pkg)
  352. if os.path.exists(revlink):
  353. # We're unlikely to get here if the package was not packaged, but just in case
  354. # we add the symlinks for unpackaged files in the future
  355. mappedpkg = os.path.basename(os.readlink(revlink))
  356. if not os.path.exists(os.path.join(args.pkgdata_dir, 'runtime', '%s.packaged' % mappedpkg)):
  357. return False
  358. else:
  359. return False
  360. else:
  361. if not os.path.exists(os.path.join(args.pkgdata_dir, 'runtime', '%s.packaged' % pkg)):
  362. return False
  363. return True
  364. pkglist = []
  365. if args.recipe:
  366. packages = get_recipe_pkgs(args.pkgdata_dir, args.recipe, args.unpackaged)
  367. if args.runtime:
  368. runtime_pkgs = lookup_pkglist(packages, args.pkgdata_dir, False)
  369. for rtpkgs in runtime_pkgs.values():
  370. pkglist.extend(rtpkgs)
  371. else:
  372. pkglist = packages
  373. else:
  374. if args.runtime:
  375. searchdir = 'runtime-reverse'
  376. else:
  377. searchdir = 'runtime'
  378. for root, dirs, files in os.walk(os.path.join(args.pkgdata_dir, searchdir)):
  379. for fn in files:
  380. if fn.endswith('.packaged'):
  381. continue
  382. pkglist.append(fn)
  383. for pkg in sorted(pkglist):
  384. if matchpkg(pkg):
  385. found = True
  386. print("%s" % pkg)
  387. if not found:
  388. if args.pkgspec:
  389. logger.error("Unable to find any package matching %s" % args.pkgspec)
  390. else:
  391. logger.error("No packages found")
  392. sys.exit(1)
  393. def list_pkg_files(args):
  394. import json
  395. def parse_pkgdatafile(pkgdatafile, long=False):
  396. with open(pkgdatafile, 'r') as f:
  397. found = False
  398. for line in f:
  399. if line.startswith('FILES_INFO:'):
  400. found = True
  401. val = line.split(': ', 1)[1].strip()
  402. dictval = json.loads(val)
  403. if long:
  404. width = max(map(len, dictval), default=0)
  405. for fullpth in sorted(dictval):
  406. print("\t{:{width}}\t{}".format(fullpth, dictval[fullpth], width=width))
  407. else:
  408. for fullpth in sorted(dictval):
  409. print("\t%s" % fullpth)
  410. break
  411. if not found:
  412. logger.error("Unable to find FILES_INFO entry in %s" % pkgdatafile)
  413. sys.exit(1)
  414. if args.recipe:
  415. if args.pkg:
  416. logger.error("list-pkg-files: If -p/--recipe is specified then a package name cannot be specified")
  417. sys.exit(1)
  418. recipepkglist = get_recipe_pkgs(args.pkgdata_dir, args.recipe, args.unpackaged)
  419. if args.runtime:
  420. pkglist = []
  421. runtime_pkgs = lookup_pkglist(recipepkglist, args.pkgdata_dir, False)
  422. for rtpkgs in runtime_pkgs.values():
  423. pkglist.extend(rtpkgs)
  424. else:
  425. pkglist = recipepkglist
  426. else:
  427. if not args.pkg:
  428. logger.error("list-pkg-files: If -p/--recipe is not specified then at least one package name must be specified")
  429. sys.exit(1)
  430. pkglist = args.pkg
  431. for pkg in sorted(pkglist):
  432. print("%s:" % pkg)
  433. if args.runtime:
  434. pkgdatafile = os.path.join(args.pkgdata_dir, "runtime-reverse", pkg)
  435. if not os.path.exists(pkgdatafile):
  436. if args.recipe:
  437. # This package was empty and thus never packaged, ignore
  438. continue
  439. logger.error("Unable to find any built runtime package named %s" % pkg)
  440. sys.exit(1)
  441. parse_pkgdatafile(pkgdatafile, args.long)
  442. else:
  443. providepkgpath = os.path.join(args.pkgdata_dir, "runtime-rprovides", pkg)
  444. if os.path.exists(providepkgpath):
  445. for f in os.listdir(providepkgpath):
  446. if f != pkg:
  447. print("%s is in the RPROVIDES of %s:" % (pkg, f))
  448. pkgdatafile = os.path.join(args.pkgdata_dir, "runtime", f)
  449. parse_pkgdatafile(pkgdatafile, args.long)
  450. continue
  451. pkgdatafile = os.path.join(args.pkgdata_dir, "runtime", pkg)
  452. if not os.path.exists(pkgdatafile):
  453. logger.error("Unable to find any built recipe-space package named %s" % pkg)
  454. sys.exit(1)
  455. parse_pkgdatafile(pkgdatafile, args.long)
  456. def find_path(args):
  457. import json
  458. found = False
  459. for root, dirs, files in os.walk(os.path.join(args.pkgdata_dir, 'runtime')):
  460. for fn in files:
  461. with open(os.path.join(root,fn)) as f:
  462. for line in f:
  463. if line.startswith('FILES_INFO:'):
  464. val = line.split(': ', 1)[1].strip()
  465. dictval = json.loads(val)
  466. for fullpth in dictval.keys():
  467. if fnmatch.fnmatchcase(fullpth, args.targetpath):
  468. found = True
  469. print("%s: %s" % (fn, fullpth))
  470. break
  471. if not found:
  472. logger.error("Unable to find any package producing path %s" % args.targetpath)
  473. sys.exit(1)
  474. def main():
  475. parser = argparse_oe.ArgumentParser(description="OpenEmbedded pkgdata tool - queries the pkgdata files written out during do_package",
  476. epilog="Use %(prog)s <subcommand> --help to get help on a specific command")
  477. parser.add_argument('-d', '--debug', help='Enable debug output', action='store_true')
  478. parser.add_argument('-p', '--pkgdata-dir', help='Path to pkgdata directory (determined automatically if not specified)')
  479. subparsers = parser.add_subparsers(title='subcommands', metavar='<subcommand>')
  480. subparsers.required = True
  481. parser_lookup_pkg = subparsers.add_parser('lookup-pkg',
  482. help='Translate between recipe-space package names and runtime package names',
  483. 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.')
  484. parser_lookup_pkg.add_argument('pkg', nargs='+', help='Package name to look up')
  485. parser_lookup_pkg.add_argument('-r', '--reverse', help='Switch to looking up recipe-space package names from runtime package names', action='store_true')
  486. parser_lookup_pkg.set_defaults(func=lookup_pkg)
  487. parser_list_pkgs = subparsers.add_parser('list-pkgs',
  488. help='List packages',
  489. description='Lists packages that have been built')
  490. parser_list_pkgs.add_argument('pkgspec', nargs='*', help='Package name to search for (wildcards * ? allowed, use quotes to avoid shell expansion)')
  491. parser_list_pkgs.add_argument('-r', '--runtime', help='Show runtime package names instead of recipe-space package names', action='store_true')
  492. parser_list_pkgs.add_argument('-p', '--recipe', help='Limit to packages produced by the specified recipe')
  493. parser_list_pkgs.add_argument('-u', '--unpackaged', help='Include unpackaged (i.e. empty) packages', action='store_true')
  494. parser_list_pkgs.set_defaults(func=list_pkgs)
  495. parser_list_pkg_files = subparsers.add_parser('list-pkg-files',
  496. help='List files within a package',
  497. description='Lists files included in one or more packages')
  498. parser_list_pkg_files.add_argument('pkg', nargs='*', help='Package name to report on (if -p/--recipe is not specified)')
  499. 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')
  500. parser_list_pkg_files.add_argument('-p', '--recipe', help='Report on all packages produced by the specified recipe')
  501. parser_list_pkg_files.add_argument('-u', '--unpackaged', help='Include unpackaged (i.e. empty) packages (only useful with -p/--recipe)', action='store_true')
  502. parser_list_pkg_files.add_argument('-l', '--long', help='Show more information per file', action='store_true')
  503. parser_list_pkg_files.set_defaults(func=list_pkg_files)
  504. parser_lookup_recipe = subparsers.add_parser('lookup-recipe',
  505. help='Find recipe producing one or more packages',
  506. description='Looks up the specified runtime package(s) to see which recipe they were produced by')
  507. parser_lookup_recipe.add_argument('pkg', nargs='+', help='Runtime package name to look up')
  508. parser_lookup_recipe.add_argument('-c', '--continue', dest="carryon", help='Continue looking up recipes even if we can not find one', action='store_true')
  509. parser_lookup_recipe.set_defaults(func=lookup_recipe)
  510. parser_package_info = subparsers.add_parser('package-info',
  511. help='Show version, recipe and size information for one or more packages',
  512. description='Looks up the specified runtime package(s) and display information')
  513. parser_package_info.add_argument('pkg', nargs='*', help='Runtime package name to look up')
  514. parser_package_info.add_argument('-f', '--file', help='Read package names from the specified file (one per line, first field only)')
  515. parser_package_info.add_argument('-e', '--extra', help='Extra variables to display, e.g., LICENSE (can be specified multiple times)', action='append')
  516. parser_package_info.set_defaults(func=package_info)
  517. parser_find_path = subparsers.add_parser('find-path',
  518. help='Find package providing a target path',
  519. description='Finds the recipe-space package providing the specified target path')
  520. parser_find_path.add_argument('targetpath', help='Path to find (wildcards * ? allowed, use quotes to avoid shell expansion)')
  521. parser_find_path.set_defaults(func=find_path)
  522. parser_read_value = subparsers.add_parser('read-value',
  523. help='Read any pkgdata value for one or more packages',
  524. description='Reads the named value from the pkgdata files for the specified packages')
  525. parser_read_value.add_argument('valuenames', help='Name of the value/s to look up (separated by commas, no spaces)')
  526. parser_read_value.add_argument('pkg', nargs='*', help='Runtime package name to look up')
  527. parser_read_value.add_argument('-f', '--file', help='Read package names from the specified file (one per line, first field only)')
  528. parser_read_value.add_argument('-n', '--prefix-name', help='Prefix output with package name', action='store_true')
  529. parser_read_value.add_argument('-u', '--unescape', help='Expand escapes such as \\n', action='store_true')
  530. parser_read_value.set_defaults(func=read_value)
  531. parser_glob = subparsers.add_parser('glob',
  532. help='Expand package name glob expression',
  533. description='Expands one or more glob expressions over the packages listed in pkglistfile')
  534. parser_glob.add_argument('pkglistfile', help='File listing packages (one package name per line)')
  535. parser_glob.add_argument('glob', nargs="+", help='Glob expression for package names, e.g. *-dev')
  536. parser_glob.add_argument('-x', '--exclude', help='Exclude packages matching specified regex from the glob operation')
  537. parser_glob.set_defaults(func=glob)
  538. args = parser.parse_args()
  539. if args.debug:
  540. logger.setLevel(logging.DEBUG)
  541. if not args.pkgdata_dir:
  542. import scriptpath
  543. bitbakepath = scriptpath.add_bitbake_lib_path()
  544. if not bitbakepath:
  545. logger.error("Unable to find bitbake by searching parent directory of this script or PATH")
  546. sys.exit(1)
  547. logger.debug('Found bitbake path: %s' % bitbakepath)
  548. if not os.environ.get('BUILDDIR', ''):
  549. logger.error("This script can only be run after initialising the build environment (e.g. by using oe-init-build-env)")
  550. sys.exit(1)
  551. tinfoil = tinfoil_init()
  552. try:
  553. args.pkgdata_dir = tinfoil.config_data.getVar('PKGDATA_DIR')
  554. finally:
  555. tinfoil.shutdown()
  556. logger.debug('Value of PKGDATA_DIR is "%s"' % args.pkgdata_dir)
  557. if not args.pkgdata_dir:
  558. logger.error('Unable to determine pkgdata directory from PKGDATA_DIR')
  559. sys.exit(1)
  560. if not os.path.exists(args.pkgdata_dir):
  561. logger.error('Unable to find pkgdata directory %s' % args.pkgdata_dir)
  562. sys.exit(1)
  563. ret = args.func(args)
  564. return ret
  565. if __name__ == "__main__":
  566. main()