blob: 8963ca4b06c27a1b1ef1e400d0f853cd27b0c633 [file] [log] [blame]
rjw1f884582022-01-06 17:20:42 +08001#!/usr/bin/env python3
2# ex:ts=4:sw=4:sts=4:et
3# -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
4#
5# Copyright (C) 2012, 2018 Wind River Systems, Inc.
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#
21# Used for dumping the bb_cache.dat
22#
23import os
24import sys
25import argparse
26
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
31import pickle
32
33class 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="")
46
47 self.args = parser.parse_args()
48
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
60
61 if self.args.recipe and self.args.recipe != pn:
62 continue
63
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))
76
77if __name__ == "__main__":
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)