Merge branch 'web-improvements' of git://github.com/catlee/buildbot
[buildbot.git] / buildbot / interfaces.py
blobcb0859f8b749e570a00b9e53f64211ca2d819a7d
2 """Interface documentation.
4 Define the interfaces that are implemented by various buildbot classes.
5 """
7 from zope.interface import Interface, Attribute
9 # exceptions that can be raised while trying to start a build
10 class NoSlaveError(Exception):
11 pass
12 class BuilderInUseError(Exception):
13 pass
14 class BuildSlaveTooOldError(Exception):
15 pass
16 class LatentBuildSlaveFailedToSubstantiate(Exception):
17 pass
19 # other exceptions
20 class BuildbotNotRunningError(Exception):
21 pass
23 class IChangeSource(Interface):
24 """Object which feeds Change objects to the changemaster. When files or
25 directories are changed and the version control system provides some
26 kind of notification, this object should turn it into a Change object
27 and pass it through::
29 self.changemaster.addChange(change)
30 """
32 def start():
33 """Called when the buildmaster starts. Can be used to establish
34 connections to VC daemons or begin polling."""
36 def stop():
37 """Called when the buildmaster shuts down. Connections should be
38 terminated, polling timers should be canceled."""
40 def describe():
41 """Should return a string which briefly describes this source. This
42 string will be displayed in an HTML status page."""
44 class IScheduler(Interface):
45 """I watch for Changes in the source tree and decide when to trigger
46 Builds. I create BuildSet objects and submit them to the BuildMaster. I
47 am a service, and the BuildMaster is always my parent.
49 @ivar properties: properties to be applied to all builds started by this
50 scheduler
51 @type properties: L<buildbot.process.properties.Properties>
52 """
54 def addChange(change):
55 """A Change has just been dispatched by one of the ChangeSources.
56 Each Scheduler will receive this Change. I may decide to start a
57 build as a result, or I might choose to ignore it."""
59 def listBuilderNames():
60 """Return a list of strings indicating the Builders that this
61 Scheduler might feed."""
63 def getPendingBuildTimes():
64 """Return a list of timestamps for any builds that are waiting in the
65 tree-stable-timer queue. This is only relevant for Change-based
66 schedulers, all others can just return an empty list."""
67 # TODO: it might be nice to make this into getPendingBuildSets, which
68 # would let someone subscribe to the buildset being finished.
69 # However, the Scheduler doesn't actually create the buildset until
70 # it gets submitted, so doing this would require some major rework.
72 class IUpstreamScheduler(Interface):
73 """This marks an IScheduler as being eligible for use as the 'upstream='
74 argument to a buildbot.scheduler.Dependent instance."""
76 def subscribeToSuccessfulBuilds(target):
77 """Request that the target callbable be invoked after every
78 successful buildset. The target will be called with a single
79 argument: the SourceStamp used by the successful builds."""
81 def listBuilderNames():
82 """Return a list of strings indicating the Builders that this
83 Scheduler might feed."""
85 class IDownstreamScheduler(Interface):
86 """This marks an IScheduler to be listening to other schedulers.
87 On reconfigs, these might get notified to check if their upstream
88 scheduler are stil the same."""
90 def checkUpstreamScheduler():
91 """Check if the upstream scheduler is still alive, and if not,
92 get a new upstream object from the master."""
95 class ISourceStamp(Interface):
96 """
97 @cvar branch: branch from which source was drawn
98 @type branch: string or None
100 @cvar revision: revision of the source, or None to use CHANGES
101 @type revision: varies depending on VC
103 @cvar patch: patch applied to the source, or None if no patch
104 @type patch: None or tuple (level diff)
106 @cvar changes: the source step should check out hte latest revision
107 in the given changes
108 @type changes: tuple of L{buildbot.changes.changes.Change} instances,
109 all of which are on the same branch
112 def canBeMergedWith(self, other):
114 Can this SourceStamp be merged with OTHER?
117 def mergeWith(self, others):
118 """Generate a SourceStamp for the merger of me and all the other
119 BuildRequests. This is called by a Build when it starts, to figure
120 out what its sourceStamp should be."""
122 def getAbsoluteSourceStamp(self, got_revision):
123 """Get a new SourceStamp object reflecting the actual revision found
124 by a Source step."""
126 def getText(self):
127 """Returns a list of strings to describe the stamp. These are
128 intended to be displayed in a narrow column. If more space is
129 available, the caller should join them together with spaces before
130 presenting them to the user."""
132 class IEmailSender(Interface):
133 """I know how to send email, and can be used by other parts of the
134 Buildbot to contact developers."""
135 pass
137 class IEmailLookup(Interface):
138 def getAddress(user):
139 """Turn a User-name string into a valid email address. Either return
140 a string (with an @ in it), None (to indicate that the user cannot
141 be reached by email), or a Deferred which will fire with the same."""
143 class IStatus(Interface):
144 """I am an object, obtainable from the buildmaster, which can provide
145 status information."""
147 def getProjectName():
148 """Return the name of the project that this Buildbot is working
149 for."""
150 def getProjectURL():
151 """Return the URL of this Buildbot's project."""
152 def getBuildbotURL():
153 """Return the URL of the top-most Buildbot status page, or None if
154 this Buildbot does not provide a web status page."""
155 def getURLForThing(thing):
156 """Return the URL of a page which provides information on 'thing',
157 which should be an object that implements one of the status
158 interfaces defined in L{buildbot.interfaces}. Returns None if no
159 suitable page is available (or if no Waterfall is running)."""
161 def getChangeSources():
162 """Return a list of IChangeSource objects."""
164 def getChange(number):
165 """Return an IChange object."""
167 def getSchedulers():
168 """Return a list of ISchedulerStatus objects for all
169 currently-registered Schedulers."""
171 def getBuilderNames(categories=None):
172 """Return a list of the names of all current Builders."""
173 def getBuilder(name):
174 """Return the IBuilderStatus object for a given named Builder. Raises
175 KeyError if there is no Builder by that name."""
177 def getSlaveNames():
178 """Return a list of buildslave names, suitable for passing to
179 getSlave()."""
180 def getSlave(name):
181 """Return the ISlaveStatus object for a given named buildslave."""
183 def getBuildSets():
184 """Return a list of active (non-finished) IBuildSetStatus objects."""
186 def generateFinishedBuilds(builders=[], branches=[],
187 num_builds=None, finished_before=None,
188 max_search=200):
189 """Return a generator that will produce IBuildStatus objects each
190 time you invoke its .next() method, starting with the most recent
191 finished build and working backwards.
193 @param builders: this is a list of Builder names, and the generator
194 will only produce builds that ran on the given
195 Builders. If the list is empty, produce builds from
196 all Builders.
198 @param branches: this is a list of branch names, and the generator
199 will only produce builds that used the given
200 branches. If the list is empty, produce builds from
201 all branches.
203 @param num_builds: the generator will stop after providing this many
204 builds. The default of None means to produce as
205 many builds as possible.
207 @type finished_before: int: a timestamp, seconds since the epoch
208 @param finished_before: if provided, do not produce any builds that
209 finished after the given timestamp.
211 @type max_search: int
212 @param max_search: this method may have to examine a lot of builds
213 to find some that match the search parameters,
214 especially if there aren't any matching builds.
215 This argument imposes a hard limit on the number
216 of builds that will be examined within any given
217 Builder.
220 def subscribe(receiver):
221 """Register an IStatusReceiver to receive new status events. The
222 receiver will immediately be sent a set of 'builderAdded' messages
223 for all current builders. It will receive further 'builderAdded' and
224 'builderRemoved' messages as the config file is reloaded and builders
225 come and go. It will also receive 'buildsetSubmitted' messages for
226 all outstanding BuildSets (and each new BuildSet that gets
227 submitted). No additional messages will be sent unless the receiver
228 asks for them by calling .subscribe on the IBuilderStatus objects
229 which accompany the addedBuilder message."""
231 def unsubscribe(receiver):
232 """Unregister an IStatusReceiver. No further status messgaes will be
233 delivered."""
235 class IBuildSetStatus(Interface):
236 """I represent a set of Builds, each run on a separate Builder but all
237 using the same source tree."""
239 def getSourceStamp():
240 """Return a SourceStamp object which can be used to re-create
241 the source tree that this build used.
243 This method will return None if the source information is no longer
244 available."""
245 pass
246 def getReason():
247 pass
248 def getID():
249 """Return the BuildSet's ID string, if any. The 'try' feature uses a
250 random string as a BuildSetID to relate submitted jobs with the
251 resulting BuildSet."""
252 def getResponsibleUsers():
253 pass # not implemented
254 def getInterestedUsers():
255 pass # not implemented
256 def getBuilderNames():
257 """Return a list of the names of all Builders on which this set will
258 do builds."""
259 def getBuildRequests():
260 """Return a list of IBuildRequestStatus objects that represent my
261 component Builds. This list might correspond to the Builders named by
262 getBuilderNames(), but if builder categories are used, or 'Builder
263 Aliases' are implemented, then they may not."""
264 def isFinished():
265 pass
266 def waitUntilSuccess():
267 """Return a Deferred that fires (with this IBuildSetStatus object)
268 when the outcome of the BuildSet is known, i.e., upon the first
269 failure, or after all builds complete successfully."""
270 def waitUntilFinished():
271 """Return a Deferred that fires (with this IBuildSetStatus object)
272 when all builds have finished."""
273 def getResults():
274 pass
276 class IBuildRequestStatus(Interface):
277 """I represent a request to build a particular set of source code on a
278 particular Builder. These requests may be merged by the time they are
279 finally turned into a Build."""
281 def getSourceStamp():
282 """Return a SourceStamp object which can be used to re-create
283 the source tree that this build used. This method will
284 return an absolute SourceStamp if possible, and its results
285 may change as the build progresses. Specifically, a "HEAD"
286 build may later be more accurately specified by an absolute
287 SourceStamp with the specific revision information.
289 This method will return None if the source information is no longer
290 available."""
291 pass
292 def getBuilderName():
293 pass
294 def getBuilds():
295 """Return a list of IBuildStatus objects for each Build that has been
296 started in an attempt to satify this BuildRequest."""
298 def subscribe(observer):
299 """Register a callable that will be invoked (with a single
300 IBuildStatus object) for each Build that is created to satisfy this
301 request. There may be multiple Builds created in an attempt to handle
302 the request: they may be interrupted by the user or abandoned due to
303 a lost slave. The last Build (the one which actually gets to run to
304 completion) is said to 'satisfy' the BuildRequest. The observer will
305 be called once for each of these Builds, both old and new."""
306 def unsubscribe(observer):
307 """Unregister the callable that was registered with subscribe()."""
308 def getSubmitTime():
309 """Return the time when this request was submitted"""
310 def setSubmitTime(t):
311 """Sets the time when this request was submitted"""
314 class ISlaveStatus(Interface):
315 def getName():
316 """Return the name of the build slave."""
318 def getAdmin():
319 """Return a string with the slave admin's contact data."""
321 def getHost():
322 """Return a string with the slave host info."""
324 def isConnected():
325 """Return True if the slave is currently online, False if not."""
327 def lastMessageReceived():
328 """Return a timestamp (seconds since epoch) indicating when the most
329 recent message was received from the buildslave."""
331 class ISchedulerStatus(Interface):
332 def getName():
333 """Return the name of this Scheduler (a string)."""
335 def getPendingBuildsets():
336 """Return an IBuildSet for all BuildSets that are pending. These
337 BuildSets are waiting for their tree-stable-timers to expire."""
338 # TODO: this is not implemented anywhere
341 class IBuilderStatus(Interface):
342 def getName():
343 """Return the name of this Builder (a string)."""
345 def getState():
346 # TODO: this isn't nearly as meaningful as it used to be
347 """Return a tuple (state, builds) for this Builder. 'state' is the
348 so-called 'big-status', indicating overall status (as opposed to
349 which step is currently running). It is a string, one of 'offline',
350 'idle', or 'building'. 'builds' is a list of IBuildStatus objects
351 (possibly empty) representing the currently active builds."""
353 def getSlaves():
354 """Return a list of ISlaveStatus objects for the buildslaves that are
355 used by this builder."""
357 def getPendingBuilds():
358 """Return an IBuildRequestStatus object for all upcoming builds
359 (those which are ready to go but which are waiting for a buildslave
360 to be available."""
362 def getCurrentBuilds():
363 """Return a list containing an IBuildStatus object for each build
364 currently in progress."""
365 # again, we could probably provide an object for 'waiting' and
366 # 'interlocked' too, but things like the Change list might still be
367 # subject to change
369 def getLastFinishedBuild():
370 """Return the IBuildStatus object representing the last finished
371 build, which may be None if the builder has not yet finished any
372 builds."""
374 def getBuild(number):
375 """Return an IBuildStatus object for a historical build. Each build
376 is numbered (starting at 0 when the Builder is first added),
377 getBuild(n) will retrieve the Nth such build. getBuild(-n) will
378 retrieve a recent build, with -1 being the most recent build
379 started. If the Builder is idle, this will be the same as
380 getLastFinishedBuild(). If the Builder is active, it will be an
381 unfinished build. This method will return None if the build is no
382 longer available. Older builds are likely to have less information
383 stored: Logs are the first to go, then Steps."""
385 def getEvent(number):
386 """Return an IStatusEvent object for a recent Event. Builders
387 connecting and disconnecting are events, as are ping attempts.
388 getEvent(-1) will return the most recent event. Events are numbered,
389 but it probably doesn't make sense to ever do getEvent(+n)."""
391 def generateFinishedBuilds(branches=[],
392 num_builds=None,
393 max_buildnum=None, finished_before=None,
394 max_search=200,
396 """Return a generator that will produce IBuildStatus objects each
397 time you invoke its .next() method, starting with the most recent
398 finished build, then the previous build, and so on back to the oldest
399 build available.
401 @param branches: this is a list of branch names, and the generator
402 will only produce builds that involve the given
403 branches. If the list is empty, the generator will
404 produce all builds regardless of what branch they
405 used.
407 @param num_builds: if provided, the generator will stop after
408 providing this many builds. The default of None
409 means to produce as many builds as possible.
411 @param max_buildnum: if provided, the generator will start by
412 providing the build with this number, or the
413 highest-numbered preceding build (i.e. the
414 generator will not produce any build numbered
415 *higher* than max_buildnum). The default of None
416 means to start with the most recent finished
417 build. -1 means the same as None. -2 means to
418 start with the next-most-recent completed build,
419 etc.
421 @type finished_before: int: a timestamp, seconds since the epoch
422 @param finished_before: if provided, do not produce any builds that
423 finished after the given timestamp.
425 @type max_search: int
426 @param max_search: this method may have to examine a lot of builds
427 to find some that match the search parameters,
428 especially if there aren't any matching builds.
429 This argument imposes a hard limit on the number
430 of builds that will be examined.
433 def subscribe(receiver):
434 """Register an IStatusReceiver to receive new status events. The
435 receiver will be given builderChangedState, buildStarted, and
436 buildFinished messages."""
438 def unsubscribe(receiver):
439 """Unregister an IStatusReceiver. No further status messgaes will be
440 delivered."""
442 class IEventSource(Interface):
443 def eventGenerator(branches=[]):
444 """This function creates a generator which will yield all of this
445 object's status events, starting with the most recent and progressing
446 backwards in time. These events provide the IStatusEvent interface.
447 At the moment they are all instances of buildbot.status.builder.Event
448 or buildbot.status.builder.BuildStepStatus .
450 @param branches: a list of branch names. The generator should only
451 return events that are associated with these branches. If the list is
452 empty, events for all branches should be returned (i.e. an empty list
453 means 'accept all' rather than 'accept none').
456 class IBuildStatus(Interface):
457 """I represent the status of a single Build/BuildRequest. It could be
458 in-progress or finished."""
460 def getBuilder():
462 Return the BuilderStatus that owns this build.
464 @rtype: implementor of L{IBuilderStatus}
467 def isFinished():
468 """Return a boolean. True means the build has finished, False means
469 it is still running."""
471 def waitUntilFinished():
472 """Return a Deferred that will fire when the build finishes. If the
473 build has already finished, this deferred will fire right away. The
474 callback is given this IBuildStatus instance as an argument."""
476 def getProperty(propname):
477 """Return the value of the build property with the given name. Raises
478 KeyError if there is no such property on this build."""
480 def getReason():
481 """Return a string that indicates why the build was run. 'changes',
482 'forced', and 'periodic' are the most likely values. 'try' will be
483 added in the future."""
485 def getSourceStamp():
486 """Return a SourceStamp object which can be used to re-create
487 the source tree that this build used.
489 This method will return None if the source information is no longer
490 available."""
491 # TODO: it should be possible to expire the patch but still remember
492 # that the build was r123+something.
494 def getChanges():
495 """Return a list of Change objects which represent which source
496 changes went into the build."""
498 def getResponsibleUsers():
499 """Return a list of Users who are to blame for the changes that went
500 into this build. If anything breaks (at least anything that wasn't
501 already broken), blame them. Specifically, this is the set of users
502 who were responsible for the Changes that went into this build. Each
503 User is a string, corresponding to their name as known by the VC
504 repository."""
506 def getInterestedUsers():
507 """Return a list of Users who will want to know about the results of
508 this build. This is a superset of getResponsibleUsers(): it adds
509 people who are interested in this build but who did not actually
510 make the Changes that went into it (build sheriffs, code-domain
511 owners)."""
513 def getNumber():
514 """Within each builder, each Build has a number. Return it."""
516 def getPreviousBuild():
517 """Convenience method. Returns None if the previous build is
518 unavailable."""
520 def getSteps():
521 """Return a list of IBuildStepStatus objects. For invariant builds
522 (those which always use the same set of Steps), this should always
523 return the complete list, however some of the steps may not have
524 started yet (step.getTimes()[0] will be None). For variant builds,
525 this may not be complete (asking again later may give you more of
526 them)."""
528 def getTimes():
529 """Returns a tuple of (start, end). 'start' and 'end' are the times
530 (seconds since the epoch) when the Build started and finished. If
531 the build is still running, 'end' will be None."""
533 # while the build is running, the following methods make sense.
534 # Afterwards they return None
536 def getETA():
537 """Returns the number of seconds from now in which the build is
538 expected to finish, or None if we can't make a guess. This guess will
539 be refined over time."""
541 def getCurrentStep():
542 """Return an IBuildStepStatus object representing the currently
543 active step."""
545 # Once you know the build has finished, the following methods are legal.
546 # Before ths build has finished, they all return None.
548 def getSlavename():
549 """Return the name of the buildslave which handled this build."""
551 def getText():
552 """Returns a list of strings to describe the build. These are
553 intended to be displayed in a narrow column. If more space is
554 available, the caller should join them together with spaces before
555 presenting them to the user."""
557 def getResults():
558 """Return a constant describing the results of the build: one of the
559 constants in buildbot.status.builder: SUCCESS, WARNINGS,
560 FAILURE, SKIPPED or EXCEPTION."""
562 def getLogs():
563 """Return a list of logs that describe the build as a whole. Some
564 steps will contribute their logs, while others are are less important
565 and will only be accessible through the IBuildStepStatus objects.
566 Each log is an object which implements the IStatusLog interface."""
568 def getTestResults():
569 """Return a dictionary that maps test-name tuples to ITestResult
570 objects. This may return an empty or partially-filled dictionary
571 until the build has completed."""
573 # subscription interface
575 def subscribe(receiver, updateInterval=None):
576 """Register an IStatusReceiver to receive new status events. The
577 receiver will be given stepStarted and stepFinished messages. If
578 'updateInterval' is non-None, buildETAUpdate messages will be sent
579 every 'updateInterval' seconds."""
581 def unsubscribe(receiver):
582 """Unregister an IStatusReceiver. No further status messgaes will be
583 delivered."""
585 class ITestResult(Interface):
586 """I describe the results of a single unit test."""
588 def getName():
589 """Returns a tuple of strings which make up the test name. Tests may
590 be arranged in a hierarchy, so looking for common prefixes may be
591 useful."""
593 def getResults():
594 """Returns a constant describing the results of the test: SUCCESS,
595 WARNINGS, FAILURE."""
597 def getText():
598 """Returns a list of short strings which describe the results of the
599 test in slightly more detail. Suggested components include
600 'failure', 'error', 'passed', 'timeout'."""
602 def getLogs():
603 # in flux, it may be possible to provide more structured information
604 # like python Failure instances
605 """Returns a dictionary of test logs. The keys are strings like
606 'stdout', 'log', 'exceptions'. The values are strings."""
609 class IBuildStepStatus(Interface):
610 """I hold status for a single BuildStep."""
612 def getName():
613 """Returns a short string with the name of this step. This string
614 may have spaces in it."""
616 def getBuild():
617 """Returns the IBuildStatus object which contains this step."""
619 def getTimes():
620 """Returns a tuple of (start, end). 'start' and 'end' are the times
621 (seconds since the epoch) when the Step started and finished. If the
622 step has not yet started, 'start' will be None. If the step is still
623 running, 'end' will be None."""
625 def getExpectations():
626 """Returns a list of tuples (name, current, target). Each tuple
627 describes a single axis along which the step's progress can be
628 measured. 'name' is a string which describes the axis itself, like
629 'filesCompiled' or 'tests run' or 'bytes of output'. 'current' is a
630 number with the progress made so far, while 'target' is the value
631 that we expect (based upon past experience) to get to when the build
632 is finished.
634 'current' will change over time until the step is finished. It is
635 'None' until the step starts. When the build is finished, 'current'
636 may or may not equal 'target' (which is merely the expectation based
637 upon previous builds)."""
639 def getURLs():
640 """Returns a dictionary of URLs. Each key is a link name (a short
641 string, like 'results' or 'coverage'), and each value is a URL. These
642 links will be displayed along with the LogFiles.
645 def getLogs():
646 """Returns a list of IStatusLog objects. If the step has not yet
647 finished, this list may be incomplete (asking again later may give
648 you more of them)."""
651 def isFinished():
652 """Return a boolean. True means the step has finished, False means it
653 is still running."""
655 def waitUntilFinished():
656 """Return a Deferred that will fire when the step finishes. If the
657 step has already finished, this deferred will fire right away. The
658 callback is given this IBuildStepStatus instance as an argument."""
660 # while the step is running, the following methods make sense.
661 # Afterwards they return None
663 def getETA():
664 """Returns the number of seconds from now in which the step is
665 expected to finish, or None if we can't make a guess. This guess will
666 be refined over time."""
668 # Once you know the step has finished, the following methods are legal.
669 # Before ths step has finished, they all return None.
671 def getText():
672 """Returns a list of strings which describe the step. These are
673 intended to be displayed in a narrow column. If more space is
674 available, the caller should join them together with spaces before
675 presenting them to the user."""
677 def getResults():
678 """Return a tuple describing the results of the step: (result,
679 strings). 'result' is one of the constants in
680 buildbot.status.builder: SUCCESS, WARNINGS, FAILURE, or SKIPPED.
681 'strings' is an optional list of strings that the step wants to
682 append to the overall build's results. These strings are usually
683 more terse than the ones returned by getText(): in particular,
684 successful Steps do not usually contribute any text to the overall
685 build."""
687 # subscription interface
689 def subscribe(receiver, updateInterval=10):
690 """Register an IStatusReceiver to receive new status events. The
691 receiver will be given logStarted and logFinished messages. It will
692 also be given a ETAUpdate message every 'updateInterval' seconds."""
694 def unsubscribe(receiver):
695 """Unregister an IStatusReceiver. No further status messgaes will be
696 delivered."""
698 class IStatusEvent(Interface):
699 """I represent a Builder Event, something non-Build related that can
700 happen to a Builder."""
702 def getTimes():
703 """Returns a tuple of (start, end) like IBuildStepStatus, but end==0
704 indicates that this is a 'point event', which has no duration.
705 SlaveConnect/Disconnect are point events. Ping is not: it starts
706 when requested and ends when the response (positive or negative) is
707 returned"""
709 def getText():
710 """Returns a list of strings which describe the event. These are
711 intended to be displayed in a narrow column. If more space is
712 available, the caller should join them together with spaces before
713 presenting them to the user."""
716 LOG_CHANNEL_STDOUT = 0
717 LOG_CHANNEL_STDERR = 1
718 LOG_CHANNEL_HEADER = 2
720 class IStatusLog(Interface):
721 """I represent a single Log, which is a growing list of text items that
722 contains some kind of output for a single BuildStep. I might be finished,
723 in which case this list has stopped growing.
725 Each Log has a name, usually something boring like 'log' or 'output'.
726 These names are not guaranteed to be unique, however they are usually
727 chosen to be useful within the scope of a single step (i.e. the Compile
728 step might produce both 'log' and 'warnings'). The name may also have
729 spaces. If you want something more globally meaningful, at least within a
730 given Build, try::
732 '%s.%s' % (log.getStep.getName(), log.getName())
734 The Log can be presented as plain text, or it can be accessed as a list
735 of items, each of which has a channel indicator (header, stdout, stderr)
736 and a text chunk. An HTML display might represent the interleaved
737 channels with different styles, while a straight download-the-text
738 interface would just want to retrieve a big string.
740 The 'header' channel is used by ShellCommands to prepend a note about
741 which command is about to be run ('running command FOO in directory
742 DIR'), and append another note giving the exit code of the process.
744 Logs can be streaming: if the Log has not yet finished, you can
745 subscribe to receive new chunks as they are added.
747 A ShellCommand will have a Log associated with it that gathers stdout
748 and stderr. Logs may also be created by parsing command output or
749 through other synthetic means (grepping for all the warnings in a
750 compile log, or listing all the test cases that are going to be run).
751 Such synthetic Logs are usually finished as soon as they are created."""
754 def getName():
755 """Returns a short string with the name of this log, probably 'log'.
758 def getStep():
759 """Returns the IBuildStepStatus which owns this log."""
760 # TODO: can there be non-Step logs?
762 def isFinished():
763 """Return a boolean. True means the log has finished and is closed,
764 False means it is still open and new chunks may be added to it."""
766 def waitUntilFinished():
767 """Return a Deferred that will fire when the log is closed. If the
768 log has already finished, this deferred will fire right away. The
769 callback is given this IStatusLog instance as an argument."""
771 def subscribe(receiver, catchup):
772 """Register an IStatusReceiver to receive chunks (with logChunk) as
773 data is added to the Log. If you use this, you will also want to use
774 waitUntilFinished to find out when the listener can be retired.
775 Subscribing to a closed Log is a no-op.
777 If 'catchup' is True, the receiver will immediately be sent a series
778 of logChunk messages to bring it up to date with the partially-filled
779 log. This allows a status client to join a Log already in progress
780 without missing any data. If the Log has already finished, it is too
781 late to catch up: just do getText() instead.
783 If the Log is very large, the receiver will be called many times with
784 a lot of data. There is no way to throttle this data. If the receiver
785 is planning on sending the data on to somewhere else, over a narrow
786 connection, you can get a throttleable subscription by using
787 C{subscribeConsumer} instead."""
789 def unsubscribe(receiver):
790 """Remove a receiver previously registered with subscribe(). Attempts
791 to remove a receiver which was not previously registered is a no-op.
794 def subscribeConsumer(consumer):
795 """Register an L{IStatusLogConsumer} to receive all chunks of the
796 logfile, including all the old entries and any that will arrive in
797 the future. The consumer will first have their C{registerProducer}
798 method invoked with a reference to an object that can be told
799 C{pauseProducing}, C{resumeProducing}, and C{stopProducing}. Then the
800 consumer's C{writeChunk} method will be called repeatedly with each
801 (channel, text) tuple in the log, starting with the very first. The
802 consumer will be notified with C{finish} when the log has been
803 exhausted (which can only happen when the log is finished). Note that
804 a small amount of data could be written via C{writeChunk} even after
805 C{pauseProducing} has been called.
807 To unsubscribe the consumer, use C{producer.stopProducing}."""
809 # once the log has finished, the following methods make sense. They can
810 # be called earlier, but they will only return the contents of the log up
811 # to the point at which they were called. You will lose items that are
812 # added later. Use C{subscribe} or C{subscribeConsumer} to avoid missing
813 # anything.
815 def hasContents():
816 """Returns True if the LogFile still has contents available. Returns
817 False for logs that have been pruned. Clients should test this before
818 offering to show the contents of any log."""
820 def getText():
821 """Return one big string with the contents of the Log. This merges
822 all non-header chunks together."""
824 def readlines(channel=LOG_CHANNEL_STDOUT):
825 """Read lines from one channel of the logfile. This returns an
826 iterator that will provide single lines of text (including the
827 trailing newline).
830 def getTextWithHeaders():
831 """Return one big string with the contents of the Log. This merges
832 all chunks (including headers) together."""
834 def getChunks():
835 """Generate a list of (channel, text) tuples. 'channel' is a number,
836 0 for stdout, 1 for stderr, 2 for header. (note that stderr is merged
837 into stdout if PTYs are in use)."""
839 class IStatusLogConsumer(Interface):
840 """I am an object which can be passed to IStatusLog.subscribeConsumer().
841 I represent a target for writing the contents of an IStatusLog. This
842 differs from a regular IStatusReceiver in that it can pause the producer.
843 This makes it more suitable for use in streaming data over network
844 sockets, such as an HTTP request. Note that the consumer can only pause
845 the producer until it has caught up with all the old data. After that
846 point, C{pauseProducing} is ignored and all new output from the log is
847 sent directoy to the consumer."""
849 def registerProducer(producer, streaming):
850 """A producer is being hooked up to this consumer. The consumer only
851 has to handle a single producer. It should send .pauseProducing and
852 .resumeProducing messages to the producer when it wants to stop or
853 resume the flow of data. 'streaming' will be set to True because the
854 producer is always a PushProducer.
857 def unregisterProducer():
858 """The previously-registered producer has been removed. No further
859 pauseProducing or resumeProducing calls should be made. The consumer
860 should delete its reference to the Producer so it can be released."""
862 def writeChunk(chunk):
863 """A chunk (i.e. a tuple of (channel, text)) is being written to the
864 consumer."""
866 def finish():
867 """The log has finished sending chunks to the consumer."""
869 class IStatusReceiver(Interface):
870 """I am an object which can receive build status updates. I may be
871 subscribed to an IStatus, an IBuilderStatus, or an IBuildStatus."""
873 def buildsetSubmitted(buildset):
874 """A new BuildSet has been submitted to the buildmaster.
876 @type buildset: implementor of L{IBuildSetStatus}
879 def requestSubmitted(request):
880 """A new BuildRequest has been submitted to the buildmaster.
882 @type request: implementor of L{IBuildRequestStatus}
885 def requestCancelled(builder, request):
886 """A BuildRequest has been cancelled on the given Builder.
888 @type builder: L{buildbot.status.builder.BuilderStatus}
889 @type request: implementor of L{IBuildRequestStatus}
892 def builderAdded(builderName, builder):
894 A new Builder has just been added. This method may return an
895 IStatusReceiver (probably 'self') which will be subscribed to receive
896 builderChangedState and buildStarted/Finished events.
898 @type builderName: string
899 @type builder: L{buildbot.status.builder.BuilderStatus}
900 @rtype: implementor of L{IStatusReceiver}
903 def builderChangedState(builderName, state):
904 """Builder 'builderName' has changed state. The possible values for
905 'state' are 'offline', 'idle', and 'building'."""
907 def buildStarted(builderName, build):
908 """Builder 'builderName' has just started a build. The build is an
909 object which implements IBuildStatus, and can be queried for more
910 information.
912 This method may return an IStatusReceiver (it could even return
913 'self'). If it does so, stepStarted and stepFinished methods will be
914 invoked on the object for the steps of this one build. This is a
915 convenient way to subscribe to all build steps without missing any.
916 This receiver will automatically be unsubscribed when the build
917 finishes.
919 It can also return a tuple of (IStatusReceiver, interval), in which
920 case buildETAUpdate messages are sent ever 'interval' seconds, in
921 addition to the stepStarted and stepFinished messages."""
923 def buildETAUpdate(build, ETA):
924 """This is a periodic update on the progress this Build has made
925 towards completion."""
927 def stepStarted(build, step):
928 """A step has just started. 'step' is the IBuildStepStatus which
929 represents the step: it can be queried for more information.
931 This method may return an IStatusReceiver (it could even return
932 'self'). If it does so, logStarted and logFinished methods will be
933 invoked on the object for logs created by this one step. This
934 receiver will be automatically unsubscribed when the step finishes.
936 Alternatively, the method may return a tuple of an IStatusReceiver
937 and an integer named 'updateInterval'. In addition to
938 logStarted/logFinished messages, it will also receive stepETAUpdate
939 messages about every updateInterval seconds."""
941 def stepTextChanged(build, step, text):
942 """The text for a step has been updated.
944 This is called when calling setText() on the step status, and
945 hands in the text list."""
947 def stepText2Changed(build, step, text2):
948 """The text2 for a step has been updated.
950 This is called when calling setText2() on the step status, and
951 hands in text2 list."""
953 def stepETAUpdate(build, step, ETA, expectations):
954 """This is a periodic update on the progress this Step has made
955 towards completion. It gets an ETA (in seconds from the present) of
956 when the step ought to be complete, and a list of expectation tuples
957 (as returned by IBuildStepStatus.getExpectations) with more detailed
958 information."""
960 def logStarted(build, step, log):
961 """A new Log has been started, probably because a step has just
962 started running a shell command. 'log' is the IStatusLog object
963 which can be queried for more information.
965 This method may return an IStatusReceiver (such as 'self'), in which
966 case the target's logChunk method will be invoked as text is added to
967 the logfile. This receiver will automatically be unsubsribed when the
968 log finishes."""
970 def logChunk(build, step, log, channel, text):
971 """Some text has been added to this log. 'channel' is one of
972 LOG_CHANNEL_STDOUT, LOG_CHANNEL_STDERR, or LOG_CHANNEL_HEADER, as
973 defined in IStatusLog.getChunks."""
975 def logFinished(build, step, log):
976 """A Log has been closed."""
978 def stepFinished(build, step, results):
979 """A step has just finished. 'results' is the result tuple described
980 in IBuildStepStatus.getResults."""
982 def buildFinished(builderName, build, results):
984 A build has just finished. 'results' is the result tuple described
985 in L{IBuildStatus.getResults}.
987 @type builderName: string
988 @type build: L{buildbot.status.builder.BuildStatus}
989 @type results: tuple
992 def builderRemoved(builderName):
993 """The Builder has been removed."""
995 class IControl(Interface):
996 def addChange(change):
997 """Add a change to all builders. Each Builder will decide for
998 themselves whether the change is interesting or not, and may initiate
999 a build as a result."""
1001 def submitBuildSet(buildset):
1002 """Submit a BuildSet object, which will eventually be run on all of
1003 the builders listed therein."""
1005 def getBuilder(name):
1006 """Retrieve the IBuilderControl object for the given Builder."""
1008 class IBuilderControl(Interface):
1009 def requestBuild(request):
1010 """Queue a L{buildbot.process.base.BuildRequest} object for later
1011 building."""
1013 def requestBuildSoon(request):
1014 """Submit a BuildRequest like requestBuild, but raise a
1015 L{buildbot.interfaces.NoSlaveError} if no slaves are currently
1016 available, so it cannot be used to queue a BuildRequest in the hopes
1017 that a slave will eventually connect. This method is appropriate for
1018 use by things like the web-page 'Force Build' button."""
1020 def resubmitBuild(buildStatus, reason="<rebuild, no reason given>"):
1021 """Rebuild something we've already built before. This submits a
1022 BuildRequest to our Builder using the same SourceStamp as the earlier
1023 build. This has no effect (but may eventually raise an exception) if
1024 this Build has not yet finished."""
1026 def getPendingBuilds():
1027 """Return a list of L{IBuildRequestControl} objects for this Builder.
1028 Each one corresponds to a pending build that has not yet started (due
1029 to a scarcity of build slaves). These upcoming builds can be canceled
1030 through the control object."""
1032 def getBuild(number):
1033 """Attempt to return an IBuildControl object for the given build.
1034 Returns None if no such object is available. This will only work for
1035 the build that is currently in progress: once the build finishes,
1036 there is nothing to control anymore."""
1038 def ping(timeout=30):
1039 """Attempt to contact the slave and see if it is still alive. This
1040 returns a Deferred which fires with either True (the slave is still
1041 alive) or False (the slave did not respond). As a side effect, adds
1042 an event to this builder's column in the waterfall display
1043 containing the results of the ping."""
1044 # TODO: this ought to live in ISlaveControl, maybe with disconnect()
1045 # or something. However the event that is emitted is most useful in
1046 # the Builder column, so it kinda fits here too.
1048 class IBuildRequestControl(Interface):
1049 def subscribe(observer):
1050 """Register a callable that will be invoked (with a single
1051 IBuildControl object) for each Build that is created to satisfy this
1052 request. There may be multiple Builds created in an attempt to handle
1053 the request: they may be interrupted by the user or abandoned due to
1054 a lost slave. The last Build (the one which actually gets to run to
1055 completion) is said to 'satisfy' the BuildRequest. The observer will
1056 be called once for each of these Builds, both old and new."""
1057 def unsubscribe(observer):
1058 """Unregister the callable that was registered with subscribe()."""
1059 def cancel():
1060 """Remove the build from the pending queue. Has no effect if the
1061 build has already been started."""
1063 class IBuildControl(Interface):
1064 def getStatus():
1065 """Return an IBuildStatus object for the Build that I control."""
1066 def stopBuild(reason="<no reason given>"):
1067 """Halt the build. This has no effect if the build has already
1068 finished."""
1070 class ILogFile(Interface):
1071 """This is the internal interface to a LogFile, used by the BuildStep to
1072 write data into the log.
1074 def addStdout(data):
1075 pass
1076 def addStderr(data):
1077 pass
1078 def addHeader(data):
1079 pass
1080 def finish():
1081 """The process that is feeding the log file has finished, and no
1082 further data will be added. This closes the logfile."""
1084 class ILogObserver(Interface):
1085 """Objects which provide this interface can be used in a BuildStep to
1086 watch the output of a LogFile and parse it incrementally.
1089 # internal methods
1090 def setStep(step):
1091 pass
1092 def setLog(log):
1093 pass
1095 # methods called by the LogFile
1096 def logChunk(build, step, log, channel, text):
1097 pass
1099 class IBuildSlave(Interface):
1100 # this is a marker interface for the BuildSlave class
1101 pass
1103 class ILatentBuildSlave(IBuildSlave):
1104 """A build slave that is not always running, but can run when requested.
1106 substantiated = Attribute('Substantiated',
1107 'Whether the latent build slave is currently '
1108 'substantiated with a real instance.')
1110 def substantiate():
1111 """Request that the slave substantiate with a real instance.
1113 Returns a deferred that will callback when a real instance has
1114 attached."""
1116 # there is an insubstantiate too, but that is not used externally ATM.
1118 def buildStarted(sb):
1119 """Inform the latent build slave that a build has started.
1121 ``sb`` is a LatentSlaveBuilder as defined in buildslave.py. The sb
1122 is the one for whom the build started.
1125 def buildFinished(sb):
1126 """Inform the latent build slave that a build has finished.
1128 ``sb`` is a LatentSlaveBuilder as defined in buildslave.py. The sb
1129 is the one for whom the build finished.