From 22a271aaa99daeb6b29c42c2c1dc670bf204310e Mon Sep 17 00:00:00 2001 From: Richard Purdie Date: Tue, 19 Jan 2010 14:48:19 +0000 Subject: bitbake-dev: Sync with upstream Signed-off-by: Richard Purdie --- bitbake-dev/lib/bb/event.py | 108 ++++++++++++++++---------------------------- 1 file changed, 40 insertions(+), 68 deletions(-) (limited to 'bitbake-dev/lib/bb/event.py') diff --git a/bitbake-dev/lib/bb/event.py b/bitbake-dev/lib/bb/event.py index 86b566febf..3062dc51be 100644 --- a/bitbake-dev/lib/bb/event.py +++ b/bitbake-dev/lib/bb/event.py @@ -24,27 +24,19 @@ BitBake build tools. import os, re import bb.utils +import pickle # This is the pid for which we should generate the event. This is set when # the runqueue forks off. worker_pid = 0 +worker_pipe = None class Event: """Base class for events""" - type = "Event" - def __init__(self, d): - self._data = d + def __init__(self): self.pid = worker_pid - def getData(self): - return self._data - - def setData(self, data): - self._data = data - - data = property(getData, setData, None, "data property") - NotHandled = 0 Handled = 1 @@ -56,33 +48,48 @@ _handlers = {} _ui_handlers = {} _ui_handler_seq = 0 -def fire(event): +def fire(event, d): """Fire off an Event""" + if worker_pid != 0: + worker_fire(event, d) + return + for handler in _handlers: h = _handlers[handler] + event.data = d if type(h).__name__ == "code": exec(h) tmpHandler(event) else: h(event) - - # Remove the event data elements for UI handlers - too much data otherwise - # They can request data if they need it - event.data = None - event._data = None + del event.data errors = [] for h in _ui_handlers: #print "Sending event %s" % event - classid = "%s.%s" % (event.__class__.__module__, event.__class__.__name__) try: - _ui_handlers[h].event.send((classid, event)) + # We use pickle here since it better handles object instances + # which xmlrpc's marshaller does not. Events *must* be serializable + # by pickle. + _ui_handlers[h].event.send((pickle.dumps(event))) except: errors.append(h) for h in errors: del _ui_handlers[h] +def worker_fire(event, d): + data = "" + pickle.dumps(event) + "" + if os.write(worker_pipe, data) != len (data): + print "Error sending event to server (short write)" + +def fire_from_worker(event, d): + if not event.startswith("") or not event.endswith(""): + print "Error, not an event" + return + event = pickle.loads(event[7:-8]) + bb.event.fire(event, d) + def register(name, handler): """Register an Event handler""" @@ -128,17 +135,17 @@ class ConfigParsed(Event): class RecipeParsed(Event): """ Recipe Parsing Complete """ - def __init__(self, fn, d): + def __init__(self, fn): self.fn = fn - Event.__init__(self, d) + Event.__init__(self) class StampUpdate(Event): """Trigger for any adjustment of the stamp files to happen""" - def __init__(self, targets, stampfns, d): + def __init__(self, targets, stampfns): self._targets = targets self._stampfns = stampfns - Event.__init__(self, d) + Event.__init__(self) def getStampPrefix(self): return self._stampfns @@ -149,30 +156,13 @@ class StampUpdate(Event): stampPrefix = property(getStampPrefix) targets = property(getTargets) -class PkgBase(Event): - """Base class for package events""" - - def __init__(self, t, d): - self._pkg = t - Event.__init__(self, d) - self._message = "package %s: %s" % (bb.data.getVar("P", d, 1), getName(self)[3:]) - - def getPkg(self): - return self._pkg - - def setPkg(self, pkg): - self._pkg = pkg - - pkg = property(getPkg, setPkg, None, "pkg property") - - class BuildBase(Event): """Base class for bbmake run events""" - def __init__(self, n, p, c, failures = 0): + def __init__(self, n, p, failures = 0): self._name = n self._pkgs = p - Event.__init__(self, c) + Event.__init__(self) self._failures = failures def getPkgs(self): @@ -204,20 +194,7 @@ class BuildBase(Event): cfg = property(getCfg, setCfg, None, "cfg property") -class DepBase(PkgBase): - """Base class for dependency events""" - def __init__(self, t, data, d): - self._dep = d - PkgBase.__init__(self, t, data) - - def getDep(self): - return self._dep - - def setDep(self, dep): - self._dep = dep - - dep = property(getDep, setDep, None, "dep property") class BuildStarted(BuildBase): @@ -228,18 +205,13 @@ class BuildCompleted(BuildBase): """bbmake build run completed""" -class UnsatisfiedDep(DepBase): - """Unsatisfied Dependency""" - -class RecursiveDep(DepBase): - """Recursive Dependency""" class NoProvider(Event): """No Provider for an Event""" - def __init__(self, item, data, runtime=False): - Event.__init__(self, data) + def __init__(self, item, runtime=False): + Event.__init__(self) self._item = item self._runtime = runtime @@ -252,8 +224,8 @@ class NoProvider(Event): class MultipleProviders(Event): """Multiple Providers""" - def __init__(self, item, candidates, data, runtime = False): - Event.__init__(self, data) + def __init__(self, item, candidates, runtime = False): + Event.__init__(self) self._item = item self._candidates = candidates self._is_runtime = runtime @@ -281,8 +253,8 @@ class ParseProgress(Event): Parsing Progress Event """ - def __init__(self, d, cached, parsed, skipped, masked, errors, total): - Event.__init__(self, d) + def __init__(self, cached, parsed, skipped, masked, errors, total): + Event.__init__(self) self.cached = cached self.parsed = parsed self.skipped = skipped @@ -296,7 +268,7 @@ class DepTreeGenerated(Event): Event when a dependency tree has been generated """ - def __init__(self, d, depgraph): - Event.__init__(self, d) + def __init__(self, depgraph): + Event.__init__(self) self._depgraph = depgraph -- cgit v1.2.3-54-g00ecf