Last active
December 16, 2015 18:19
-
-
Save MichaelMayorov/5476434 to your computer and use it in GitHub Desktop.
Template for future Buildbot AMP slave-server
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from twisted.protocols import amp | |
class GetInfo(amp.Command): | |
arguments = [] | |
response = [ | |
('commands', amp.AmpList([ | |
('name', amp.String()), | |
('version', amp.Integer()), | |
]) | |
), | |
('environ', amp.AmpList([ | |
('key', amp.String()), | |
('value', amp.String()), | |
]) | |
), | |
('system', amp.String()), | |
('basedir', amp.String()), | |
('version', amp.String()), | |
] | |
# What arguments should be passed? | |
# What values it should return? | |
class SetBuilderList(amp.Command): | |
""" | |
Given a list of builders and their build directories, ensures that those | |
builders, and only those builders, are running. | |
This can be called after the initial connection is established, with a new | |
list, to add or remove builders. | |
""" | |
arguments = [amp.AmpList([ | |
('builder_name', amp.String()), | |
('dir', amp.String()), | |
]) | |
response = [('result', amp.Integer())] # 0 for success, 1 or others for errors | |
class RemotePrint(amp.Command): | |
""" | |
Adds a message to the slave logfile | |
""" | |
arguments = [('message', amp.String())] | |
response = [('result', amp.Integer())] # 0 if OK, 1 if not | |
# Following classes declare arguments and responses of bot.SlaveBuilder methods | |
# with "remote_" prefix | |
class SlaveBuilderStartBuild(amp.Command): | |
""" | |
This is invoked before the first step of any new build is run. It | |
doesn't do much, but masters call it so it's still here. | |
""" | |
arguments = [] | |
response = [('result', amp.Integer())] # 0 if OK, 1 if not | |
class SlaveBuilderStartCommand(amp.Command): | |
arguments = [('command', amp.String()), ('args', amp.String())] | |
response = [('result', amp.Integer())] # Commands could be runned in background, do we need this? | |
class SlaveBuilderInterruptCommand(amp.Command): | |
arguments = [('why', amp.String())] | |
response = [('result', amp.Integer())] | |
class SlaveBuilderShutdown(amp.Command): | |
arguments = [] | |
response = [('result', amp.Integer())] | |
class Bot(amp.AMP): | |
def get_info(self): | |
commands = [ | |
{'name': 'shell', 'version': 1}, | |
{'name': 'uploadFile', 'version': 1}, | |
{'name': 'uploadDirectory', 'version': 1}, | |
{'name': 'downloadFile', 'version': 1}, | |
{'name': 'svn', 'version': 1}, | |
{'name': 'bk', 'version': 1}, | |
{'name': 'cvs', 'version': 1}, | |
{'name': 'darcs', 'version': 1}, | |
{'name': 'git', 'version': 1}, | |
{'name': 'repo', 'version': 1}, | |
{'name': 'bzr', 'version': 1}, | |
{'name': 'hg', 'version': 1}, | |
{'name': 'p4', 'version': 1}, | |
{'name': 'mtn', 'version': 1}, | |
{'name': 'mkdir', 'version': 1}, | |
{'name': 'rmdir', 'version': 1}, | |
{'name': 'cpdir', 'version': 1}, | |
{'name': 'stat', 'version': 1}, | |
] | |
environ = [{'key': 'foo', 'value': 'bar'}, {'key': 'asd', 'value': 'qwe'}] | |
system = 'SYSTEM' | |
basedir= 'BASEDIR' | |
version = '0.1' | |
return {'commands': commands, 'environ': environ, 'system': system, | |
'basedir': basedir, 'version': version, | |
} | |
GetInfo.responder(get_info) | |
# What it should do here? | |
def set_builder_list(self) | |
return [] | |
SetBuilderList.responder(set_builder_list) | |
def remote_print(self, message): | |
print "Message: \"%s\"" % message | |
return {'result': 0} | |
RemotePrint.responder(remote_print) | |
def main(): | |
from twisted.internet import reactor | |
from twisted.internet.protocol import Factory | |
pf = Factory() | |
pf.protocol = Bot | |
reactor.listenTCP(1234, pf) | |
print 'started' | |
reactor.run() | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment