__init__.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. # ex:ts=4:sw=4:sts=4:et
  2. # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
  3. #
  4. # BitBake Build System Python Library
  5. #
  6. # Copyright (C) 2003 Holger Schurig
  7. # Copyright (C) 2003, 2004 Chris Larson
  8. #
  9. # Based on Gentoo's portage.py.
  10. #
  11. # This program is free software; you can redistribute it and/or modify
  12. # it under the terms of the GNU General Public License version 2 as
  13. # published by the Free Software Foundation.
  14. #
  15. # This program is distributed in the hope that it will be useful,
  16. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. # GNU General Public License for more details.
  19. #
  20. # You should have received a copy of the GNU General Public License along
  21. # with this program; if not, write to the Free Software Foundation, Inc.,
  22. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  23. __version__ = "1.11.0"
  24. import sys
  25. if sys.version_info < (2, 6, 0):
  26. raise RuntimeError("Sorry, python 2.6.0 or later is required for this version of bitbake")
  27. import os
  28. import bb.msg
  29. if "BBDEBUG" in os.environ:
  30. level = int(os.environ["BBDEBUG"])
  31. if level:
  32. bb.msg.set_debug_level(level)
  33. # Messaging convenience functions
  34. def plain(*args):
  35. bb.msg.plain(''.join(args))
  36. def debug(lvl, *args):
  37. bb.msg.debug(lvl, None, ''.join(args))
  38. def note(*args):
  39. bb.msg.note(1, None, ''.join(args))
  40. def warn(*args):
  41. bb.msg.warn(None, ''.join(args))
  42. def error(*args):
  43. bb.msg.error(None, ''.join(args))
  44. def fatal(*args):
  45. bb.msg.fatal(None, ''.join(args))
  46. def deprecated(func, name = None, advice = ""):
  47. """This is a decorator which can be used to mark functions
  48. as deprecated. It will result in a warning being emmitted
  49. when the function is used."""
  50. import warnings
  51. if advice:
  52. advice = ": %s" % advice
  53. if name is None:
  54. name = func.__name__
  55. def newFunc(*args, **kwargs):
  56. warnings.warn("Call to deprecated function %s%s." % (name,
  57. advice),
  58. category = PendingDeprecationWarning,
  59. stacklevel = 2)
  60. return func(*args, **kwargs)
  61. newFunc.__name__ = func.__name__
  62. newFunc.__doc__ = func.__doc__
  63. newFunc.__dict__.update(func.__dict__)
  64. return newFunc
  65. # For compatibility
  66. def deprecate_import(current, modulename, fromlist, renames = None):
  67. """Import objects from one module into another, wrapping them with a DeprecationWarning"""
  68. import sys
  69. module = __import__(modulename, fromlist = fromlist)
  70. for position, objname in enumerate(fromlist):
  71. obj = getattr(module, objname)
  72. newobj = deprecated(obj, "{0}.{1}".format(current, objname),
  73. "Please use {0}.{1} instead".format(modulename, objname))
  74. if renames:
  75. newname = renames[position]
  76. else:
  77. newname = objname
  78. setattr(sys.modules[current], newname, newobj)
  79. deprecate_import(__name__, "bb.fetch", ("MalformedUrl", "encodeurl", "decodeurl"))
  80. deprecate_import(__name__, "bb.utils", ("mkdirhier", "movefile", "copyfile", "which"))
  81. deprecate_import(__name__, "bb.utils", ["vercmp_string"], ["vercmp"])