__init__.py 2.2 KB

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