diff options
Diffstat (limited to 'bitbake/lib/bb/event.py')
-rw-r--r-- | bitbake/lib/bb/event.py | 42 |
1 files changed, 31 insertions, 11 deletions
diff --git a/bitbake/lib/bb/event.py b/bitbake/lib/bb/event.py index 9a07ed5c0a..ec6446d64c 100644 --- a/bitbake/lib/bb/event.py +++ b/bitbake/lib/bb/event.py | |||
@@ -37,6 +37,8 @@ import bb.utils | |||
37 | worker_pid = 0 | 37 | worker_pid = 0 |
38 | worker_pipe = None | 38 | worker_pipe = None |
39 | 39 | ||
40 | logger = logging.getLogger('BitBake.Event') | ||
41 | |||
40 | class Event(object): | 42 | class Event(object): |
41 | """Base class for events""" | 43 | """Base class for events""" |
42 | 44 | ||
@@ -58,18 +60,35 @@ _ui_handler_seq = 0 | |||
58 | bb.utils._context["NotHandled"] = NotHandled | 60 | bb.utils._context["NotHandled"] = NotHandled |
59 | bb.utils._context["Handled"] = Handled | 61 | bb.utils._context["Handled"] = Handled |
60 | 62 | ||
63 | def execute_handler(name, handler, event, d): | ||
64 | event.data = d | ||
65 | try: | ||
66 | ret = handler(event) | ||
67 | except Exception: | ||
68 | etype, value, tb = sys.exc_info() | ||
69 | logger.error("Execution of event handler '%s' failed" % name, | ||
70 | exc_info=(etype, value, tb.tb_next)) | ||
71 | raise | ||
72 | except SystemExit as exc: | ||
73 | if exc.code != 0: | ||
74 | logger.error("Execution of event handler '%s' failed" % name) | ||
75 | raise | ||
76 | finally: | ||
77 | del event.data | ||
78 | |||
79 | if ret is not None: | ||
80 | warnings.warn("Using Handled/NotHandled in event handlers is deprecated", | ||
81 | DeprecationWarning, stacklevel = 2) | ||
82 | |||
61 | def fire_class_handlers(event, d): | 83 | def fire_class_handlers(event, d): |
62 | if isinstance(event, logging.LogRecord): | 84 | if isinstance(event, logging.LogRecord): |
63 | return | 85 | return |
64 | 86 | ||
65 | for handler in _handlers.itervalues(): | 87 | for name, handler in _handlers.iteritems(): |
66 | event.data = d | 88 | try: |
67 | ret = handler(event) | 89 | execute_handler(name, handler, event, d) |
68 | if ret is not None: | 90 | except BaseException: |
69 | warnings.warn("Using Handled/NotHandled in event handlers is deprecated", | 91 | continue |
70 | DeprecationWarning, stacklevel = 2) | ||
71 | |||
72 | del event.data | ||
73 | 92 | ||
74 | ui_queue = [] | 93 | ui_queue = [] |
75 | @atexit.register | 94 | @atexit.register |
@@ -141,11 +160,12 @@ def register(name, handler): | |||
141 | if handler is not None: | 160 | if handler is not None: |
142 | # handle string containing python code | 161 | # handle string containing python code |
143 | if isinstance(handler, basestring): | 162 | if isinstance(handler, basestring): |
144 | tmp = "def tmpHandler(e):\n%s" % handler | 163 | tmp = "def %s(e):\n%s" % (name, handler) |
145 | comp = bb.utils.better_compile(tmp, "tmpHandler(e)", "bb.event._registerCode") | 164 | comp = bb.utils.better_compile(tmp, "%s(e)" % name, |
165 | "bb.event._registerCode") | ||
146 | env = {} | 166 | env = {} |
147 | bb.utils.simple_exec(comp, env) | 167 | bb.utils.simple_exec(comp, env) |
148 | func = bb.utils.better_eval("tmpHandler", env) | 168 | func = bb.utils.better_eval(name, env) |
149 | _handlers[name] = func | 169 | _handlers[name] = func |
150 | else: | 170 | else: |
151 | _handlers[name] = handler | 171 | _handlers[name] = handler |