blob: 8963ca4b06c27a1b1ef1e400d0f853cd27b0c633 [file] [log] [blame]
Patrick Williamsc0f7c042017-02-23 20:41:17 -06001#!/usr/bin/env python3
Patrick Williamsc124f4f2015-09-15 14:41:29 -05002# ex:ts=4:sw=4:sts=4:et
3# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
4#
Brad Bishop316dfdd2018-06-25 12:45:53 -04005# Copyright (C) 2012, 2018 Wind River Systems, Inc.
Patrick Williamsc124f4f2015-09-15 14:41:29 -05006#
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 Bishop316dfdd2018-06-25 12:45:53 -040021# Used for dumping the bb_cache.dat
Patrick Williamsc124f4f2015-09-15 14:41:29 -050022#
23import os
24import sys
Brad Bishop316dfdd2018-06-25 12:45:53 -040025import argparse
Patrick Williamsc124f4f2015-09-15 14:41:29 -050026
27# For importing bb.cache
28sys.path.insert(0, os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])), '../lib'))
29from bb.cache import CoreRecipeInfo
30
Brad Bishop316dfdd2018-06-25 12:45:53 -040031import pickle
Patrick Williamsc124f4f2015-09-15 14:41:29 -050032
Brad Bishop316dfdd2018-06-25 12:45:53 -040033class 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 Williamsc124f4f2015-09-15 14:41:29 -050046
Brad Bishop316dfdd2018-06-25 12:45:53 -040047 self.args = parser.parse_args()
Patrick Williamsc124f4f2015-09-15 14:41:29 -050048
Brad Bishop316dfdd2018-06-25 12:45:53 -040049 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 Williamsc124f4f2015-09-15 14:41:29 -050060
Brad Bishop316dfdd2018-06-25 12:45:53 -040061 if self.args.recipe and self.args.recipe != pn:
62 continue
Patrick Williamsc124f4f2015-09-15 14:41:29 -050063
Brad Bishop316dfdd2018-06-25 12:45:53 -040064 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 Williamsc124f4f2015-09-15 14:41:29 -050076
77if __name__ == "__main__":
Brad Bishop316dfdd2018-06-25 12:45:53 -040078 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)