PageRenderTime 122ms CodeModel.GetById 40ms app.highlight 7ms RepoModel.GetById 74ms app.codeStats 0ms

/kai/lib/buildbot.py

https://bitbucket.org/bbangert/kai/
Python | 45 lines | 34 code | 3 blank | 8 comment | 4 complexity | c59bbd1a4c31a1f3d8e5c6ac496fd613 MD5 | raw file
 1"""Query and interact with the buildbot via XMLRPC for info"""
 2import xmlrpclib
 3from datetime import datetime
 4
 5import pylons
 6from pytz import timezone
 7
 8buildbot_server = xmlrpclib.Server(pylons.config['buildbot_server'])
 9day = 60 * 60 * 24
10
11def recent_builds(num_builds=2):
12    """Fetchs all builds for num_builds, and sorts them into
13    an organized dict
14
15    For performance, this function caches itself for 30 seconds at a
16    time
17
18    """
19    mycache = pylons.cache.get_cache(__file__ + 'recent_builds')
20    def get_items():
21        results = buildbot_server.getAllLastBuilds(num_builds)
22        builders = {}
23        tzinfo = timezone('US/Pacific')
24        for res in results:
25            start = datetime.fromtimestamp(res[2], tzinfo)
26            end = datetime.fromtimestamp(res[3], tzinfo)
27            elapsed = res[3] - res[2]
28            build = dict(name=res[0], version=res[1], 
29                         start=start, end=end, branch=res[4],
30                         revision=res[5], results=res[6], text=res[7],
31                         reasons=res[8], elapsed=elapsed)
32            builders.setdefault(build['name'], []).append(build)
33        for ver, items in builders.items():
34            builders[ver] = sorted(items, cmp=lambda x,y: cmp(y['end'], x['end']))
35        return builders
36    return mycache.get_value(key='', createfunc=get_items, expiretime=30)
37
38def build_info(name, build_number):
39    mycache = pylons.cache.get_cache(__file__ + 'build_info')
40    if isinstance(build_number, basestring):
41        build_number = int(build_number)
42    def get_build():
43        results = buildbot_server.getBuild(name, build_number)
44        return results
45    return mycache.get_value(key='%s%s' % (name, build_number), createfunc=get_build, expiretime=day)