1#!/usr/bin/env python3 2# 3# Copyright (C) 2012, 2018 Wind River Systems, Inc. 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# 19# Used for dumping the bb_cache.dat 20# 21import os 22import sys 23import argparse 24 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 29import pickle 30 31class 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="") 44 45 self.args = parser.parse_args() 46 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 58 59 if self.args.recipe and self.args.recipe != pn: 60 continue 61 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)) 74 75if __name__ == "__main__": 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) 84