summaryrefslogtreecommitdiff
path: root/gear/client.py
diff options
context:
space:
mode:
Diffstat (limited to 'gear/client.py')
-rw-r--r--gear/client.py80
1 files changed, 46 insertions, 34 deletions
diff --git a/gear/client.py b/gear/client.py
index 561cd9a7..17202cdd 100644
--- a/gear/client.py
+++ b/gear/client.py
@@ -10,18 +10,17 @@ UNBUILT = 'not-built'
BUILDING = 'building'
BUILT = 'built'
+import logging
+logging.basicConfig()
+
gear.Server()
-class aGearmanClient(gear.Client):
+class theController():
def __init__(self):
- super(aGearmanClient, self).__init__()
- print "init"
- self.finished = False
+ self.graph_client = aGearmanClient(self)
+ self.artifact = None
- def handleWorkComplete(self, packet):
- job = super(aGearmanClient, self).handleWorkComplete(packet)
- print "workcomplete"
- self.finished = True
+ def _process_build_graph(self, packet):
print "Decoding artifact received"
self.artifact = distbuild.decode_artifact_reference(job.data[-1])
print "Decoding artifact received done"
@@ -30,9 +29,45 @@ class aGearmanClient(gear.Client):
def set_initial_state(artifact):
artifact.state = UNBUILT
print "Setting them as unbuilt"
- map_build_graph(self.artifact, set_initial_state)
+ self._map_build_graph(self.artifact, set_initial_state)
print "Setting them as unbuilt done"
+ def _map_build_graph(self, artifact, callback, components=[]):
+ """Run callback on each artifact in the build graph and return result.
+
+ If components is given, then only look at the components given and
+ their dependencies. Also, return a list of the components after they
+ have had callback called on them.
+
+ """
+ result = []
+ mapped_components = []
+ done = set()
+ if components:
+ queue = list(components)
+ else:
+ queue = [artifact]
+ while queue:
+ a = queue.pop()
+ if a not in done:
+ result.append(callback(a))
+ queue.extend(a.dependencies)
+ done.add(a)
+ if a in components:
+ mapped_components.append(a)
+ return result, mapped_components
+
+
+class aGearmanClient(gear.Client):
+ def __init__(self, controller):
+ super(aGearmanClient, self).__init__()
+ self.controller = controller
+ self.finished = False
+
+ def handleWorkComplete(self, packet):
+ job = super(aGearmanClient, self).handleWorkComplete(packet)
+ print "workcomplete"
+ self.controller._process_build_graph(packet)
return job
def handleWorkData(self, packet):
@@ -57,33 +92,10 @@ class aGearmanClient(gear.Client):
-def map_build_graph(artifact, callback, components=[]):
- """Run callback on each artifact in the build graph and return result.
-
- If components is given, then only look at the components given and
- their dependencies. Also, return a list of the components after they
- have had callback called on them.
-
- """
- result = []
- mapped_components = []
- done = set()
- if components:
- queue = list(components)
- else:
- queue = [artifact]
- while queue:
- a = queue.pop()
- if a not in done:
- result.append(callback(a))
- queue.extend(a.dependencies)
- done.add(a)
- if a in components:
- mapped_components.append(a)
- return result, mapped_components
-client = aGearmanClient()
+controller = theController()
+client = controller.graph_client
client.addServer('localhost')
client.waitForServer() # Wait for at least one server to be connected
print "server connected"