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 sopported. 28 """ 29 name='MasterShellCommand' 30 description='Running' 31 descriptionDone='Ran' 32
33 - def __init__(self, command, 34 description=None, descriptionDone=None, 35 env=None, path=None, usePTY=0, 36 **kwargs):
37 BuildStep.__init__(self, **kwargs) 38 self.addFactoryArguments(description=description, 39 descriptionDone=descriptionDone, 40 env=env, path=path, usePTY=usePTY, 41 command=command) 42 43 self.command=command 44 if description: 45 self.description = description 46 if isinstance(self.description, str): 47 self.description = [self.description] 48 if descriptionDone: 49 self.descriptionDone = descriptionDone 50 if isinstance(self.descriptionDone, str): 51 self.descriptionDone = [self.descriptionDone] 52 self.env=env 53 self.path=path 54 self.usePTY=usePTY
55
56 - class LocalPP(ProcessProtocol):
57 - def __init__(self, step):
58 self.step = step
59
60 - def outReceived(self, data):
61 self.step.stdio_log.addStdout(data)
62
63 - def errReceived(self, data):
64 self.step.stdio_log.addStderr(data)
65
66 - def processEnded(self, status_object):
67 self.step.stdio_log.addHeader("exit status %d\n" % status_object.value.exitCode) 68 self.step.processEnded(status_object)
69
70 - def start(self):
71 # render properties 72 properties = self.build.getProperties() 73 command = properties.render(self.command) 74 # set up argv 75 if type(command) in types.StringTypes: 76 if runtime.platformType == 'win32': 77 argv = os.environ['COMSPEC'].split() # allow %COMSPEC% to have args 78 if '/c' not in argv: argv += ['/c'] 79 argv += [command] 80 else: 81 # for posix, use /bin/sh. for other non-posix, well, doesn't 82 # hurt to try 83 argv = ['/bin/sh', '-c', command] 84 else: 85 if runtime.platformType == 'win32': 86 argv = os.environ['COMSPEC'].split() # allow %COMSPEC% to have args 87 if '/c' not in argv: argv += ['/c'] 88 argv += list(command) 89 else: 90 argv = command 91 92 self.stdio_log = stdio_log = self.addLog("stdio") 93 94 if type(command) in types.StringTypes: 95 stdio_log.addHeader(command.strip() + "\n\n") 96 else: 97 stdio_log.addHeader(" ".join(command) + "\n\n") 98 stdio_log.addHeader("** RUNNING ON BUILDMASTER **\n") 99 stdio_log.addHeader(" in dir %s\n" % os.getcwd()) 100 stdio_log.addHeader(" argv: %s\n" % (argv,)) 101 self.step_status.setText(list(self.description)) 102 103 if self.env is None: 104 env = os.environ 105 else: 106 assert isinstance(self.env, dict) 107 env = self.env 108 # TODO add a timeout? 109 reactor.spawnProcess(self.LocalPP(self), argv[0], argv, 110 path=self.path, usePTY=self.usePTY, env=env )
111 # (the LocalPP object will call processEnded for us) 112
113 - def processEnded(self, status_object):
114 if status_object.value.exitCode != 0: 115 self.step_status.setText(["failed (%d)" % status_object.value.exitCode]) 116 self.finished(FAILURE) 117 else: 118 self.step_status.setText(list(self.descriptionDone)) 119 self.finished(SUCCESS)
120