1 from twisted.python import log
2 from twisted.web import xmlrpc
3 from buildbot.status.builder import Results
4 from itertools import count
5
9
16
22
29
31 """Return the last N completed builds for all builders.
32
33 'num_builds' is the number of builds for each builder to
34 return
35
36 """
37 all_builds = []
38 for name in self.status.getBuilderNames():
39 all_builds.extend(self.xmlrpc_getLastBuilds(name, num_builds))
40 return all_builds
41
43 """Return the last N completed builds for the given builder.
44 'builder_name' is the name of the builder to query
45 'num_builds' is the number of builds to return
46
47 Each build is returned in the same form as xmlrpc_getAllBuildsInInterval
48 """
49 log.msg("getLastBuilds: %s - %d" % (builder_name, num_builds))
50 builder = self.status.getBuilder(builder_name)
51 all_builds = []
52 for build_number in range(1, num_builds+1):
53 build = builder.getBuild(-build_number)
54 if not build:
55 break
56 if not build.isFinished():
57 continue
58 (build_start, build_end) = build.getTimes()
59
60 ss = build.getSourceStamp()
61 branch = ss.branch
62 if branch is None:
63 branch = ""
64 try:
65 revision = build.getProperty("got_revision")
66 except KeyError:
67 revision = ""
68 revision = str(revision)
69
70 result = Results[build.getResults()]
71 if result == 'failure':
72 fail_names = result = build.getText()[1:]
73 reasons = []
74 for s in build.getSteps():
75 if s.getName() in fail_names:
76 reasons.append(s.getText())
77 else:
78 result = build.getText()
79 reasons = []
80 answer = (builder_name,
81 build.getNumber(),
82 build_start,
83 build_end,
84 branch,
85 revision,
86 Results[build.getResults()],
87 result,
88 reasons,
89 )
90 all_builds.append((build_end, answer))
91
92
93
94 all_builds.sort(lambda a,b: cmp(a[0], b[0]))
95
96 all_builds = [t[1] for t in all_builds]
97
98 log.msg("ready to go: %s" % (all_builds,))
99
100 return all_builds
101
102
104 """Return a list of builds that have completed after the 'start'
105 timestamp and before the 'stop' timestamp. This looks at all
106 Builders.
107
108 The timestamps are integers, interpreted as standard unix timestamps
109 (seconds since epoch).
110
111 Each Build is returned as a tuple in the form::
112 (buildername, buildnumber, build_end, branchname, revision,
113 results, text)
114
115 The buildnumber is an integer. 'build_end' is an integer (seconds
116 since epoch) specifying when the build finished.
117
118 The branchname is a string, which may be an empty string to indicate
119 None (i.e. the default branch). The revision is a string whose
120 meaning is specific to the VC system in use, and comes from the
121 'got_revision' build property. The results are expressed as a string,
122 one of ('success', 'warnings', 'failure', 'exception'). The text is a
123 list of short strings that ought to be joined by spaces and include
124 slightly more data about the results of the build.
125 """
126
127 log.msg("getAllBuildsInInterval: %d - %d" % (start, stop))
128 all_builds = []
129
130 for builder_name in self.status.getBuilderNames():
131 builder = self.status.getBuilder(builder_name)
132 for build_number in count(1):
133 build = builder.getBuild(-build_number)
134 if not build:
135 break
136 if not build.isFinished():
137 continue
138 (build_start, build_end) = build.getTimes()
139
140
141
142
143 if build_end > stop:
144 continue
145 if build_end < start:
146 break
147
148 ss = build.getSourceStamp()
149 branch = ss.branch
150 if branch is None:
151 branch = ""
152 try:
153 revision = build.getProperty("got_revision")
154 except KeyError:
155 revision = ""
156 revision = str(revision)
157
158 answer = (builder_name,
159 build.getNumber(),
160 build_end,
161 branch,
162 revision,
163 Results[build.getResults()],
164 build.getText(),
165 )
166 all_builds.append((build_end, answer))
167
168
169
170
171
172 all_builds.sort(lambda a,b: cmp(a[0], b[0]))
173
174 all_builds = [t[1] for t in all_builds]
175
176 log.msg("ready to go: %s" % (all_builds,))
177
178 return all_builds
179
237