ISlaveStatus: provide an interface to read BuildSlave.lastMessageReceived
[buildbot.git] / buildbot / interfaces.py
blobba62a80a61437b8488c24f4c6d0963094b8eacf7
2 """Interface documentation.
4 Define the interfaces that are implemented by various buildbot classes.
5 """
7 from zope.interface import Interface
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
17 class IChangeSource(Interface):
18 """Object which feeds Change objects to the changemaster. When files or
19 directories are changed and the version control system provides some
20 kind of notification, this object should turn it into a Change object
21 and pass it through::
23 self.changemaster.addChange(change)
24 """
26 def start():
27 """Called when the buildmaster starts. Can be used to establish
28 connections to VC daemons or begin polling."""
30 def stop():
31 """Called when the buildmaster shuts down. Connections should be
32 terminated, polling timers should be canceled."""
34 def describe():
35 """Should return a string which briefly describes this source. This
36 string will be displayed in an HTML status page."""
38 class IScheduler(Interface):
39 """I watch for Changes in the source tree and decide when to trigger
40 Builds. I create BuildSet objects and submit them to the BuildMaster. I
41 am a service, and the BuildMaster is always my parent."""
43 def addChange(change):
44 """A Change has just been dispatched by one of the ChangeSources.
45 Each Scheduler will receive this Change. I may decide to start a
46 build as a result, or I might choose to ignore it."""
48 def listBuilderNames():
49 """Return a list of strings indicating the Builders that this
50 Scheduler might feed."""
52 def getPendingBuildTimes():
53 """Return a list of timestamps for any builds that are waiting in the
54 tree-stable-timer queue. This is only relevant for Change-based
55 schedulers, all others can just return an empty list."""
56 # TODO: it might be nice to make this into getPendingBuildSets, which
57 # would let someone subscribe to the buildset being finished.
58 # However, the Scheduler doesn't actually create the buildset until
59 # it gets submitted, so doing this would require some major rework.
61 class IUpstreamScheduler(Interface):
62 """This marks an IScheduler as being eligible for use as the 'upstream='
63 argument to a buildbot.scheduler.Dependent instance."""
65 def subscribeToSuccessfulBuilds(target):
66 """Request that the target callbable be invoked after every
67 successful buildset. The target will be called with a single
68 argument: the SourceStamp used by the successful builds."""
70 def listBuilderNames():
71 """Return a list of strings indicating the Builders that this
72 Scheduler might feed."""
74 class ISourceStamp(Interface):
75 """
76 @cvar branch: branch from which source was drawn
77 @type branch: string or None
79 @cvar revision: revision of the source, or None to use CHANGES
80 @type revision: varies depending on VC
82 @cvar patch: patch applied to the source, or None if no patch
83 @type patch: None or tuple (level diff)
85 @cvar changes: the source step should check out hte latest revision
86 in the given changes
87 @type changes: tuple of L{buildbot.changes.changes.Change} instances,
88 all of which are on the same branch
89 """
91 def canBeMergedWith(self, other):
92 """
93 Can this SourceStamp be merged with OTHER?
94 """
96 def mergeWith(self, others):
97 """Generate a SourceStamp for the merger of me and all the other
98 BuildRequests. This is called by a Build when it starts, to figure
99 out what its sourceStamp should be."""
101 def getText(self):
102 """Returns a list of strings to describe the stamp. These are
103 intended to be displayed in a narrow column. If more space is
104 available, the caller should join them together with spaces before
105 presenting them to the user."""
107 class IEmailSender(Interface):
108 """I know how to send email, and can be used by other parts of the
109 Buildbot to contact developers."""
110 pass
112 class IEmailLookup(Interface):
113 def getAddress(user):
114 """Turn a User-name string into a valid email address. Either return
115 a string (with an @ in it), None (to indicate that the user cannot
116 be reached by email), or a Deferred which will fire with the same."""
118 class IStatus(Interface):
119 """I am an object, obtainable from the buildmaster, which can provide
120 status information."""
122 def getProjectName():
123 """Return the name of the project that this Buildbot is working
124 for."""
125 def getProjectURL():
126 """Return the URL of this Buildbot's project."""
127 def getBuildbotURL():
128 """Return the URL of the top-most Buildbot status page, or None if
129 this Buildbot does not provide a web status page."""
130 def getURLForThing(thing):
131 """Return the URL of a page which provides information on 'thing',
132 which should be an object that implements one of the status
133 interfaces defined in L{buildbot.interfaces}. Returns None if no
134 suitable page is available (or if no Waterfall is running)."""
136 def getChangeSources():
137 """Return a list of IChangeSource objects."""
139 def getChange(number):
140 """Return an IChange object."""
142 def getSchedulers():
143 """Return a list of ISchedulerStatus objects for all
144 currently-registered Schedulers."""
146 def getBuilderNames(categories=None):
147 """Return a list of the names of all current Builders."""
148 def getBuilder(name):
149 """Return the IBuilderStatus object for a given named Builder. Raises
150 KeyError if there is no Builder by that name."""
151 def getSlave(name):
152 """Return the ISlaveStatus object for a given named buildslave."""
154 def getBuildSets():
155 """Return a list of active (non-finished) IBuildSetStatus objects."""
157 def generateFinishedBuilds(builders=[], branches=[],
158 num_builds=None, finished_before=None):
159 """Return a generator that will produce IBuildStatus objects each
160 time you invoke its .next() method, starting with the most recent
161 finished build and working backwards.
163 @param builders: this is a list of Builder names, and the generator
164 will only produce builds that ran on the given
165 Builders. If the list is empty, produce builds from
166 all Builders.
168 @param branches: this is a list of branch names, and the generator
169 will only produce builds that used the given
170 branches. If the list is empty, produce builds from
171 all branches.
173 @param num_builds: the generator will stop after providing this many
174 builds. The default of None means to produce as
175 many builds as possible.
177 @type finished_before: int: a timestamp, seconds since the epoch
178 @param finished_before: if provided, do not produce any builds that
179 finished after the given timestamp.
182 def subscribe(receiver):
183 """Register an IStatusReceiver to receive new status events. The
184 receiver will immediately be sent a set of 'builderAdded' messages
185 for all current builders. It will receive further 'builderAdded' and
186 'builderRemoved' messages as the config file is reloaded and builders
187 come and go. It will also receive 'buildsetSubmitted' messages for
188 all outstanding BuildSets (and each new BuildSet that gets
189 submitted). No additional messages will be sent unless the receiver
190 asks for them by calling .subscribe on the IBuilderStatus objects
191 which accompany the addedBuilder message."""
193 def unsubscribe(receiver):
194 """Unregister an IStatusReceiver. No further status messgaes will be
195 delivered."""
197 class IBuildSetStatus(Interface):
198 """I represent a set of Builds, each run on a separate Builder but all
199 using the same source tree."""
201 def getSourceStamp():
202 """Return a SourceStamp object which can be used to re-create
203 the source tree that this build used.
205 This method will return None if the source information is no longer
206 available."""
207 pass
208 def getReason():
209 pass
210 def getID():
211 """Return the BuildSet's ID string, if any. The 'try' feature uses a
212 random string as a BuildSetID to relate submitted jobs with the
213 resulting BuildSet."""
214 def getResponsibleUsers():
215 pass # not implemented
216 def getInterestedUsers():
217 pass # not implemented
218 def getBuilderNames():
219 """Return a list of the names of all Builders on which this set will
220 do builds."""
221 def getBuildRequests():
222 """Return a list of IBuildRequestStatus objects that represent my
223 component Builds. This list might correspond to the Builders named by
224 getBuilderNames(), but if builder categories are used, or 'Builder
225 Aliases' are implemented, then they may not."""
226 def isFinished():
227 pass
228 def waitUntilSuccess():
229 """Return a Deferred that fires (with this IBuildSetStatus object)
230 when the outcome of the BuildSet is known, i.e., upon the first
231 failure, or after all builds complete successfully."""
232 def waitUntilFinished():
233 """Return a Deferred that fires (with this IBuildSetStatus object)
234 when all builds have finished."""
235 def getResults():
236 pass
238 class IBuildRequestStatus(Interface):
239 """I represent a request to build a particular set of source code on a
240 particular Builder. These requests may be merged by the time they are
241 finally turned into a Build."""
243 def getSourceStamp():
244 """Return a SourceStamp object which can be used to re-create
245 the source tree that this build used.
247 This method will return None if the source information is no longer
248 available."""
249 pass
250 def getBuilderName():
251 pass
252 def getBuilds():
253 """Return a list of IBuildStatus objects for each Build that has been
254 started in an attempt to satify this BuildRequest."""
256 def subscribe(observer):
257 """Register a callable that will be invoked (with a single
258 IBuildStatus object) for each Build that is created to satisfy this
259 request. There may be multiple Builds created in an attempt to handle
260 the request: they may be interrupted by the user or abandoned due to
261 a lost slave. The last Build (the one which actually gets to run to
262 completion) is said to 'satisfy' the BuildRequest. The observer will
263 be called once for each of these Builds, both old and new."""
264 def unsubscribe(observer):
265 """Unregister the callable that was registered with subscribe()."""
268 class ISlaveStatus(Interface):
269 def getName():
270 """Return the name of the build slave."""
272 def getAdmin():
273 """Return a string with the slave admin's contact data."""
275 def getHost():
276 """Return a string with the slave host info."""
278 def isConnected():
279 """Return True if the slave is currently online, False if not."""
281 def lastMessageReceived():
282 """Return a timestamp (seconds since epoch) indicating when the most
283 recent message was received from the buildslave."""
285 class ISchedulerStatus(Interface):
286 def getName():
287 """Return the name of this Scheduler (a string)."""
289 def getPendingBuildsets():
290 """Return an IBuildSet for all BuildSets that are pending. These
291 BuildSets are waiting for their tree-stable-timers to expire."""
292 # TODO: this is not implemented anywhere
295 class IBuilderStatus(Interface):
296 def getName():
297 """Return the name of this Builder (a string)."""
299 def getState():
300 # TODO: this isn't nearly as meaningful as it used to be
301 """Return a tuple (state, builds) for this Builder. 'state' is the
302 so-called 'big-status', indicating overall status (as opposed to
303 which step is currently running). It is a string, one of 'offline',
304 'idle', or 'building'. 'builds' is a list of IBuildStatus objects
305 (possibly empty) representing the currently active builds."""
307 def getSlaves():
308 """Return a list of ISlaveStatus objects for the buildslaves that are
309 used by this builder."""
311 def getPendingBuilds():
312 """Return an IBuildRequestStatus object for all upcoming builds
313 (those which are ready to go but which are waiting for a buildslave
314 to be available."""
316 def getCurrentBuilds():
317 """Return a list containing an IBuildStatus object for each build
318 currently in progress."""
319 # again, we could probably provide an object for 'waiting' and
320 # 'interlocked' too, but things like the Change list might still be
321 # subject to change
323 def getLastFinishedBuild():
324 """Return the IBuildStatus object representing the last finished
325 build, which may be None if the builder has not yet finished any
326 builds."""
328 def getBuild(number):
329 """Return an IBuildStatus object for a historical build. Each build
330 is numbered (starting at 0 when the Builder is first added),
331 getBuild(n) will retrieve the Nth such build. getBuild(-n) will
332 retrieve a recent build, with -1 being the most recent build
333 started. If the Builder is idle, this will be the same as
334 getLastFinishedBuild(). If the Builder is active, it will be an
335 unfinished build. This method will return None if the build is no
336 longer available. Older builds are likely to have less information
337 stored: Logs are the first to go, then Steps."""
339 def getEvent(number):
340 """Return an IStatusEvent object for a recent Event. Builders
341 connecting and disconnecting are events, as are ping attempts.
342 getEvent(-1) will return the most recent event. Events are numbered,
343 but it probably doesn't make sense to ever do getEvent(+n)."""
345 def generateFinishedBuilds(branches=[],
346 num_builds=None,
347 max_buildnum=None, finished_before=None
349 """Return a generator that will produce IBuildStatus objects each
350 time you invoke its .next() method, starting with the most recent
351 finished build, then the previous build, and so on back to the oldest
352 build available.
354 @param branches: this is a list of branch names, and the generator
355 will only produce builds that involve the given
356 branches. If the list is empty, the generator will
357 produce all builds regardless of what branch they
358 used.
360 @param num_builds: if provided, the generator will stop after
361 providing this many builds. The default of None
362 means to produce as many builds as possible.
364 @param max_buildnum: if provided, the generator will start by
365 providing the build with this number, or the
366 highest-numbered preceding build (i.e. the
367 generator will not produce any build numbered
368 *higher* than max_buildnum). The default of None
369 means to start with the most recent finished
370 build. -1 means the same as None. -2 means to
371 start with the next-most-recent completed build,
372 etc.
374 @type finished_before: int: a timestamp, seconds since the epoch
375 @param finished_before: if provided, do not produce any builds that
376 finished after the given timestamp.
379 def subscribe(receiver):
380 """Register an IStatusReceiver to receive new status events. The
381 receiver will be given builderChangedState, buildStarted, and
382 buildFinished messages."""
384 def unsubscribe(receiver):
385 """Unregister an IStatusReceiver. No further status messgaes will be
386 delivered."""
388 class IEventSource(Interface):
389 def eventGenerator(branches=[]):
390 """This function creates a generator which will yield all of this
391 object's status events, starting with the most recent and progressing
392 backwards in time. These events provide the IStatusEvent interface.
393 At the moment they are all instances of buildbot.status.builder.Event
394 or buildbot.status.builder.BuildStepStatus .
396 @param branches: a list of branch names. The generator should only
397 return events that are associated with these branches. If the list is
398 empty, events for all branches should be returned (i.e. an empty list
399 means 'accept all' rather than 'accept none').
402 class IBuildStatus(Interface):
403 """I represent the status of a single Build/BuildRequest. It could be
404 in-progress or finished."""
406 def getBuilder():
408 Return the BuilderStatus that owns this build.
410 @rtype: implementor of L{IBuilderStatus}
413 def isFinished():
414 """Return a boolean. True means the build has finished, False means
415 it is still running."""
417 def waitUntilFinished():
418 """Return a Deferred that will fire when the build finishes. If the
419 build has already finished, this deferred will fire right away. The
420 callback is given this IBuildStatus instance as an argument."""
422 def getProperty(propname):
423 """Return the value of the build property with the given name. Raises
424 KeyError if there is no such property on this build."""
426 def getReason():
427 """Return a string that indicates why the build was run. 'changes',
428 'forced', and 'periodic' are the most likely values. 'try' will be
429 added in the future."""
431 def getSourceStamp():
432 """Return a SourceStamp object which can be used to re-create
433 the source tree that this build used.
435 This method will return None if the source information is no longer
436 available."""
437 # TODO: it should be possible to expire the patch but still remember
438 # that the build was r123+something.
440 def getChanges():
441 """Return a list of Change objects which represent which source
442 changes went into the build."""
444 def getResponsibleUsers():
445 """Return a list of Users who are to blame for the changes that went
446 into this build. If anything breaks (at least anything that wasn't
447 already broken), blame them. Specifically, this is the set of users
448 who were responsible for the Changes that went into this build. Each
449 User is a string, corresponding to their name as known by the VC
450 repository."""
452 def getInterestedUsers():
453 """Return a list of Users who will want to know about the results of
454 this build. This is a superset of getResponsibleUsers(): it adds
455 people who are interested in this build but who did not actually
456 make the Changes that went into it (build sheriffs, code-domain
457 owners)."""
459 def getNumber():
460 """Within each builder, each Build has a number. Return it."""
462 def getPreviousBuild():
463 """Convenience method. Returns None if the previous build is
464 unavailable."""
466 def getSteps():
467 """Return a list of IBuildStepStatus objects. For invariant builds
468 (those which always use the same set of Steps), this should always
469 return the complete list, however some of the steps may not have
470 started yet (step.getTimes()[0] will be None). For variant builds,
471 this may not be complete (asking again later may give you more of
472 them)."""
474 def getTimes():
475 """Returns a tuple of (start, end). 'start' and 'end' are the times
476 (seconds since the epoch) when the Build started and finished. If
477 the build is still running, 'end' will be None."""
479 # while the build is running, the following methods make sense.
480 # Afterwards they return None
482 def getETA():
483 """Returns the number of seconds from now in which the build is
484 expected to finish, or None if we can't make a guess. This guess will
485 be refined over time."""
487 def getCurrentStep():
488 """Return an IBuildStepStatus object representing the currently
489 active step."""
491 # Once you know the build has finished, the following methods are legal.
492 # Before ths build has finished, they all return None.
494 def getSlavename():
495 """Return the name of the buildslave which handled this build."""
497 def getText():
498 """Returns a list of strings to describe the build. These are
499 intended to be displayed in a narrow column. If more space is
500 available, the caller should join them together with spaces before
501 presenting them to the user."""
503 def getColor():
504 """Returns a single string with the color that should be used to
505 display the build. 'green', 'orange', or 'red' are the most likely
506 ones."""
508 def getResults():
509 """Return a constant describing the results of the build: one of the
510 constants in buildbot.status.builder: SUCCESS, WARNINGS, or
511 FAILURE."""
513 def getLogs():
514 """Return a list of logs that describe the build as a whole. Some
515 steps will contribute their logs, while others are are less important
516 and will only be accessible through the IBuildStepStatus objects.
517 Each log is an object which implements the IStatusLog interface."""
519 def getTestResults():
520 """Return a dictionary that maps test-name tuples to ITestResult
521 objects. This may return an empty or partially-filled dictionary
522 until the build has completed."""
524 # subscription interface
526 def subscribe(receiver, updateInterval=None):
527 """Register an IStatusReceiver to receive new status events. The
528 receiver will be given stepStarted and stepFinished messages. If
529 'updateInterval' is non-None, buildETAUpdate messages will be sent
530 every 'updateInterval' seconds."""
532 def unsubscribe(receiver):
533 """Unregister an IStatusReceiver. No further status messgaes will be
534 delivered."""
536 class ITestResult(Interface):
537 """I describe the results of a single unit test."""
539 def getName():
540 """Returns a tuple of strings which make up the test name. Tests may
541 be arranged in a hierarchy, so looking for common prefixes may be
542 useful."""
544 def getResults():
545 """Returns a constant describing the results of the test: SUCCESS,
546 WARNINGS, FAILURE."""
548 def getText():
549 """Returns a list of short strings which describe the results of the
550 test in slightly more detail. Suggested components include
551 'failure', 'error', 'passed', 'timeout'."""
553 def getLogs():
554 # in flux, it may be possible to provide more structured information
555 # like python Failure instances
556 """Returns a dictionary of test logs. The keys are strings like
557 'stdout', 'log', 'exceptions'. The values are strings."""
560 class IBuildStepStatus(Interface):
561 """I hold status for a single BuildStep."""
563 def getName():
564 """Returns a short string with the name of this step. This string
565 may have spaces in it."""
567 def getBuild():
568 """Returns the IBuildStatus object which contains this step."""
570 def getTimes():
571 """Returns a tuple of (start, end). 'start' and 'end' are the times
572 (seconds since the epoch) when the Step started and finished. If the
573 step has not yet started, 'start' will be None. If the step is still
574 running, 'end' will be None."""
576 def getExpectations():
577 """Returns a list of tuples (name, current, target). Each tuple
578 describes a single axis along which the step's progress can be
579 measured. 'name' is a string which describes the axis itself, like
580 'filesCompiled' or 'tests run' or 'bytes of output'. 'current' is a
581 number with the progress made so far, while 'target' is the value
582 that we expect (based upon past experience) to get to when the build
583 is finished.
585 'current' will change over time until the step is finished. It is
586 'None' until the step starts. When the build is finished, 'current'
587 may or may not equal 'target' (which is merely the expectation based
588 upon previous builds)."""
590 def getURLs():
591 """Returns a dictionary of URLs. Each key is a link name (a short
592 string, like 'results' or 'coverage'), and each value is a URL. These
593 links will be displayed along with the LogFiles.
596 def getLogs():
597 """Returns a list of IStatusLog objects. If the step has not yet
598 finished, this list may be incomplete (asking again later may give
599 you more of them)."""
602 def isFinished():
603 """Return a boolean. True means the step has finished, False means it
604 is still running."""
606 def waitUntilFinished():
607 """Return a Deferred that will fire when the step finishes. If the
608 step has already finished, this deferred will fire right away. The
609 callback is given this IBuildStepStatus instance as an argument."""
611 # while the step is running, the following methods make sense.
612 # Afterwards they return None
614 def getETA():
615 """Returns the number of seconds from now in which the step is
616 expected to finish, or None if we can't make a guess. This guess will
617 be refined over time."""
619 # Once you know the step has finished, the following methods are legal.
620 # Before ths step has finished, they all return None.
622 def getText():
623 """Returns a list of strings which describe the step. These are
624 intended to be displayed in a narrow column. If more space is
625 available, the caller should join them together with spaces before
626 presenting them to the user."""
628 def getColor():
629 """Returns a single string with the color that should be used to
630 display this step. 'green', 'orange', 'red' and 'yellow' are the
631 most likely ones."""
633 def getResults():
634 """Return a tuple describing the results of the step: (result,
635 strings). 'result' is one of the constants in
636 buildbot.status.builder: SUCCESS, WARNINGS, FAILURE, or SKIPPED.
637 'strings' is an optional list of strings that the step wants to
638 append to the overall build's results. These strings are usually
639 more terse than the ones returned by getText(): in particular,
640 successful Steps do not usually contribute any text to the overall
641 build."""
643 # subscription interface
645 def subscribe(receiver, updateInterval=10):
646 """Register an IStatusReceiver to receive new status events. The
647 receiver will be given logStarted and logFinished messages. It will
648 also be given a ETAUpdate message every 'updateInterval' seconds."""
650 def unsubscribe(receiver):
651 """Unregister an IStatusReceiver. No further status messgaes will be
652 delivered."""
654 class IStatusEvent(Interface):
655 """I represent a Builder Event, something non-Build related that can
656 happen to a Builder."""
658 def getTimes():
659 """Returns a tuple of (start, end) like IBuildStepStatus, but end==0
660 indicates that this is a 'point event', which has no duration.
661 SlaveConnect/Disconnect are point events. Ping is not: it starts
662 when requested and ends when the response (positive or negative) is
663 returned"""
665 def getText():
666 """Returns a list of strings which describe the event. These are
667 intended to be displayed in a narrow column. If more space is
668 available, the caller should join them together with spaces before
669 presenting them to the user."""
671 def getColor():
672 """Returns a single string with the color that should be used to
673 display this event. 'red' and 'yellow' are the most likely ones."""
676 LOG_CHANNEL_STDOUT = 0
677 LOG_CHANNEL_STDERR = 1
678 LOG_CHANNEL_HEADER = 2
680 class IStatusLog(Interface):
681 """I represent a single Log, which is a growing list of text items that
682 contains some kind of output for a single BuildStep. I might be finished,
683 in which case this list has stopped growing.
685 Each Log has a name, usually something boring like 'log' or 'output'.
686 These names are not guaranteed to be unique, however they are usually
687 chosen to be useful within the scope of a single step (i.e. the Compile
688 step might produce both 'log' and 'warnings'). The name may also have
689 spaces. If you want something more globally meaningful, at least within a
690 given Build, try::
692 '%s.%s' % (log.getStep.getName(), log.getName())
694 The Log can be presented as plain text, or it can be accessed as a list
695 of items, each of which has a channel indicator (header, stdout, stderr)
696 and a text chunk. An HTML display might represent the interleaved
697 channels with different styles, while a straight download-the-text
698 interface would just want to retrieve a big string.
700 The 'header' channel is used by ShellCommands to prepend a note about
701 which command is about to be run ('running command FOO in directory
702 DIR'), and append another note giving the exit code of the process.
704 Logs can be streaming: if the Log has not yet finished, you can
705 subscribe to receive new chunks as they are added.
707 A ShellCommand will have a Log associated with it that gathers stdout
708 and stderr. Logs may also be created by parsing command output or
709 through other synthetic means (grepping for all the warnings in a
710 compile log, or listing all the test cases that are going to be run).
711 Such synthetic Logs are usually finished as soon as they are created."""
714 def getName():
715 """Returns a short string with the name of this log, probably 'log'.
718 def getStep():
719 """Returns the IBuildStepStatus which owns this log."""
720 # TODO: can there be non-Step logs?
722 def isFinished():
723 """Return a boolean. True means the log has finished and is closed,
724 False means it is still open and new chunks may be added to it."""
726 def waitUntilFinished():
727 """Return a Deferred that will fire when the log is closed. If the
728 log has already finished, this deferred will fire right away. The
729 callback is given this IStatusLog instance as an argument."""
731 def subscribe(receiver, catchup):
732 """Register an IStatusReceiver to receive chunks (with logChunk) as
733 data is added to the Log. If you use this, you will also want to use
734 waitUntilFinished to find out when the listener can be retired.
735 Subscribing to a closed Log is a no-op.
737 If 'catchup' is True, the receiver will immediately be sent a series
738 of logChunk messages to bring it up to date with the partially-filled
739 log. This allows a status client to join a Log already in progress
740 without missing any data. If the Log has already finished, it is too
741 late to catch up: just do getText() instead.
743 If the Log is very large, the receiver will be called many times with
744 a lot of data. There is no way to throttle this data. If the receiver
745 is planning on sending the data on to somewhere else, over a narrow
746 connection, you can get a throttleable subscription by using
747 C{subscribeConsumer} instead."""
749 def unsubscribe(receiver):
750 """Remove a receiver previously registered with subscribe(). Attempts
751 to remove a receiver which was not previously registered is a no-op.
754 def subscribeConsumer(consumer):
755 """Register an L{IStatusLogConsumer} to receive all chunks of the
756 logfile, including all the old entries and any that will arrive in
757 the future. The consumer will first have their C{registerProducer}
758 method invoked with a reference to an object that can be told
759 C{pauseProducing}, C{resumeProducing}, and C{stopProducing}. Then the
760 consumer's C{writeChunk} method will be called repeatedly with each
761 (channel, text) tuple in the log, starting with the very first. The
762 consumer will be notified with C{finish} when the log has been
763 exhausted (which can only happen when the log is finished). Note that
764 a small amount of data could be written via C{writeChunk} even after
765 C{pauseProducing} has been called.
767 To unsubscribe the consumer, use C{producer.stopProducing}."""
769 # once the log has finished, the following methods make sense. They can
770 # be called earlier, but they will only return the contents of the log up
771 # to the point at which they were called. You will lose items that are
772 # added later. Use C{subscribe} or C{subscribeConsumer} to avoid missing
773 # anything.
775 def hasContents():
776 """Returns True if the LogFile still has contents available. Returns
777 False for logs that have been pruned. Clients should test this before
778 offering to show the contents of any log."""
780 def getText():
781 """Return one big string with the contents of the Log. This merges
782 all non-header chunks together."""
784 def readlines(channel=LOG_CHANNEL_STDOUT):
785 """Read lines from one channel of the logfile. This returns an
786 iterator that will provide single lines of text (including the
787 trailing newline).
790 def getTextWithHeaders():
791 """Return one big string with the contents of the Log. This merges
792 all chunks (including headers) together."""
794 def getChunks():
795 """Generate a list of (channel, text) tuples. 'channel' is a number,
796 0 for stdout, 1 for stderr, 2 for header. (note that stderr is merged
797 into stdout if PTYs are in use)."""
799 class IStatusLogConsumer(Interface):
800 """I am an object which can be passed to IStatusLog.subscribeConsumer().
801 I represent a target for writing the contents of an IStatusLog. This
802 differs from a regular IStatusReceiver in that it can pause the producer.
803 This makes it more suitable for use in streaming data over network
804 sockets, such as an HTTP request. Note that the consumer can only pause
805 the producer until it has caught up with all the old data. After that
806 point, C{pauseProducing} is ignored and all new output from the log is
807 sent directoy to the consumer."""
809 def registerProducer(producer, streaming):
810 """A producer is being hooked up to this consumer. The consumer only
811 has to handle a single producer. It should send .pauseProducing and
812 .resumeProducing messages to the producer when it wants to stop or
813 resume the flow of data. 'streaming' will be set to True because the
814 producer is always a PushProducer.
817 def unregisterProducer():
818 """The previously-registered producer has been removed. No further
819 pauseProducing or resumeProducing calls should be made. The consumer
820 should delete its reference to the Producer so it can be released."""
822 def writeChunk(chunk):
823 """A chunk (i.e. a tuple of (channel, text)) is being written to the
824 consumer."""
826 def finish():
827 """The log has finished sending chunks to the consumer."""
829 class IStatusReceiver(Interface):
830 """I am an object which can receive build status updates. I may be
831 subscribed to an IStatus, an IBuilderStatus, or an IBuildStatus."""
833 def buildsetSubmitted(buildset):
834 """A new BuildSet has been submitted to the buildmaster.
836 @type buildset: implementor of L{IBuildSetStatus}
839 def builderAdded(builderName, builder):
841 A new Builder has just been added. This method may return an
842 IStatusReceiver (probably 'self') which will be subscribed to receive
843 builderChangedState and buildStarted/Finished events.
845 @type builderName: string
846 @type builder: L{buildbot.status.builder.BuilderStatus}
847 @rtype: implementor of L{IStatusReceiver}
850 def builderChangedState(builderName, state):
851 """Builder 'builderName' has changed state. The possible values for
852 'state' are 'offline', 'idle', and 'building'."""
854 def buildStarted(builderName, build):
855 """Builder 'builderName' has just started a build. The build is an
856 object which implements IBuildStatus, and can be queried for more
857 information.
859 This method may return an IStatusReceiver (it could even return
860 'self'). If it does so, stepStarted and stepFinished methods will be
861 invoked on the object for the steps of this one build. This is a
862 convenient way to subscribe to all build steps without missing any.
863 This receiver will automatically be unsubscribed when the build
864 finishes.
866 It can also return a tuple of (IStatusReceiver, interval), in which
867 case buildETAUpdate messages are sent ever 'interval' seconds, in
868 addition to the stepStarted and stepFinished messages."""
870 def buildETAUpdate(build, ETA):
871 """This is a periodic update on the progress this Build has made
872 towards completion."""
874 def stepStarted(build, step):
875 """A step has just started. 'step' is the IBuildStepStatus which
876 represents the step: it can be queried for more information.
878 This method may return an IStatusReceiver (it could even return
879 'self'). If it does so, logStarted and logFinished methods will be
880 invoked on the object for logs created by this one step. This
881 receiver will be automatically unsubscribed when the step finishes.
883 Alternatively, the method may return a tuple of an IStatusReceiver
884 and an integer named 'updateInterval'. In addition to
885 logStarted/logFinished messages, it will also receive stepETAUpdate
886 messages about every updateInterval seconds."""
888 def stepETAUpdate(build, step, ETA, expectations):
889 """This is a periodic update on the progress this Step has made
890 towards completion. It gets an ETA (in seconds from the present) of
891 when the step ought to be complete, and a list of expectation tuples
892 (as returned by IBuildStepStatus.getExpectations) with more detailed
893 information."""
895 def logStarted(build, step, log):
896 """A new Log has been started, probably because a step has just
897 started running a shell command. 'log' is the IStatusLog object
898 which can be queried for more information.
900 This method may return an IStatusReceiver (such as 'self'), in which
901 case the target's logChunk method will be invoked as text is added to
902 the logfile. This receiver will automatically be unsubsribed when the
903 log finishes."""
905 def logChunk(build, step, log, channel, text):
906 """Some text has been added to this log. 'channel' is one of
907 LOG_CHANNEL_STDOUT, LOG_CHANNEL_STDERR, or LOG_CHANNEL_HEADER, as
908 defined in IStatusLog.getChunks."""
910 def logFinished(build, step, log):
911 """A Log has been closed."""
913 def stepFinished(build, step, results):
914 """A step has just finished. 'results' is the result tuple described
915 in IBuildStepStatus.getResults."""
917 def buildFinished(builderName, build, results):
919 A build has just finished. 'results' is the result tuple described
920 in L{IBuildStatus.getResults}.
922 @type builderName: string
923 @type build: L{buildbot.status.builder.BuildStatus}
924 @type results: tuple
927 def builderRemoved(builderName):
928 """The Builder has been removed."""
930 class IControl(Interface):
931 def addChange(change):
932 """Add a change to all builders. Each Builder will decide for
933 themselves whether the change is interesting or not, and may initiate
934 a build as a result."""
936 def submitBuildSet(buildset):
937 """Submit a BuildSet object, which will eventually be run on all of
938 the builders listed therein."""
940 def getBuilder(name):
941 """Retrieve the IBuilderControl object for the given Builder."""
943 class IBuilderControl(Interface):
944 def requestBuild(request):
945 """Queue a L{buildbot.process.base.BuildRequest} object for later
946 building."""
948 def requestBuildSoon(request):
949 """Submit a BuildRequest like requestBuild, but raise a
950 L{buildbot.interfaces.NoSlaveError} if no slaves are currently
951 available, so it cannot be used to queue a BuildRequest in the hopes
952 that a slave will eventually connect. This method is appropriate for
953 use by things like the web-page 'Force Build' button."""
955 def resubmitBuild(buildStatus, reason="<rebuild, no reason given>"):
956 """Rebuild something we've already built before. This submits a
957 BuildRequest to our Builder using the same SourceStamp as the earlier
958 build. This has no effect (but may eventually raise an exception) if
959 this Build has not yet finished."""
961 def getPendingBuilds():
962 """Return a list of L{IBuildRequestControl} objects for this Builder.
963 Each one corresponds to a pending build that has not yet started (due
964 to a scarcity of build slaves). These upcoming builds can be canceled
965 through the control object."""
967 def getBuild(number):
968 """Attempt to return an IBuildControl object for the given build.
969 Returns None if no such object is available. This will only work for
970 the build that is currently in progress: once the build finishes,
971 there is nothing to control anymore."""
973 def ping(timeout=30):
974 """Attempt to contact the slave and see if it is still alive. This
975 returns a Deferred which fires with either True (the slave is still
976 alive) or False (the slave did not respond). As a side effect, adds
977 an event to this builder's column in the waterfall display
978 containing the results of the ping."""
979 # TODO: this ought to live in ISlaveControl, maybe with disconnect()
980 # or something. However the event that is emitted is most useful in
981 # the Builder column, so it kinda fits here too.
983 class IBuildRequestControl(Interface):
984 def subscribe(observer):
985 """Register a callable that will be invoked (with a single
986 IBuildControl object) for each Build that is created to satisfy this
987 request. There may be multiple Builds created in an attempt to handle
988 the request: they may be interrupted by the user or abandoned due to
989 a lost slave. The last Build (the one which actually gets to run to
990 completion) is said to 'satisfy' the BuildRequest. The observer will
991 be called once for each of these Builds, both old and new."""
992 def unsubscribe(observer):
993 """Unregister the callable that was registered with subscribe()."""
994 def cancel():
995 """Remove the build from the pending queue. Has no effect if the
996 build has already been started."""
998 class IBuildControl(Interface):
999 def getStatus():
1000 """Return an IBuildStatus object for the Build that I control."""
1001 def stopBuild(reason="<no reason given>"):
1002 """Halt the build. This has no effect if the build has already
1003 finished."""
1005 class ILogFile(Interface):
1006 """This is the internal interface to a LogFile, used by the BuildStep to
1007 write data into the log.
1009 def addStdout(data):
1010 pass
1011 def addStderr(data):
1012 pass
1013 def addHeader(data):
1014 pass
1015 def finish():
1016 """The process that is feeding the log file has finished, and no
1017 further data will be added. This closes the logfile."""
1019 class ILogObserver(Interface):
1020 """Objects which provide this interface can be used in a BuildStep to
1021 watch the output of a LogFile and parse it incrementally.
1024 # internal methods
1025 def setStep(step):
1026 pass
1027 def setLog(log):
1028 pass
1030 # methods called by the LogFile
1031 def logChunk(build, step, log, channel, text):
1032 pass