dump_cache.py 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  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. # Used for dumping the bb_cache.dat
  19. #
  20. import os
  21. import sys
  22. import argparse
  23. # For importing bb.cache
  24. sys.path.insert(0, os.path.join(os.path.abspath(os.path.dirname(sys.argv[0])), '../lib'))
  25. from bb.cache import CoreRecipeInfo
  26. import pickle
  27. class DumpCache(object):
  28. def __init__(self):
  29. parser = argparse.ArgumentParser(
  30. description="bb_cache.dat's dumper",
  31. epilog="Use %(prog)s --help to get help")
  32. parser.add_argument("-r", "--recipe",
  33. help="specify the recipe, default: all recipes", action="store")
  34. parser.add_argument("-m", "--members",
  35. help = "specify the member, use comma as separator for multiple ones, default: all members", action="store", default="")
  36. parser.add_argument("-s", "--skip",
  37. help = "skip skipped recipes", action="store_true")
  38. parser.add_argument("cachefile",
  39. help = "specify bb_cache.dat", nargs = 1, action="store", default="")
  40. self.args = parser.parse_args()
  41. def main(self):
  42. with open(self.args.cachefile[0], "rb") as cachefile:
  43. pickled = pickle.Unpickler(cachefile)
  44. while True:
  45. try:
  46. key = pickled.load()
  47. val = pickled.load()
  48. except Exception:
  49. break
  50. if isinstance(val, CoreRecipeInfo):
  51. pn = val.pn
  52. if self.args.recipe and self.args.recipe != pn:
  53. continue
  54. if self.args.skip and val.skipped:
  55. continue
  56. if self.args.members:
  57. out = key
  58. for member in self.args.members.split(','):
  59. out += ": %s" % val.__dict__.get(member)
  60. print("%s" % out)
  61. else:
  62. print("%s: %s" % (key, val.__dict__))
  63. elif not self.args.recipe:
  64. print("%s %s" % (key, val))
  65. if __name__ == "__main__":
  66. try:
  67. dump = DumpCache()
  68. ret = dump.main()
  69. except Exception as esc:
  70. ret = 1
  71. import traceback
  72. traceback.print_exc()
  73. sys.exit(ret)