summaryrefslogtreecommitdiff
path: root/bitbake/lib/bb/event.py
diff options
context:
space:
mode:
authorRichard Purdie <richard@openedhand.com>2006-05-09 15:44:08 +0000
committerRichard Purdie <richard@openedhand.com>2006-05-09 15:44:08 +0000
commit27dba1e6247ae48349aee1bce141a9eefaafaad1 (patch)
tree822235005ccbd2707f7874ad680dedc4df36760c /bitbake/lib/bb/event.py
parented234aca98d0867c7b32801fc63820b19cf67df9 (diff)
downloadopenembedded-core-27dba1e6247ae48349aee1bce141a9eefaafaad1.tar.gz
openembedded-core-27dba1e6247ae48349aee1bce141a9eefaafaad1.tar.bz2
openembedded-core-27dba1e6247ae48349aee1bce141a9eefaafaad1.zip
Update to bitbake 1.4.2 (latest stable branch release). This includes the caching speedups
git-svn-id: https://svn.o-hand.com/repos/poky/trunk@371 311d38ba-8fff-0310-9ca6-ca027cbcb966
Diffstat (limited to 'bitbake/lib/bb/event.py')
-rw-r--r--bitbake/lib/bb/event.py44
1 files changed, 28 insertions, 16 deletions
diff --git a/bitbake/lib/bb/event.py b/bitbake/lib/bb/event.py
index cbe6d2a11a..b1d12177c4 100644
--- a/bitbake/lib/bb/event.py
+++ b/bitbake/lib/bb/event.py
@@ -44,7 +44,13 @@ class Event:
NotHandled = 0
Handled = 1
-handlers = []
+
+Registered = 10
+AlreadyRegistered = 14
+
+# Internal
+_handlers = []
+_handlers_dict = {}
def tmpHandler(event):
"""Default handler for code events"""
@@ -57,7 +63,7 @@ def defaultTmpHandler():
def fire(event):
"""Fire off an Event"""
- for h in handlers:
+ for h in _handlers:
if type(h).__name__ == "code":
exec(h)
if tmpHandler(event) == Handled:
@@ -67,15 +73,22 @@ def fire(event):
return Handled
return NotHandled
-def register(handler):
+def register(name, handler):
"""Register an Event handler"""
+
+ # already registered
+ if name in _handlers_dict:
+ return AlreadyRegistered
+
if handler is not None:
# handle string containing python code
if type(handler).__name__ == "str":
- return _registerCode(handler)
-# prevent duplicate registration
- if not handler in handlers:
- handlers.append(handler)
+ _registerCode(handler)
+ else:
+ _handlers.append(handler)
+
+ _handlers_dict[name] = 1
+ return Registered
def _registerCode(handlerStr):
"""Register a 'code' Event.
@@ -88,24 +101,23 @@ def _registerCode(handlerStr):
tmp = "def tmpHandler(e):\n%s" % handlerStr
comp = bb.utils.better_compile(tmp, "tmpHandler(e)", "bb.event._registerCode")
# prevent duplicate registration
- if not comp in handlers:
- handlers.append(comp)
+ _handlers.append(comp)
-def remove(handler):
+def remove(name, handler):
"""Remove an Event handler"""
- for h in handlers:
- if type(handler).__name__ == "str":
- return _removeCode(handler)
- if handler is h:
- handlers.remove(handler)
+ _handlers_dict.pop(name)
+ if type(handler).__name__ == "str":
+ return _removeCode(handler)
+ else:
+ _handlers.remove(handler)
def _removeCode(handlerStr):
"""Remove a 'code' Event handler
Deprecated interface; call remove instead."""
tmp = "def tmpHandler(e):\n%s" % handlerStr
comp = bb.utils.better_compile(tmp, "tmpHandler(e)", "bb.event._removeCode")
- handlers.remove(comp)
+ _handlers.remove(comp)
def getName(e):
"""Returns the name of a class or class instance"""