From 14229b1d2aee659fdee82051dde4f67420172970 Mon Sep 17 00:00:00 2001 From: Pedro Alvarez Date: Sun, 6 Mar 2016 20:36:44 +0000 Subject: Store artifacts and mark them as unbuilt Change-Id: Id3cbbbadb0d78e8c12a9ba7b16c7bd517a0a3fc1 --- gear/client.py | 50 +++++++++++++++++++++++++++++++++++++++++++++++--- 1 file 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) -- cgit v1.2.1