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