Skip to content

Commit

Permalink
warn on use of old-style log methods in new-style steps
Browse files Browse the repository at this point in the history
  • Loading branch information
djmitche committed Mar 3, 2014
1 parent 08b078d commit beaa12d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
1 change: 1 addition & 0 deletions master/buildbot/process/buildstep.py
Expand Up @@ -460,6 +460,7 @@ def addLog(self, name):
loog = self._step_status.addLog(name)
self._connectPendingLogObservers()
if self.isNewStyle():
loog._isNewStyle = True
return defer.succeed(loog)
else:
return loog
Expand Down
9 changes: 9 additions & 0 deletions master/buildbot/status/logfile.py
Expand Up @@ -212,6 +212,7 @@ class LogFile:
BUFFERSIZE = 2048
filename = None # relative to the Builder's basedir
openfile = None
_isNewStyle = False # set to True by new-style buildsteps

def __init__(self, parent, name, logfilename):
"""
Expand Down Expand Up @@ -259,6 +260,7 @@ def hasContents(self):
@returns: boolean
"""
assert not self._isNewStyle, "not available in new-style steps"
return os.path.exists(self.getFilename() + '.bz2') or \
os.path.exists(self.getFilename() + '.gz') or \
os.path.exists(self.getFilename())
Expand Down Expand Up @@ -328,9 +330,11 @@ def getFile(self):

def getText(self):
# this produces one ginormous string
assert not self._isNewStyle, "not available in new-style steps"
return "".join(self.getChunks([STDOUT, STDERR], onlyText=True))

def getTextWithHeaders(self):
assert not self._isNewStyle, "not available in new-style steps"
return "".join(self.getChunks(onlyText=True))

def getChunks(self, channels=[], onlyText=False):
Expand All @@ -346,6 +350,8 @@ def getChunks(self, channels=[], onlyText=False):
# data, you must insure that nothing will be added to the log during
# yield() calls.

assert not self._isNewStyle, "not available in new-style steps"

f = self.getFile()
if not self.finished:
offset = 0
Expand Down Expand Up @@ -404,11 +410,13 @@ def _generateChunks(self, f, offset, remaining, leftover,
def readlines(self):
"""Return an iterator that produces newline-terminated lines,
excluding header chunks."""
assert not self._isNewStyle, "not available in new-style steps"
alltext = "".join(self.getChunks([STDOUT], onlyText=True))
io = StringIO(alltext)
return io.readlines()

def subscribe(self, receiver, catchup):
assert not self._isNewStyle, "not available in new-style steps"
if self.finished:
return
self.watchers.append(receiver)
Expand All @@ -423,6 +431,7 @@ def unsubscribe(self, receiver):
self.watchers.remove(receiver)

def subscribeConsumer(self, consumer):
assert not self._isNewStyle, "not available in new-style steps"
p = LogFileProducer(self, consumer)
p.resumeProducing()

Expand Down
3 changes: 3 additions & 0 deletions master/buildbot/test/integration/test_custom_buildstep.py
Expand Up @@ -287,6 +287,9 @@ def buildFinished(*args):

def assertLogs(self, exp_logs):
bs = self.master.status.lastBuilderStatus.lastBuildStatus
# tell the steps they're not new-style anymore, so they don't assert
for l in bs.getLogs():
l._isNewStyle = False
got_logs = dict((l.name, l.getText()) for l in bs.getLogs())
self.assertEqual(got_logs, exp_logs)

Expand Down

0 comments on commit beaa12d

Please sign in to comment.