Allow users to specify the remote git branch.
[buildbot.git] / buildbot / interfaces.py
blobdcfb3379294deb270766305065366f3725239f68
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()."""
310 class ISlaveStatus(Interface):
311 def getName():
312 """Return the name of the build slave."""
314 def getAdmin():
315 """Return a string with the slave admin's contact data."""
317 def getHost():
318 """Return a string with the slave host info."""
320 def isConnected():
321 """Return True if the slave is currently online, False if not."""
323 def lastMessageReceived():
324 """Return a timestamp (seconds since epoch) indicating when the most
325 recent message was received from the buildslave."""
327 class ISchedulerStatus(Interface):
328 def getName():
329 """Return the name of this Scheduler (a string)."""
331 def getPendingBuildsets():
332 """Return an IBuildSet for all BuildSets that are pending. These
333 BuildSets are waiting for their tree-stable-timers to expire."""
334 # TODO: this is not implemented anywhere
337 class IBuilderStatus(Interface):
338 def getName():
339 """Return the name of this Builder (a string)."""
341 def getState():
342 # TODO: this isn't nearly as meaningful as it used to be
343 """Return a tuple (state, builds) for this Builder. 'state' is the
344 so-called 'big-status', indicating overall status (as opposed to
345 which step is currently running). It is a string, one of 'offline',
346 'idle', or 'building'. 'builds' is a list of IBuildStatus objects
347 (possibly empty) representing the currently active builds."""
349 def getSlaves():
350 """Return a list of ISlaveStatus objects for the buildslaves that are
351 used by this builder."""
353 def getPendingBuilds():
354 """Return an IBuildRequestStatus object for all upcoming builds
355 (those which are ready to go but which are waiting for a buildslave
356 to be available."""
358 def getCurrentBuilds():
359 """Return a list containing an IBuildStatus object for each build
360 currently in progress."""
361 # again, we could probably provide an object for 'waiting' and
362 # 'interlocked' too, but things like the Change list might still be
363 # subject to change
365 def getLastFinishedBuild():
366 """Return the IBuildStatus object representing the last finished
367 build, which may be None if the builder has not yet finished any
368 builds."""
370 def getBuild(number):
371 """Return an IBuildStatus object for a historical build. Each build
372 is numbered (starting at 0 when the Builder is first added),
373 getBuild(n) will retrieve the Nth such build. getBuild(-n) will
374 retrieve a recent build, with -1 being the most recent build
375 started. If the Builder is idle, this will be the same as
376 getLastFinishedBuild(). If the Builder is active, it will be an
377 unfinished build. This method will return None if the build is no
378 longer available. Older builds are likely to have less information
379 stored: Logs are the first to go, then Steps."""
381 def getEvent(number):
382 """Return an IStatusEvent object for a recent Event. Builders
383 connecting and disconnecting are events, as are ping attempts.
384 getEvent(-1) will return the most recent event. Events are numbered,
385 but it probably doesn't make sense to ever do getEvent(+n)."""
387 def generateFinishedBuilds(branches=[],
388 num_builds=None,
389 max_buildnum=None, finished_before=None,
390 max_search=200,
392 """Return a generator that will produce IBuildStatus objects each
393 time you invoke its .next() method, starting with the most recent
394 finished build, then the previous build, and so on back to the oldest
395 build available.
397 @param branches: this is a list of branch names, and the generator
398 will only produce builds that involve the given
399 branches. If the list is empty, the generator will
400 produce all builds regardless of what branch they
401 used.
403 @param num_builds: if provided, the generator will stop after
404 providing this many builds. The default of None
405 means to produce as many builds as possible.
407 @param max_buildnum: if provided, the generator will start by
408 providing the build with this number, or the
409 highest-numbered preceding build (i.e. the
410 generator will not produce any build numbered
411 *higher* than max_buildnum). The default of None
412 means to start with the most recent finished
413 build. -1 means the same as None. -2 means to
414 start with the next-most-recent completed build,
415 etc.
417 @type finished_before: int: a timestamp, seconds since the epoch
418 @param finished_before: if provided, do not produce any builds that
419 finished after the given timestamp.
421 @type max_search: int
422 @param max_search: this method may have to examine a lot of builds
423 to find some that match the search parameters,
424 especially if there aren't any matching builds.
425 This argument imposes a hard limit on the number
426 of builds that will be examined.
429 def subscribe(receiver):
430 """Register an IStatusReceiver to receive new status events. The
431 receiver will be given builderChangedState, buildStarted, and
432 buildFinished messages."""
434 def unsubscribe(receiver):
435 """Unregister an IStatusReceiver. No further status messgaes will be
436 delivered."""
438 class IEventSource(Interface):
439 def eventGenerator(branches=[]):
440 """This function creates a generator which will yield all of this
441 object's status events, starting with the most recent and progressing
442 backwards in time. These events provide the IStatusEvent interface.
443 At the moment they are all instances of buildbot.status.builder.Event
444 or buildbot.status.builder.BuildStepStatus .
446 @param branches: a list of branch names. The generator should only
447 return events that are associated with these branches. If the list is
448 empty, events for all branches should be returned (i.e. an empty list
449 means 'accept all' rather than 'accept none').
452 class IBuildStatus(Interface):
453 """I represent the status of a single Build/BuildRequest. It could be
454 in-progress or finished."""
456 def getBuilder():
458 Return the BuilderStatus that owns this build.
460 @rtype: implementor of L{IBuilderStatus}
463 def isFinished():
464 """Return a boolean. True means the build has finished, False means
465 it is still running."""
467 def waitUntilFinished():
468 """Return a Deferred that will fire when the build finishes. If the
469 build has already finished, this deferred will fire right away. The
470 callback is given this IBuildStatus instance as an argument."""
472 def getProperty(propname):
473 """Return the value of the build property with the given name. Raises
474 KeyError if there is no such property on this build."""
476 def getReason():
477 """Return a string that indicates why the build was run. 'changes',
478 'forced', and 'periodic' are the most likely values. 'try' will be
479 added in the future."""
481 def getSourceStamp():
482 """Return a SourceStamp object which can be used to re-create
483 the source tree that this build used.
485 This method will return None if the source information is no longer
486 available."""
487 # TODO: it should be possible to expire the patch but still remember
488 # that the build was r123+something.
490 def getChanges():
491 """Return a list of Change objects which represent which source
492 changes went into the build."""
494 def getResponsibleUsers():
495 """Return a list of Users who are to blame for the changes that went
496 into this build. If anything breaks (at least anything that wasn't
497 already broken), blame them. Specifically, this is the set of users
498 who were responsible for the Changes that went into this build. Each
499 User is a string, corresponding to their name as known by the VC
500 repository."""
502 def getInterestedUsers():
503 """Return a list of Users who will want to know about the results of
504 this build. This is a superset of getResponsibleUsers(): it adds
505 people who are interested in this build but who did not actually
506 make the Changes that went into it (build sheriffs, code-domain
507 owners)."""
509 def getNumber():
510 """Within each builder, each Build has a number. Return it."""
512 def getPreviousBuild():
513 """Convenience method. Returns None if the previous build is
514 unavailable."""
516 def getSteps():
517 """Return a list of IBuildStepStatus objects. For invariant builds
518 (those which always use the same set of Steps), this should always
519 return the complete list, however some of the steps may not have
520 started yet (step.getTimes()[0] will be None). For variant builds,
521 this may not be complete (asking again later may give you more of
522 them)."""
524 def getTimes():
525 """Returns a tuple of (start, end). 'start' and 'end' are the times
526 (seconds since the epoch) when the Build started and finished. If
527 the build is still running, 'end' will be None."""
529 # while the build is running, the following methods make sense.
530 # Afterwards they return None
532 def getETA():
533 """Returns the number of seconds from now in which the build is
534 expected to finish, or None if we can't make a guess. This guess will
535 be refined over time."""
537 def getCurrentStep():
538 """Return an IBuildStepStatus object representing the currently
539 active step."""
541 # Once you know the build has finished, the following methods are legal.
542 # Before ths build has finished, they all return None.
544 def getSlavename():
545 """Return the name of the buildslave which handled this build."""
547 def getText():
548 """Returns a list of strings to describe the build. These are
549 intended to be displayed in a narrow column. If more space is
550 available, the caller should join them together with spaces before
551 presenting them to the user."""
553 def getColor():
554 """Returns a single string with the color that should be used to
555 display the build. 'green', 'orange', or 'red' are the most likely
556 ones."""
558 def getResults():
559 """Return a constant describing the results of the build: one of the
560 constants in buildbot.status.builder: SUCCESS, WARNINGS, or
561 FAILURE."""
563 def getLogs():
564 """Return a list of logs that describe the build as a whole. Some
565 steps will contribute their logs, while others are are less important
566 and will only be accessible through the IBuildStepStatus objects.
567 Each log is an object which implements the IStatusLog interface."""
569 def getTestResults():
570 """Return a dictionary that maps test-name tuples to ITestResult
571 objects. This may return an empty or partially-filled dictionary
572 until the build has completed."""
574 # subscription interface
576 def subscribe(receiver, updateInterval=None):
577 """Register an IStatusReceiver to receive new status events. The
578 receiver will be given stepStarted and stepFinished messages. If
579 'updateInterval' is non-None, buildETAUpdate messages will be sent
580 every 'updateInterval' seconds."""
582 def unsubscribe(receiver):
583 """Unregister an IStatusReceiver. No further status messgaes will be
584 delivered."""
586 class ITestResult(Interface):
587 """I describe the results of a single unit test."""
589 def getName():
590 """Returns a tuple of strings which make up the test name. Tests may
591 be arranged in a hierarchy, so looking for common prefixes may be
592 useful."""
594 def getResults():
595 """Returns a constant describing the results of the test: SUCCESS,
596 WARNINGS, FAILURE."""
598 def getText():
599 """Returns a list of short strings which describe the results of the
600 test in slightly more detail. Suggested components include
601 'failure', 'error', 'passed', 'timeout'."""
603 def getLogs():
604 # in flux, it may be possible to provide more structured information
605 # like python Failure instances
606 """Returns a dictionary of test logs. The keys are strings like
607 'stdout', 'log', 'exceptions'. The values are strings."""
610 class IBuildStepStatus(Interface):
611 """I hold status for a single BuildStep."""
613 def getName():
614 """Returns a short string with the name of this step. This string
615 may have spaces in it."""
617 def getBuild():
618 """Returns the IBuildStatus object which contains this step."""
620 def getTimes():
621 """Returns a tuple of (start, end). 'start' and 'end' are the times
622 (seconds since the epoch) when the Step started and finished. If the
623 step has not yet started, 'start' will be None. If the step is still
624 running, 'end' will be None."""
626 def getExpectations():
627 """Returns a list of tuples (name, current, target). Each tuple
628 describes a single axis along which the step's progress can be
629 measured. 'name' is a string which describes the axis itself, like
630 'filesCompiled' or 'tests run' or 'bytes of output'. 'current' is a
631 number with the progress made so far, while 'target' is the value
632 that we expect (based upon past experience) to get to when the build
633 is finished.
635 'current' will change over time until the step is finished. It is
636 'None' until the step starts. When the build is finished, 'current'
637 may or may not equal 'target' (which is merely the expectation based
638 upon previous builds)."""
640 def getURLs():
641 """Returns a dictionary of URLs. Each key is a link name (a short
642 string, like 'results' or 'coverage'), and each value is a URL. These
643 links will be displayed along with the LogFiles.
646 def getLogs():
647 """Returns a list of IStatusLog objects. If the step has not yet
648 finished, this list may be incomplete (asking again later may give
649 you more of them)."""
652 def isFinished():
653 """Return a boolean. True means the step has finished, False means it
654 is still running."""
656 def waitUntilFinished():
657 """Return a Deferred that will fire when the step finishes. If the
658 step has already finished, this deferred will fire right away. The
659 callback is given this IBuildStepStatus instance as an argument."""
661 # while the step is running, the following methods make sense.
662 # Afterwards they return None
664 def getETA():
665 """Returns the number of seconds from now in which the step is
666 expected to finish, or None if we can't make a guess. This guess will
667 be refined over time."""
669 # Once you know the step has finished, the following methods are legal.
670 # Before ths step has finished, they all return None.
672 def getText():
673 """Returns a list of strings which describe the step. These are
674 intended to be displayed in a narrow column. If more space is
675 available, the caller should join them together with spaces before
676 presenting them to the user."""
678 def getColor():
679 """Returns a single string with the color that should be used to
680 display this step. 'green', 'orange', 'red' and 'yellow' are the
681 most likely ones."""
683 def getResults():
684 """Return a tuple describing the results of the step: (result,
685 strings). 'result' is one of the constants in
686 buildbot.status.builder: SUCCESS, WARNINGS, FAILURE, or SKIPPED.
687 'strings' is an optional list of strings that the step wants to
688 append to the overall build's results. These strings are usually
689 more terse than the ones returned by getText(): in particular,
690 successful Steps do not usually contribute any text to the overall
691 build."""
693 # subscription interface
695 def subscribe(receiver, updateInterval=10):
696 """Register an IStatusReceiver to receive new status events. The
697 receiver will be given logStarted and logFinished messages. It will
698 also be given a ETAUpdate message every 'updateInterval' seconds."""
700 def unsubscribe(receiver):
701 """Unregister an IStatusReceiver. No further status messgaes will be
702 delivered."""
704 class IStatusEvent(Interface):
705 """I represent a Builder Event, something non-Build related that can
706 happen to a Builder."""
708 def getTimes():
709 """Returns a tuple of (start, end) like IBuildStepStatus, but end==0
710 indicates that this is a 'point event', which has no duration.
711 SlaveConnect/Disconnect are point events. Ping is not: it starts
712 when requested and ends when the response (positive or negative) is
713 returned"""
715 def getText():
716 """Returns a list of strings which describe the event. These are
717 intended to be displayed in a narrow column. If more space is
718 available, the caller should join them together with spaces before
719 presenting them to the user."""
721 def getColor():
722 """Returns a single string with the color that should be used to
723 display this event. 'red' and 'yellow' are the most likely ones."""
726 LOG_CHANNEL_STDOUT = 0
727 LOG_CHANNEL_STDERR = 1
728 LOG_CHANNEL_HEADER = 2
730 class IStatusLog(Interface):
731 """I represent a single Log, which is a growing list of text items that
732 contains some kind of output for a single BuildStep. I might be finished,
733 in which case this list has stopped growing.
735 Each Log has a name, usually something boring like 'log' or 'output'.
736 These names are not guaranteed to be unique, however they are usually
737 chosen to be useful within the scope of a single step (i.e. the Compile
738 step might produce both 'log' and 'warnings'). The name may also have
739 spaces. If you want something more globally meaningful, at least within a
740 given Build, try::
742 '%s.%s' % (log.getStep.getName(), log.getName())
744 The Log can be presented as plain text, or it can be accessed as a list
745 of items, each of which has a channel indicator (header, stdout, stderr)
746 and a text chunk. An HTML display might represent the interleaved
747 channels with different styles, while a straight download-the-text
748 interface would just want to retrieve a big string.
750 The 'header' channel is used by ShellCommands to prepend a note about
751 which command is about to be run ('running command FOO in directory
752 DIR'), and append another note giving the exit code of the process.
754 Logs can be streaming: if the Log has not yet finished, you can
755 subscribe to receive new chunks as they are added.
757 A ShellCommand will have a Log associated with it that gathers stdout
758 and stderr. Logs may also be created by parsing command output or
759 through other synthetic means (grepping for all the warnings in a
760 compile log, or listing all the test cases that are going to be run).
761 Such synthetic Logs are usually finished as soon as they are created."""
764 def getName():
765 """Returns a short string with the name of this log, probably 'log'.
768 def getStep():
769 """Returns the IBuildStepStatus which owns this log."""
770 # TODO: can there be non-Step logs?
772 def isFinished():
773 """Return a boolean. True means the log has finished and is closed,
774 False means it is still open and new chunks may be added to it."""
776 def waitUntilFinished():
777 """Return a Deferred that will fire when the log is closed. If the
778 log has already finished, this deferred will fire right away. The
779 callback is given this IStatusLog instance as an argument."""
781 def subscribe(receiver, catchup):
782 """Register an IStatusReceiver to receive chunks (with logChunk) as
783 data is added to the Log. If you use this, you will also want to use
784 waitUntilFinished to find out when the listener can be retired.
785 Subscribing to a closed Log is a no-op.
787 If 'catchup' is True, the receiver will immediately be sent a series
788 of logChunk messages to bring it up to date with the partially-filled
789 log. This allows a status client to join a Log already in progress
790 without missing any data. If the Log has already finished, it is too
791 late to catch up: just do getText() instead.
793 If the Log is very large, the receiver will be called many times with
794 a lot of data. There is no way to throttle this data. If the receiver
795 is planning on sending the data on to somewhere else, over a narrow
796 connection, you can get a throttleable subscription by using
797 C{subscribeConsumer} instead."""
799 def unsubscribe(receiver):
800 """Remove a receiver previously registered with subscribe(). Attempts
801 to remove a receiver which was not previously registered is a no-op.
804 def subscribeConsumer(consumer):
805 """Register an L{IStatusLogConsumer} to receive all chunks of the
806 logfile, including all the old entries and any that will arrive in
807 the future. The consumer will first have their C{registerProducer}
808 method invoked with a reference to an object that can be told
809 C{pauseProducing}, C{resumeProducing}, and C{stopProducing}. Then the
810 consumer's C{writeChunk} method will be called repeatedly with each
811 (channel, text) tuple in the log, starting with the very first. The
812 consumer will be notified with C{finish} when the log has been
813 exhausted (which can only happen when the log is finished). Note that
814 a small amount of data could be written via C{writeChunk} even after
815 C{pauseProducing} has been called.
817 To unsubscribe the consumer, use C{producer.stopProducing}."""
819 # once the log has finished, the following methods make sense. They can
820 # be called earlier, but they will only return the contents of the log up
821 # to the point at which they were called. You will lose items that are
822 # added later. Use C{subscribe} or C{subscribeConsumer} to avoid missing
823 # anything.
825 def hasContents():
826 """Returns True if the LogFile still has contents available. Returns
827 False for logs that have been pruned. Clients should test this before
828 offering to show the contents of any log."""
830 def getText():
831 """Return one big string with the contents of the Log. This merges
832 all non-header chunks together."""
834 def readlines(channel=LOG_CHANNEL_STDOUT):
835 """Read lines from one channel of the logfile. This returns an
836 iterator that will provide single lines of text (including the
837 trailing newline).
840 def getTextWithHeaders():
841 """Return one big string with the contents of the Log. This merges
842 all chunks (including headers) together."""
844 def getChunks():
845 """Generate a list of (channel, text) tuples. 'channel' is a number,
846 0 for stdout, 1 for stderr, 2 for header. (note that stderr is merged
847 into stdout if PTYs are in use)."""
849 class IStatusLogConsumer(Interface):
850 """I am an object which can be passed to IStatusLog.subscribeConsumer().
851 I represent a target for writing the contents of an IStatusLog. This
852 differs from a regular IStatusReceiver in that it can pause the producer.
853 This makes it more suitable for use in streaming data over network
854 sockets, such as an HTTP request. Note that the consumer can only pause
855 the producer until it has caught up with all the old data. After that
856 point, C{pauseProducing} is ignored and all new output from the log is
857 sent directoy to the consumer."""
859 def registerProducer(producer, streaming):
860 """A producer is being hooked up to this consumer. The consumer only
861 has to handle a single producer. It should send .pauseProducing and
862 .resumeProducing messages to the producer when it wants to stop or
863 resume the flow of data. 'streaming' will be set to True because the
864 producer is always a PushProducer.
867 def unregisterProducer():
868 """The previously-registered producer has been removed. No further
869 pauseProducing or resumeProducing calls should be made. The consumer
870 should delete its reference to the Producer so it can be released."""
872 def writeChunk(chunk):
873 """A chunk (i.e. a tuple of (channel, text)) is being written to the
874 consumer."""
876 def finish():
877 """The log has finished sending chunks to the consumer."""
879 class IStatusReceiver(Interface):
880 """I am an object which can receive build status updates. I may be
881 subscribed to an IStatus, an IBuilderStatus, or an IBuildStatus."""
883 def buildsetSubmitted(buildset):
884 """A new BuildSet has been submitted to the buildmaster.
886 @type buildset: implementor of L{IBuildSetStatus}
889 def builderAdded(builderName, builder):
891 A new Builder has just been added. This method may return an
892 IStatusReceiver (probably 'self') which will be subscribed to receive
893 builderChangedState and buildStarted/Finished events.
895 @type builderName: string
896 @type builder: L{buildbot.status.builder.BuilderStatus}
897 @rtype: implementor of L{IStatusReceiver}
900 def builderChangedState(builderName, state):
901 """Builder 'builderName' has changed state. The possible values for
902 'state' are 'offline', 'idle', and 'building'."""
904 def buildStarted(builderName, build):
905 """Builder 'builderName' has just started a build. The build is an
906 object which implements IBuildStatus, and can be queried for more
907 information.
909 This method may return an IStatusReceiver (it could even return
910 'self'). If it does so, stepStarted and stepFinished methods will be
911 invoked on the object for the steps of this one build. This is a
912 convenient way to subscribe to all build steps without missing any.
913 This receiver will automatically be unsubscribed when the build
914 finishes.
916 It can also return a tuple of (IStatusReceiver, interval), in which
917 case buildETAUpdate messages are sent ever 'interval' seconds, in
918 addition to the stepStarted and stepFinished messages."""
920 def buildETAUpdate(build, ETA):
921 """This is a periodic update on the progress this Build has made
922 towards completion."""
924 def stepStarted(build, step):
925 """A step has just started. 'step' is the IBuildStepStatus which
926 represents the step: it can be queried for more information.
928 This method may return an IStatusReceiver (it could even return
929 'self'). If it does so, logStarted and logFinished methods will be
930 invoked on the object for logs created by this one step. This
931 receiver will be automatically unsubscribed when the step finishes.
933 Alternatively, the method may return a tuple of an IStatusReceiver
934 and an integer named 'updateInterval'. In addition to
935 logStarted/logFinished messages, it will also receive stepETAUpdate
936 messages about every updateInterval seconds."""
938 def stepTextChanged(build, step, text):
939 """The text for a step has been updated.
941 This is called when calling setText() on the step status, and
942 hands in the text list."""
944 def stepText2Changed(build, step, text2):
945 """The text2 for a step has been updated.
947 This is called when calling setText2() on the step status, and
948 hands in text2 list."""
950 def stepETAUpdate(build, step, ETA, expectations):
951 """This is a periodic update on the progress this Step has made
952 towards completion. It gets an ETA (in seconds from the present) of
953 when the step ought to be complete, and a list of expectation tuples
954 (as returned by IBuildStepStatus.getExpectations) with more detailed
955 information."""
957 def logStarted(build, step, log):
958 """A new Log has been started, probably because a step has just
959 started running a shell command. 'log' is the IStatusLog object
960 which can be queried for more information.
962 This method may return an IStatusReceiver (such as 'self'), in which
963 case the target's logChunk method will be invoked as text is added to
964 the logfile. This receiver will automatically be unsubsribed when the
965 log finishes."""
967 def logChunk(build, step, log, channel, text):
968 """Some text has been added to this log. 'channel' is one of
969 LOG_CHANNEL_STDOUT, LOG_CHANNEL_STDERR, or LOG_CHANNEL_HEADER, as
970 defined in IStatusLog.getChunks."""
972 def logFinished(build, step, log):
973 """A Log has been closed."""
975 def stepFinished(build, step, results):
976 """A step has just finished. 'results' is the result tuple described
977 in IBuildStepStatus.getResults."""
979 def buildFinished(builderName, build, results):
981 A build has just finished. 'results' is the result tuple described
982 in L{IBuildStatus.getResults}.
984 @type builderName: string
985 @type build: L{buildbot.status.builder.BuildStatus}
986 @type results: tuple
989 def builderRemoved(builderName):
990 """The Builder has been removed."""
992 class IControl(Interface):
993 def addChange(change):
994 """Add a change to all builders. Each Builder will decide for
995 themselves whether the change is interesting or not, and may initiate
996 a build as a result."""
998 def submitBuildSet(buildset):
999 """Submit a BuildSet object, which will eventually be run on all of
1000 the builders listed therein."""
1002 def getBuilder(name):
1003 """Retrieve the IBuilderControl object for the given Builder."""
1005 class IBuilderControl(Interface):
1006 def requestBuild(request):
1007 """Queue a L{buildbot.process.base.BuildRequest} object for later
1008 building."""
1010 def requestBuildSoon(request):
1011 """Submit a BuildRequest like requestBuild, but raise a
1012 L{buildbot.interfaces.NoSlaveError} if no slaves are currently
1013 available, so it cannot be used to queue a BuildRequest in the hopes
1014 that a slave will eventually connect. This method is appropriate for
1015 use by things like the web-page 'Force Build' button."""
1017 def resubmitBuild(buildStatus, reason="<rebuild, no reason given>"):
1018 """Rebuild something we've already built before. This submits a
1019 BuildRequest to our Builder using the same SourceStamp as the earlier
1020 build. This has no effect (but may eventually raise an exception) if
1021 this Build has not yet finished."""
1023 def getPendingBuilds():
1024 """Return a list of L{IBuildRequestControl} objects for this Builder.
1025 Each one corresponds to a pending build that has not yet started (due
1026 to a scarcity of build slaves). These upcoming builds can be canceled
1027 through the control object."""
1029 def getBuild(number):
1030 """Attempt to return an IBuildControl object for the given build.
1031 Returns None if no such object is available. This will only work for
1032 the build that is currently in progress: once the build finishes,
1033 there is nothing to control anymore."""
1035 def ping(timeout=30):
1036 """Attempt to contact the slave and see if it is still alive. This
1037 returns a Deferred which fires with either True (the slave is still
1038 alive) or False (the slave did not respond). As a side effect, adds
1039 an event to this builder's column in the waterfall display
1040 containing the results of the ping."""
1041 # TODO: this ought to live in ISlaveControl, maybe with disconnect()
1042 # or something. However the event that is emitted is most useful in
1043 # the Builder column, so it kinda fits here too.
1045 class IBuildRequestControl(Interface):
1046 def subscribe(observer):
1047 """Register a callable that will be invoked (with a single
1048 IBuildControl object) for each Build that is created to satisfy this
1049 request. There may be multiple Builds created in an attempt to handle
1050 the request: they may be interrupted by the user or abandoned due to
1051 a lost slave. The last Build (the one which actually gets to run to
1052 completion) is said to 'satisfy' the BuildRequest. The observer will
1053 be called once for each of these Builds, both old and new."""
1054 def unsubscribe(observer):
1055 """Unregister the callable that was registered with subscribe()."""
1056 def cancel():
1057 """Remove the build from the pending queue. Has no effect if the
1058 build has already been started."""
1060 class IBuildControl(Interface):
1061 def getStatus():
1062 """Return an IBuildStatus object for the Build that I control."""
1063 def stopBuild(reason="<no reason given>"):
1064 """Halt the build. This has no effect if the build has already
1065 finished."""
1067 class ILogFile(Interface):
1068 """This is the internal interface to a LogFile, used by the BuildStep to
1069 write data into the log.
1071 def addStdout(data):
1072 pass
1073 def addStderr(data):
1074 pass
1075 def addHeader(data):
1076 pass
1077 def finish():
1078 """The process that is feeding the log file has finished, and no
1079 further data will be added. This closes the logfile."""
1081 class ILogObserver(Interface):
1082 """Objects which provide this interface can be used in a BuildStep to
1083 watch the output of a LogFile and parse it incrementally.
1086 # internal methods
1087 def setStep(step):
1088 pass
1089 def setLog(log):
1090 pass
1092 # methods called by the LogFile
1093 def logChunk(build, step, log, channel, text):
1094 pass
1096 class IBuildSlave(Interface):
1097 # this is a marker interface for the BuildSlave class
1098 pass
1100 class ILatentBuildSlave(IBuildSlave):
1101 """A build slave that is not always running, but can run when requested.
1103 substantiated = Attribute('Substantiated',
1104 'Whether the latent build slave is currently '
1105 'substantiated with a real instance.')
1107 def substantiate():
1108 """Request that the slave substantiate with a real instance.
1110 Returns a deferred that will callback when a real instance has
1111 attached."""
1113 # there is an insubstantiate too, but that is not used externally ATM.
1115 def buildStarted(sb):
1116 """Inform the latent build slave that a build has started.
1118 ``sb`` is a LatentSlaveBuilder as defined in buildslave.py. The sb
1119 is the one for whom the build started.
1122 def buildFinished(sb):
1123 """Inform the latent build slave that a build has finished.
1125 ``sb`` is a LatentSlaveBuilder as defined in buildslave.py. The sb
1126 is the one for whom the build finished.