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