import gear import sys import json import threading import requests import time import signal import urlparse import distbuild #TODO: values from settings cache_server = 'http://cache.baserock.org:8080' # Artifact build states. These are used to loosely track the state of the # remote cache. UNBUILT = 'not-built' BUILDING = 'building' BUILT = 'built' import logging logging.basicConfig() class GearRequestClient(gear.Client): def __init__(self): super(GearRequestClient, self).__init__() self.finished = False def handleWorkComplete(self, packet): job = super(GearRequestClient, self).handleWorkComplete(packet) print "Build workcomplete" self.controller._mark_artifact_as_built(job.data[-1]) self.finished = True return job def handleWorkFailed(self, packet): job = super(GearRequestClient, self).handleWorkFailed(packet) print "Build workfailed" self.controller._mark_artifact_as_built(job.data[-1]) self.finished = True return job def handleWorkData(self, packet): job = super(GearRequestClient, self).handleWorkData(packet) print job.data[-1] job.data = [] return job request = {} request['repo'] = "baserock:baserock/definitions" request['ref'] = "fbce45e45da79e5c35341845ec3b3d7c321e6ff2" request['system'] = "systems/minimal-system-x86_64-generic.morph" json_request = json.dumps(request) print json_request gear_request_client = GearRequestClient() gear_request_client.addServer('localhost') gear_request_client.waitForServer() job = gear.Job("build-request", json_request) gear_request_client.submitJob(job) while not gear_request_client.finished: try: print "waiting" time.sleep(3) except KeyboardInterrupt: print "Ctrl + C: asking tasks to exit nicely...\n" exit(0)