oe-pkgdata-util 25 KB

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