Skip to content

Commit

Permalink
Pulled runTransferCommand up to _TransferBuildStep
Browse files Browse the repository at this point in the history
Formerly runUploadCommand of MultipleFileUpload.
The runTransferCommand function adds a callback to extract the result
from the command instance and (optionally) ann error callback to
cancel the command's writer.
  • Loading branch information
jpommerening committed Nov 29, 2013
1 parent d8b8277 commit a5a65e8
Showing 1 changed file with 28 additions and 56 deletions.
84 changes: 28 additions & 56 deletions master/buildbot/steps/transfer.py
Expand Up @@ -222,23 +222,30 @@ def _getWorkdir(self):
workdir = self.workdir
return workdir

def runTransferCommand(self, cmd, writer=None):
# Run a transfer step, add a callback to extract the command status,
# add an error handler that cancels the writer.
self.cmd = cmd
d = self.runCommand(cmd)

@d.addCallback
def checkResult(_):
return FAILURE if cmd.didFail() else SUCCESS

@d.addErrback
def cancel(res):
if writer:
writer.cancel()
return res

return d

def interrupt(self, reason):
self.addCompleteLog('interrupt', str(reason))
if self.cmd:
d = self.cmd.interrupt(reason)
return d

def finished(self, result):
# Subclasses may choose to skip a transfer. In those cases, self.cmd
# will be None, and we should just let BuildStep.finished() handle
# the rest
if result == SKIPPED:
return BuildStep.finished(self, SKIPPED)

if self.cmd.didFail():
return BuildStep.finished(self, FAILURE)
return BuildStep.finished(self, SUCCESS)


class FileUpload(_TransferBuildStep):

Expand Down Expand Up @@ -298,13 +305,8 @@ def start(self):
'keepstamp': self.keepstamp,
}

self.cmd = makeStatusRemoteCommand(self, 'uploadFile', args)
d = self.runCommand(self.cmd)

@d.addErrback
def cancel(res):
fileWriter.cancel()
return res
cmd = makeStatusRemoteCommand(self, 'uploadFile', args)
d = self.runTransferCommand(cmd, fileWriter)
d.addCallback(self.finished).addErrback(self.failed)


Expand Down Expand Up @@ -359,26 +361,10 @@ def start(self):
'compress': self.compress
}

self.cmd = makeStatusRemoteCommand(self, 'uploadDirectory', args)
d = self.runCommand(self.cmd)

@d.addErrback
def cancel(res):
dirWriter.cancel()
return res
cmd = makeStatusRemoteCommand(self, 'uploadDirectory', args)
d = self.runTransferCommand(cmd, dirWriter)
d.addCallback(self.finished).addErrback(self.failed)

def finished(self, result):
# Subclasses may choose to skip a transfer. In those cases, self.cmd
# will be None, and we should just let BuildStep.finished() handle
# the rest
if result == SKIPPED:
return BuildStep.finished(self, SKIPPED)

if self.cmd.didFail():
return BuildStep.finished(self, FAILURE)
return BuildStep.finished(self, SUCCESS)


class MultipleFileUpload(_TransferBuildStep):

Expand Down Expand Up @@ -406,20 +392,6 @@ def __init__(self, slavesrcs, masterdest,
self.keepstamp = keepstamp
self.url = url

def runUploadCommand(self, cmd, writer):
d = self.runCommand(cmd)

@d.addCallback
def checkResult(_):
return FAILURE if cmd.didFail() else SUCCESS

@d.addErrback
def cancel(res):
writer.cancel()
return res

return d

def uploadFile(self, source, masterdest):
fileWriter = _FileWriter(masterdest, self.maxsize, self.mode)

Expand All @@ -433,7 +405,7 @@ def uploadFile(self, source, masterdest):
}

cmd = makeStatusRemoteCommand(self, 'uploadFile', args)
return self.runUploadCommand(cmd, fileWriter)
return self.runTransferCommand(cmd, fileWriter)

def uploadDirectory(self, source, masterdest):
dirWriter = _DirectoryWriter(masterdest, self.maxsize, self.compress, 0600)
Expand All @@ -448,7 +420,7 @@ def uploadDirectory(self, source, masterdest):
}

cmd = makeStatusRemoteCommand(self, 'uploadDirectory', args)
return self.runUploadCommand(cmd, dirWriter)
return self.runTransferCommand(cmd, dirWriter)

def startUpload(self, source, destdir):
masterdest = os.path.join(destdir, os.path.basename(source))
Expand Down Expand Up @@ -619,8 +591,8 @@ def start(self):
'mode': self.mode,
}

self.cmd = makeStatusRemoteCommand(self, 'downloadFile', args)
d = self.runCommand(self.cmd)
cmd = makeStatusRemoteCommand(self, 'downloadFile', args)
d = self.runTransferCommand(cmd)
d.addCallback(self.finished).addErrback(self.failed)


Expand Down Expand Up @@ -671,8 +643,8 @@ def start(self):
'mode': self.mode,
}

self.cmd = makeStatusRemoteCommand(self, 'downloadFile', args)
d = self.runCommand(self.cmd)
cmd = makeStatusRemoteCommand(self, 'downloadFile', args)
d = self.runTransferCommand(cmd)
d.addCallback(self.finished).addErrback(self.failed)


Expand Down

0 comments on commit a5a65e8

Please sign in to comment.