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