blob: c6723cbf0ae3bce6a7cb96db51fbc7cb196d6ed8 [file] [log] [blame]
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001#!/usr/bin/env python3
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002#
Brad Bishop316dfdd2018-06-25 12:45:53 -04003# Copyright (C) 2012, 2018 Wind River Systems, Inc.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05004#
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 Bishop316dfdd2018-06-25 12:45:53 -040019# Used for dumping the bb_cache.dat
Patrick Williamsc124f4f2015-09-15 14:41:29 -050020#
21import os
22import sys
Brad Bishop316dfdd2018-06-25 12:45:53 -040023import argparse
Patrick Williamsc124f4f2015-09-15 14:41:29 -050024
25# For importing bb.cache
26sys.path.insert(0, os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])), '../lib'))
27from bb.cache import CoreRecipeInfo
28
Brad Bishop316dfdd2018-06-25 12:45:53 -040029import pickle
Patrick Williamsc124f4f2015-09-15 14:41:29 -050030
Brad Bishop316dfdd2018-06-25 12:45:53 -040031class 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 Williamsc124f4f2015-09-15 14:41:29 -050044
Brad Bishop316dfdd2018-06-25 12:45:53 -040045 self.args = parser.parse_args()
Patrick Williamsc124f4f2015-09-15 14:41:29 -050046
Brad Bishop316dfdd2018-06-25 12:45:53 -040047 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 Williamsc124f4f2015-09-15 14:41:29 -050058
Brad Bishop316dfdd2018-06-25 12:45:53 -040059 if self.args.recipe and self.args.recipe != pn:
60 continue
Patrick Williamsc124f4f2015-09-15 14:41:29 -050061
Brad Bishop316dfdd2018-06-25 12:45:53 -040062 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 Williamsc124f4f2015-09-15 14:41:29 -050074
75if __name__ == "__main__":
Brad Bishop316dfdd2018-06-25 12:45:53 -040076 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)