~tom.prince/twisted-trac-integration/updated-force-builds.py

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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/usr/bin/python

"""
Force the Twisted buildmaster to run a builds on all supported builders for
a particular branch.
"""

import os, sys, pwd, urllib

import twisted
from twisted.internet import reactor
from twisted.python import log
from twisted.web import client, http_headers

VERSION = "0.1"

SUPPORTED_BUILDERS_URL = (
    "http://buildbot.twistedmatrix.com/supported-builders.txt")

USER_AGENT = (
    "force-builds.py/%(version)s (%(name)s; %(platform)s) Twisted/%(twisted)s "
    "Python/%(python)s" % dict(
        version=VERSION, name=os.name, platform=sys.platform,
        twisted=twisted.__version__, python=hex(sys.hexversion)))

def main():
    if len(sys.argv) == 3:
        branch, comments = sys.argv[1:]
        tests = None
    elif len(sys.argv) == 4:
        branch, comments, tests = sys.argv[1:]
    else:
        raise SystemExit("Usage: %s <branch> <comments> [test-case-name]" % (sys.argv[0],))

    log.startLogging(sys.stdout)
    if not branch.startswith('/branches/'):
        branch = '/branches/' + branch

    def forced(result):
        print 'Forced.'

    args = [
        ('username', 'twisted'),
        ('passwd', 'matrix'),
        ('forcescheduler', 'force-supported'),
        ('revision', ''),
        ('submit', 'Force Build'),
        ('branch', branch),
        ('test-case-name', tests),
        ('reason', '%s: %s' % (pwd.getpwuid(os.getuid())[0], comments))]

    agent = client.Agent(reactor, pool=client.HTTPConnectionPool(reactor))

    headers = http_headers.Headers({'user-agent': [USER_AGENT]})

    print 'Forcing...'
    url = "http://buildbot.twistedmatrix.com/builders/_all/forceall"
    url = url + '?' + '&'.join([k + '=' + urllib.quote(v) for (k, v) in args])
    d = agent.request("GET", url, headers)
    d.addCallback(forced)
    d.addErrback(log.err, "Build force failure")
    d.addCallback(lambda ign: reactor.stop())
    reactor.run()
    print 'See http://buildbot.twistedmatrix.com/boxes-supported?branch=%s' % (branch,)


if __name__ == '__main__':
    main()