dump_cache.py 3.0 KB

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