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