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

Source Code for Module buildbot.steps.master

 1  import os, types 
 2  from twisted.python import runtime 
 3  from twisted.internet import reactor  
 4  from buildbot.process.buildstep import BuildStep 
 5  from buildbot.process.buildstep import SUCCESS, FAILURE 
 6  from twisted.internet.protocol import ProcessProtocol 
 7   
8 -class MasterShellCommand(BuildStep):
9 """ 10 Run a shell command locally - on the buildmaster. The shell command 11 COMMAND is specified just as for a RemoteShellCommand. Note that extra 12 logfiles are not sopported. 13 """ 14 name='MasterShellCommand' 15 description='Running' 16 descriptionDone='Ran' 17
18 - def __init__(self, command, 19 description=None, descriptionDone=None, 20 **kwargs):
21 BuildStep.__init__(self, **kwargs) 22 self.addFactoryArguments(description=description, 23 descriptionDone=descriptionDone, 24 command=command) 25 26 self.command=command 27 if description: 28 self.description = description 29 if isinstance(self.description, str): 30 self.description = [self.description] 31 if descriptionDone: 32 self.descriptionDone = descriptionDone 33 if isinstance(self.descriptionDone, str): 34 self.descriptionDone = [self.descriptionDone]
35
36 - class LocalPP(ProcessProtocol):
37 - def __init__(self, step):
38 self.step = step
39
40 - def outReceived(self, data):
41 self.step.stdio_log.addStdout(data)
42
43 - def errReceived(self, data):
44 self.step.stdio_log.addStderr(data)
45
46 - def processEnded(self, status_object):
47 self.step.stdio_log.addHeader("exit status %d\n" % status_object.value.exitCode) 48 self.step.processEnded(status_object)
49
50 - def start(self):
51 # render properties 52 properties = self.build.getProperties() 53 command = properties.render(self.command) 54 # set up argv 55 if type(command) in types.StringTypes: 56 if runtime.platformType == 'win32': 57 argv = os.environ['COMSPEC'].split() # allow %COMSPEC% to have args 58 if '/c' not in argv: argv += ['/c'] 59 argv += [command] 60 else: 61 # for posix, use /bin/sh. for other non-posix, well, doesn't 62 # hurt to try 63 argv = ['/bin/sh', '-c', command] 64 else: 65 if runtime.platformType == 'win32': 66 argv = os.environ['COMSPEC'].split() # allow %COMSPEC% to have args 67 if '/c' not in argv: argv += ['/c'] 68 argv += list(command) 69 else: 70 argv = command 71 72 self.stdio_log = stdio_log = self.addLog("stdio") 73 74 if type(command) in types.StringTypes: 75 stdio_log.addHeader(command.strip() + "\n\n") 76 else: 77 stdio_log.addHeader(" ".join(command) + "\n\n") 78 stdio_log.addHeader("** RUNNING ON BUILDMASTER **\n") 79 stdio_log.addHeader(" in dir %s\n" % os.getcwd()) 80 stdio_log.addHeader(" argv: %s\n" % (argv,)) 81 self.step_status.setText(list(self.description)) 82 83 # TODO add a timeout? 84 reactor.spawnProcess(self.LocalPP(self), argv[0], argv)
85 # (the LocalPP object will call processEnded for us) 86
87 - def processEnded(self, status_object):
88 if status_object.value.exitCode != 0: 89 self.step_status.setText(["failed (%d)" % status_object.value.exitCode]) 90 self.finished(FAILURE) 91 else: 92 self.step_status.setText(list(self.descriptionDone)) 93 self.finished(SUCCESS)
94