web: Builder/Build: use a relative link to the welcome page
[buildbot.git] / buildbot / status / web / xmlrpc.py
blobb0f74b8333587f9df797fdf3ef0230e9f0a10fa7
2 from twisted.python import log
3 from twisted.web import xmlrpc
4 from buildbot.status.builder import Results
5 from itertools import count
7 class XMLRPCServer(xmlrpc.XMLRPC):
8 def __init__(self):
9 xmlrpc.XMLRPC.__init__(self)
11 def render(self, req):
12 # extract the IStatus and IControl objects for later use, since they
13 # come from the request object. They'll be the same each time, but
14 # they aren't available until the first request arrives.
15 self.status = req.site.buildbot_service.getStatus()
16 self.control = req.site.buildbot_service.getControl()
17 return xmlrpc.XMLRPC.render(self, req)
19 def xmlrpc_getAllBuildsInInterval(self, start, stop):
20 """Return a list of builds that have completed after the 'start'
21 timestamp and before the 'stop' timestamp. This looks at all
22 Builders.
24 The timestamps are integers, interpreted as standard unix timestamps
25 (seconds since epoch).
27 Each Build is returned as a tuple in the form::
28 (buildername, buildnumber, build_end, branchname, revision,
29 results, text)
31 The buildnumber is an integer. 'build_end' is an integer (seconds
32 since epoch) specifying when the build finished.
34 The branchname is a string, which may be an empty string to indicate
35 None (i.e. the default branch). The revision is a string whose
36 meaning is specific to the VC system in use, and comes from the
37 'got_revision' build property. The results are expressed as a string,
38 one of ('success', 'warnings', 'failure', 'exception'). The text is a
39 list of short strings that ought to be joined by spaces and include
40 slightly more data about the results of the build.
41 """
42 #log.msg("start: %s %s %s" % (start, type(start), start.__class__))
43 log.msg("getAllBuildsInInterval: %d - %d" % (start, stop))
44 all_builds = []
46 for builder_name in self.status.getBuilderNames():
47 builder = self.status.getBuilder(builder_name)
48 for build_number in count(1):
49 build = builder.getBuild(-build_number)
50 if not build:
51 break
52 if not build.isFinished():
53 continue
54 (build_start, build_end) = build.getTimes()
55 # in reality, builds are mostly ordered by start time. For
56 # the purposes of this method, we pretend that they are
57 # strictly ordered by end time, so that we can stop searching
58 # when we start seeing builds that are outside the window.
59 if build_end > stop:
60 continue # keep looking
61 if build_end < start:
62 break # stop looking
64 ss = build.getSourceStamp()
65 branch = ss.branch
66 if branch is None:
67 branch = ""
68 try:
69 revision = build.getProperty("got_revision")
70 except KeyError:
71 revision = ""
72 revision = "fake-rev"
74 answer = (builder_name,
75 build.getNumber(),
76 build_end,
77 branch,
78 revision,
79 Results[build.getResults()],
80 build.getText(),
82 all_builds.append((build_end, answer))
83 # we've gotten all the builds that we care about from this
84 # particular builder, so now we can continue on the next builder
86 # now we've gotten all the builds we're interested in. Sort them by
87 # end time.
88 all_builds.sort(lambda a,b: cmp(a[0], b[0]))
89 # and remove the timestamps
90 all_builds = [t[1] for t in all_builds]
92 log.msg("ready to go: %s" % (all_builds,))
94 return all_builds
96 def xmlrpc_getBuild(self, builder_name, build_number):
97 """Return information about a specific build.
99 """
100 builder = self.status.getBuilder(builder_name)
101 build = builder.getBuild(build_number)
102 info = {}
103 info['builder_name'] = builder.getName()
104 info['url'] = self.status.getURLForThing(build)
105 info['reason'] = build.getReason()
106 info['slavename'] = build.getSlavename()
107 info['results'] = build.getResults()
108 info['text'] = build.getText()
109 ss = build.getSourceStamp()
110 info['start'], info['end'] = build.getTimes()
112 info_steps = []
113 for s in build.getSteps():
114 stepinfo = {}
115 stepinfo['name'] = s.getName()
116 stepinfo['start'], stepinfo['end'] = s.getTimes()
117 stepinfo['results'] = s.getResults()
118 info_steps.append(stepinfo)
119 info['steps'] = info_steps
121 info_logs = []
122 for l in build.getLogs():
123 loginfo = {}
124 loginfo['name'] = l.getStep().getName() + "/" + l.getName()
125 #loginfo['text'] = l.getText()
126 loginfo['text'] = "HUGE"
127 info_logs.append(loginfo)
128 info['logs'] = info_logs
130 return info