summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPedro Alvarez <pedro.alvarez@codethink.co.uk>2016-03-06 20:36:44 +0000
committerPedro Alvarez <pedro.alvarez@codethink.co.uk>2016-03-27 11:53:01 +0000
commit14229b1d2aee659fdee82051dde4f67420172970 (patch)
treec412484c02435b38b94d74cf8f4ff92b3e9b45af
parent51303de0703b7cfc604214da6585c504c50f54b6 (diff)
downloadmorph-14229b1d2aee659fdee82051dde4f67420172970.tar.gz
Store artifacts and mark them as unbuilt
Change-Id: Id3cbbbadb0d78e8c12a9ba7b16c7bd517a0a3fc1
-rw-r--r--gear/client.py50
1 files changed, 47 insertions, 3 deletions
diff --git a/gear/client.py b/gear/client.py
index 4ef06d26..561cd9a7 100644
--- a/gear/client.py
+++ b/gear/client.py
@@ -3,6 +3,13 @@ import sys
import json
import distbuild
+
+# Artifact build states. These are used to loosely track the state of the
+# remote cache.
+UNBUILT = 'not-built'
+BUILDING = 'building'
+BUILT = 'built'
+
gear.Server()
class aGearmanClient(gear.Client):
@@ -15,8 +22,17 @@ class aGearmanClient(gear.Client):
job = super(aGearmanClient, self).handleWorkComplete(packet)
print "workcomplete"
self.finished = True
- artifact = distbuild.decode_artifact_reference(job.data[-1])
- print artifact.dependencies[0].dependencies
+ print "Decoding artifact received"
+ self.artifact = distbuild.decode_artifact_reference(job.data[-1])
+ print "Decoding artifact received done"
+ # Mark everything as unbuilt to begin with. We'll query the actua
+ # state from the cache in self._query_cache_state().
+ def set_initial_state(artifact):
+ artifact.state = UNBUILT
+ print "Setting them as unbuilt"
+ map_build_graph(self.artifact, set_initial_state)
+ print "Setting them as unbuilt done"
+
return job
def handleWorkData(self, packet):
@@ -39,6 +55,34 @@ class aGearmanClient(gear.Client):
job = super(aGearmanClient, self).handleDisconnect(job)
print "disconnect"
+
+
+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()
client.addServer('localhost')
client.waitForServer() # Wait for at least one server to be connected
@@ -51,8 +95,8 @@ build_graph_request['system'] = "systems/minimal-system-x86_64-generic.morph"
s=json.dumps(build_graph_request)
+print "Json produced: "
print s
-print "json produced"
job = gear.Job("build-graph", s)
client.submitJob(job)