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