msg.py 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #!/usr/bin/env python
  2. # ex:ts=4:sw=4:sts=4:et
  3. # -*- tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*-
  4. """
  5. BitBake 'msg' implementation
  6. Message handling infrastructure for bitbake
  7. """
  8. # Copyright (C) 2006 Richard Purdie
  9. #
  10. # This program is free software; you can redistribute it and/or modify
  11. # it under the terms of the GNU General Public License version 2 as
  12. # published by the Free Software Foundation.
  13. #
  14. # This program is distributed in the hope that it will be useful,
  15. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  17. # GNU General Public License for more details.
  18. #
  19. # You should have received a copy of the GNU General Public License along
  20. # with this program; if not, write to the Free Software Foundation, Inc.,
  21. # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  22. import sys, os, re, bb
  23. from bb import utils
  24. debug_level = {}
  25. verbose = False
  26. domain = bb.utils.Enum(
  27. 'Build',
  28. 'Cache',
  29. 'Collection',
  30. 'Data',
  31. 'Depends',
  32. 'Fetcher',
  33. 'Parsing',
  34. 'Provider',
  35. 'RunQueue',
  36. 'TaskData',
  37. 'Util')
  38. #
  39. # Message control functions
  40. #
  41. def set_debug_level(level):
  42. bb.msg.debug_level = {}
  43. for domain in bb.msg.domain:
  44. bb.msg.debug_level[domain] = level
  45. bb.msg.debug_level['default'] = level
  46. def set_verbose(level):
  47. bb.msg.verbose = level
  48. def set_debug_domains(domains):
  49. for domain in domains:
  50. found = False
  51. for ddomain in bb.msg.domain:
  52. if domain == str(ddomain):
  53. bb.msg.debug_level[ddomain] = bb.msg.debug_level[ddomain] + 1
  54. found = True
  55. if not found:
  56. std_warn("Logging domain %s is not valid, ignoring" % domain)
  57. #
  58. # Message handling functions
  59. #
  60. def debug(level, domain, msg, fn = None):
  61. if debug_level[domain] >= level:
  62. print 'DEBUG: ' + msg
  63. def note(level, domain, msg, fn = None):
  64. if level == 1 or verbose or debug_level[domain] >= 1:
  65. std_note(msg)
  66. def warn(domain, msg, fn = None):
  67. std_warn(msg)
  68. def error(domain, msg, fn = None):
  69. std_error(msg)
  70. def fatal(domain, msg, fn = None):
  71. std_fatal(msg)
  72. #
  73. # Compatibility functions for the original message interface
  74. #
  75. def std_debug(lvl, msg):
  76. if debug_level['default'] >= lvl:
  77. print 'DEBUG: ' + msg
  78. def std_note(msg):
  79. print 'NOTE: ' + msg
  80. def std_warn(msg):
  81. print 'WARNING: ' + msg
  82. def std_error(msg):
  83. print 'ERROR: ' + msg
  84. def std_fatal(msg):
  85. print 'ERROR: ' + msg
  86. sys.exit(1)