summaryrefslogtreecommitdiff
path: root/source/bottlerock.py
blob: 9b7915f3d80c95387cc728d3e60fd0e6bfdc618a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#!/usr/bin/env python2.7

# This script provides an interface for sandboxed code to trigger buildbot
# using plain HTTP

from bottle import post, request, run, HTTPResponse

trigger_names = [
        'repo_update',
        'definitions_update',
        'build_complete']

def call_trigger(trigger_name,*args):
    global trigger_names
    assert trigger_name in trigger_names
    import subprocess
    trigger_cmd = ['sh','source/%s' % trigger_name]
    for arg in args: trigger_cmd.append(arg)
    trigger_ballback = subprocess.Popen(trigger_cmd)
    return trigger_callback.wait()

@post('/repo_update')
def repo_update():
    repo_name = request.forms.get("repo_name")
    if not repo_name:
        return HTTPResponse(
                status=400,
                body="400: A repo_name is required")
    if call_trigger('repo_update',repo_name):
        return HTTPResponse(status=500)
    return 0

@post('/definitions_update')
def definitions_update():
    pass

@post('/build_complete')
def repo_update():
    pass

if __name__ == '__main__':
    run(host='localhost', port=8080, debug=True)