__init__.py 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. """
  2. BitBake Parsers
  3. File parsers for the BitBake build tools.
  4. """
  5. # Copyright (C) 2003, 2004 Chris Larson
  6. # Copyright (C) 2003, 2004 Phil Blundell
  7. #
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License version 2 as
  10. # published by the Free Software Foundation.
  11. #
  12. # This program is distributed in the hope that it will be useful,
  13. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. # GNU General Public License for more details.
  16. #
  17. # You should have received a copy of the GNU General Public License along
  18. # with this program; if not, write to the Free Software Foundation, Inc.,
  19. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  20. #
  21. # Based on functions from the base bb module, Copyright 2003 Holger Schurig
  22. __all__ = [ 'ParseError', 'SkipPackage', 'cached_mtime', 'mark_dependency',
  23. 'supports', 'handle', 'init' ]
  24. handlers = []
  25. import bb, os
  26. class ParseError(Exception):
  27. """Exception raised when parsing fails"""
  28. class SkipPackage(Exception):
  29. """Exception raised to skip this package"""
  30. __mtime_cache = {}
  31. def cached_mtime(f):
  32. if not __mtime_cache.has_key(f):
  33. __mtime_cache[f] = os.stat(f)[8]
  34. return __mtime_cache[f]
  35. def cached_mtime_noerror(f):
  36. if not __mtime_cache.has_key(f):
  37. try:
  38. __mtime_cache[f] = os.stat(f)[8]
  39. except OSError:
  40. return 0
  41. return __mtime_cache[f]
  42. def mark_dependency(d, f):
  43. if f.startswith('./'):
  44. f = "%s/%s" % (os.getcwd(), f[2:])
  45. deps = bb.data.getVar('__depends', d) or []
  46. deps.append( (f, cached_mtime(f)) )
  47. bb.data.setVar('__depends', deps, d)
  48. def supports(fn, data):
  49. """Returns true if we have a handler for this file, false otherwise"""
  50. for h in handlers:
  51. if h['supports'](fn, data):
  52. return 1
  53. return 0
  54. def handle(fn, data, include = 0):
  55. """Call the handler that is appropriate for this file"""
  56. for h in handlers:
  57. if h['supports'](fn, data):
  58. return h['handle'](fn, data, include)
  59. raise ParseError("%s is not a BitBake file" % fn)
  60. def init(fn, data):
  61. for h in handlers:
  62. if h['supports'](fn):
  63. return h['init'](data)
  64. from parse_py import __version__, ConfHandler, BBHandler