tinfoil.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. # tinfoil: a simple wrapper around cooker for bitbake-based command-line utilities
  2. #
  3. # Copyright (C) 2012 Intel Corporation
  4. # Copyright (C) 2011 Mentor Graphics Corporation
  5. #
  6. # This program is free software; you can redistribute it and/or modify
  7. # it under the terms of the GNU General Public License version 2 as
  8. # published by the Free Software Foundation.
  9. #
  10. # This program is distributed in the hope that it will be useful,
  11. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. # GNU General Public License for more details.
  14. #
  15. # You should have received a copy of the GNU General Public License along
  16. # with this program; if not, write to the Free Software Foundation, Inc.,
  17. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  18. import logging
  19. import warnings
  20. import os
  21. import sys
  22. import bb.cache
  23. import bb.cooker
  24. import bb.providers
  25. import bb.utils
  26. from bb.cooker import state
  27. import bb.fetch2
  28. class Tinfoil:
  29. def __init__(self, output=sys.stdout):
  30. # Needed to avoid deprecation warnings with python 2.6
  31. warnings.filterwarnings("ignore", category=DeprecationWarning)
  32. # Set up logging
  33. self.logger = logging.getLogger('BitBake')
  34. console = logging.StreamHandler(output)
  35. bb.msg.addDefaultlogFilter(console)
  36. format = bb.msg.BBLogFormatter("%(levelname)s: %(message)s")
  37. if output.isatty():
  38. format.enable_color()
  39. console.setFormatter(format)
  40. self.logger.addHandler(console)
  41. initialenv = os.environ.copy()
  42. bb.utils.clean_environment()
  43. self.config = TinfoilConfig(parse_only=True)
  44. self.cooker = bb.cooker.BBCooker(self.config,
  45. self.register_idle_function,
  46. initialenv)
  47. self.config_data = self.cooker.configuration.data
  48. bb.providers.logger.setLevel(logging.ERROR)
  49. self.cooker_data = None
  50. def register_idle_function(self, function, data):
  51. pass
  52. def parseRecipes(self):
  53. sys.stderr.write("Parsing recipes..")
  54. self.logger.setLevel(logging.WARNING)
  55. try:
  56. while self.cooker.state in (state.initial, state.parsing):
  57. self.cooker.updateCache()
  58. except KeyboardInterrupt:
  59. self.cooker.shutdown()
  60. self.cooker.updateCache()
  61. sys.exit(2)
  62. self.logger.setLevel(logging.INFO)
  63. sys.stderr.write("done.\n")
  64. self.cooker_data = self.cooker.recipecache
  65. def prepare(self, config_only = False):
  66. if not self.cooker_data:
  67. if config_only:
  68. self.cooker.parseConfiguration()
  69. self.cooker_data = self.cooker.recipecache
  70. else:
  71. self.parseRecipes()
  72. class TinfoilConfig(object):
  73. def __init__(self, **options):
  74. self.pkgs_to_build = []
  75. self.debug_domains = []
  76. self.extra_assume_provided = []
  77. self.prefile = []
  78. self.postfile = []
  79. self.debug = 0
  80. self.__dict__.update(options)
  81. def __getattr__(self, attribute):
  82. try:
  83. return super(TinfoilConfig, self).__getattribute__(attribute)
  84. except AttributeError:
  85. return None