Package buildbot :: Package steps :: Module master
[frames] | no frames]

Source Code for Module buildbot.steps.master

  1  # This file is part of Buildbot.  Buildbot is free software: you can 
  2  # redistribute it and/or modify it under the terms of the GNU General Public 
  3  # License as published by the Free Software Foundation, version 2. 
  4  # 
  5  # This program is distributed in the hope that it will be useful, but WITHOUT 
  6  # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 
  7  # FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more 
  8  # details. 
  9  # 
 10  # You should have received a copy of the GNU General Public License along with 
 11  # this program; if not, write to the Free Software Foundation, Inc., 51 
 12  # Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. 
 13  # 
 14  # Copyright Buildbot Team Members 
 15   
 16  import os, types 
 17  from twisted.python import runtime 
 18  from twisted.internet import reactor  
 19  from buildbot.process.buildstep import BuildStep 
 20  from buildbot.process.buildstep import SUCCESS, FAILURE 
 21  from twisted.internet.protocol import ProcessProtocol 
 22   
23 -class MasterShellCommand(BuildStep):
24 """ 25 Run a shell command locally - on the buildmaster. The shell command 26 COMMAND is specified just as for a RemoteShellCommand. Note that extra 27 logfiles are not supported. 28 """ 29 name='MasterShellCommand' 30 description='Running' 31 descriptionDone='Ran' 32 renderables = [ 'command' ] 33 haltOnFailure = True 34 flunkOnFailure = True 35
36 - def __init__(self, command, 37 description=None, descriptionDone=None, 38 env=None, path=None, usePTY=0, 39 **kwargs):
40 BuildStep.__init__(self, **kwargs) 41 self.addFactoryArguments(description=description, 42 descriptionDone=descriptionDone, 43 env=env, path=path, usePTY=usePTY, 44 command=command) 45 46 self.command=command 47 if description: 48 self.description = description 49 if isinstance(self.description, str): 50 self.description = [self.description] 51 if descriptionDone: 52 self.descriptionDone = descriptionDone 53 if isinstance(self.descriptionDone, str): 54 self.descriptionDone = [self.descriptionDone] 55 self.env=env 56 self.path=path 57 self.usePTY=usePTY
58
59 - class LocalPP(ProcessProtocol):
60 - def __init__(self, step):
61 self.step = step
62
63 - def outReceived(self, data):
64 self.step.stdio_log.addStdout(data)
65
66 - def errReceived(self, data):
67 self.step.stdio_log.addStderr(data)
68
69 - def processEnded(self, status_object):
70 self.step.stdio_log.addHeader("exit status %d\n" % status_object.value.exitCode) 71 self.step.processEnded(status_object)
72
73 - def start(self):
74 # render properties 75 command = self.command 76 # set up argv 77 if type(command) in types.StringTypes: 78 if runtime.platformType == 'win32': 79 argv = os.environ['COMSPEC'].split() # allow %COMSPEC% to have args 80 if '/c' not in argv: argv += ['/c'] 81 argv += [command] 82 else: 83 # for posix, use /bin/sh. for other non-posix, well, doesn't 84 # hurt to try 85 argv = ['/bin/sh', '-c', command] 86 else: 87 if runtime.platformType == 'win32': 88 argv = os.environ['COMSPEC'].split() # allow %COMSPEC% to have args 89 if '/c' not in argv: argv += ['/c'] 90 argv += list(command) 91 else: 92 argv = command 93 94 self.stdio_log = stdio_log = self.addLog("stdio") 95 96 if type(command) in types.StringTypes: 97 stdio_log.addHeader(command.strip() + "\n\n") 98 else: 99 stdio_log.addHeader(" ".join(command) + "\n\n") 100 stdio_log.addHeader("** RUNNING ON BUILDMASTER **\n") 101 stdio_log.addHeader(" in dir %s\n" % os.getcwd()) 102 stdio_log.addHeader(" argv: %s\n" % (argv,)) 103 self.step_status.setText(list(self.description)) 104 105 if self.env is None: 106 env = os.environ 107 else: 108 assert isinstance(self.env, dict) 109 env = self.env 110 # TODO add a timeout? 111 reactor.spawnProcess(self.LocalPP(self), argv[0], argv, 112 path=self.path, usePTY=self.usePTY, env=env )
113 # (the LocalPP object will call processEnded for us) 114
115 - def processEnded(self, status_object):
116 if status_object.value.exitCode != 0: 117 self.step_status.setText(["failed (%d)" % status_object.value.exitCode]) 118 self.finished(FAILURE) 119 else: 120 self.step_status.setText(list(self.descriptionDone)) 121 self.finished(SUCCESS)
122