Patrick Williams | c0f7c04 | 2017-02-23 20:41:17 -0600 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 2 | # ex:ts=4:sw=4:sts=4:et |
| 3 | # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- |
| 4 | # |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame^] | 5 | # Copyright (C) 2012, 2018 Wind River Systems, Inc. |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 6 | # |
| 7 | # This program is free software; you can redistribute it and/or modify |
| 8 | # it under the terms of the GNU General Public License version 2 as |
| 9 | # published by the Free Software Foundation. |
| 10 | # |
| 11 | # This program is distributed in the hope that it will be useful, |
| 12 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | # GNU General Public License for more details. |
| 15 | # |
| 16 | # You should have received a copy of the GNU General Public License along |
| 17 | # with this program; if not, write to the Free Software Foundation, Inc., |
| 18 | # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 19 | |
| 20 | # |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame^] | 21 | # Used for dumping the bb_cache.dat |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 22 | # |
| 23 | import os |
| 24 | import sys |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame^] | 25 | import argparse |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 26 | |
| 27 | # For importing bb.cache |
| 28 | sys.path.insert(0, os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])), '../lib')) |
| 29 | from bb.cache import CoreRecipeInfo |
| 30 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame^] | 31 | import pickle |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 32 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame^] | 33 | class DumpCache(object): |
| 34 | def __init__(self): |
| 35 | parser = argparse.ArgumentParser( |
| 36 | description="bb_cache.dat's dumper", |
| 37 | epilog="Use %(prog)s --help to get help") |
| 38 | parser.add_argument("-r", "--recipe", |
| 39 | help="specify the recipe, default: all recipes", action="store") |
| 40 | parser.add_argument("-m", "--members", |
| 41 | help = "specify the member, use comma as separator for multiple ones, default: all members", action="store", default="") |
| 42 | parser.add_argument("-s", "--skip", |
| 43 | help = "skip skipped recipes", action="store_true") |
| 44 | parser.add_argument("cachefile", |
| 45 | help = "specify bb_cache.dat", nargs = 1, action="store", default="") |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 46 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame^] | 47 | self.args = parser.parse_args() |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 48 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame^] | 49 | def main(self): |
| 50 | with open(self.args.cachefile[0], "rb") as cachefile: |
| 51 | pickled = pickle.Unpickler(cachefile) |
| 52 | while True: |
| 53 | try: |
| 54 | key = pickled.load() |
| 55 | val = pickled.load() |
| 56 | except Exception: |
| 57 | break |
| 58 | if isinstance(val, CoreRecipeInfo): |
| 59 | pn = val.pn |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 60 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame^] | 61 | if self.args.recipe and self.args.recipe != pn: |
| 62 | continue |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 63 | |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame^] | 64 | if self.args.skip and val.skipped: |
| 65 | continue |
| 66 | |
| 67 | if self.args.members: |
| 68 | out = key |
| 69 | for member in self.args.members.split(','): |
| 70 | out += ": %s" % val.__dict__.get(member) |
| 71 | print("%s" % out) |
| 72 | else: |
| 73 | print("%s: %s" % (key, val.__dict__)) |
| 74 | elif not self.args.recipe: |
| 75 | print("%s %s" % (key, val)) |
Patrick Williams | c124f4f | 2015-09-15 14:41:29 -0500 | [diff] [blame] | 76 | |
| 77 | if __name__ == "__main__": |
Brad Bishop | 316dfdd | 2018-06-25 12:45:53 -0400 | [diff] [blame^] | 78 | try: |
| 79 | dump = DumpCache() |
| 80 | ret = dump.main() |
| 81 | except Exception as esc: |
| 82 | ret = 1 |
| 83 | import traceback |
| 84 | traceback.print_exc() |
| 85 | sys.exit(ret) |