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

Source Code for Module buildbot.steps.slave

  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 stat 
 17  from buildbot.process import buildstep 
 18  from buildbot.status.results import SUCCESS, FAILURE 
 19  from buildbot.interfaces import BuildSlaveTooOldError 
 20   
21 -class SetPropertiesFromEnv(buildstep.BuildStep):
22 """ 23 Sets properties from envirionment variables on the slave. 24 25 Note this is transfered when the slave first connects 26 """ 27 name='SetPropertiesFromEnv' 28 description='Setting' 29 descriptionDone='Set' 30
31 - def __init__(self, variables, source="SlaveEnvironment", **kwargs):
32 buildstep.BuildStep.__init__(self, **kwargs) 33 self.variables = variables 34 self.source = source
35
36 - def start(self):
37 # on Windows, environment variables are case-insensitive, but we have 38 # a case-sensitive dictionary in slave_environ. Fortunately, that 39 # dictionary is also folded to uppercase, so we can simply fold the 40 # variable names to uppercase to duplicate the case-insensitivity. 41 fold_to_uppercase = (self.buildslave.slave_system == 'win32') 42 43 properties = self.build.getProperties() 44 environ = self.buildslave.slave_environ 45 variables = self.variables 46 log = [] 47 if isinstance(variables, str): 48 variables = [self.variables] 49 for variable in variables: 50 key = variable 51 if fold_to_uppercase: 52 key = variable.upper() 53 value = environ.get(key, None) 54 if value: 55 # note that the property is not uppercased 56 properties.setProperty(variable, value, self.source, 57 runtime=True) 58 log.append("%s = %r" % (variable, value)) 59 self.addCompleteLog("properties", "\n".join(log)) 60 self.finished(SUCCESS)
61
62 -class FileExists(buildstep.BuildStep):
63 """ 64 Check for the existence of a file on the slave. 65 """ 66 name='FileExists' 67 description='Checking' 68 descriptionDone='Checked' 69 70 renderables = [ 'file' ] 71 72 haltOnFailure = True 73 flunkOnFailure = True 74 75
76 - def __init__(self, file, **kwargs):
77 buildstep.BuildStep.__init__(self, **kwargs) 78 self.file = file
79
80 - def start(self):
81 slavever = self.slaveVersion('stat') 82 if not slavever: 83 raise BuildSlaveTooOldError("slave is too old, does not know " 84 "about stat") 85 cmd = buildstep.RemoteCommand('stat', {'file': self.file }) 86 d = self.runCommand(cmd) 87 d.addCallback(lambda res: self.commandComplete(cmd)) 88 d.addErrback(self.failed)
89
90 - def commandComplete(self, cmd):
91 if cmd.didFail(): 92 self.step_status.setText(["File not found."]) 93 self.finished(FAILURE) 94 return 95 s = cmd.updates["stat"][-1] 96 if stat.S_ISREG(s[stat.ST_MODE]): 97 self.step_status.setText(["File found."]) 98 self.finished(SUCCESS) 99 else: 100 self.step_status.setText(["Not a file."]) 101 self.finished(FAILURE)
102
103 -class RemoveDirectory(buildstep.BuildStep):
104 """ 105 Remove a directory tree on the slave. 106 """ 107 name='RemoveDirectory' 108 description='Deleting' 109 desciprtionDone='Deleted' 110 111 renderables = [ 'dir' ] 112 113 haltOnFailure = True 114 flunkOnFailure = True 115
116 - def __init__(self, dir, **kwargs):
117 buildstep.BuildStep.__init__(self, **kwargs) 118 self.dir = dir
119
120 - def start(self):
121 slavever = self.slaveVersion('rmdir') 122 if not slavever: 123 raise BuildSlaveTooOldError("slave is too old, does not know " 124 "about rmdir") 125 cmd = buildstep.RemoteCommand('rmdir', {'dir': self.dir }) 126 d = self.runCommand(cmd) 127 d.addCallback(lambda res: self.commandComplete(cmd)) 128 d.addErrback(self.failed)
129
130 - def commandComplete(self, cmd):
131 if cmd.didFail(): 132 self.step_status.setText(["Delete failed."]) 133 self.finished(FAILURE) 134 return 135 self.finished(SUCCESS)
136
137 -class MakeDirectory(buildstep.BuildStep):
138 """ 139 Create a directory on the slave. 140 """ 141 name='MakeDirectory' 142 description='Creating' 143 desciprtionDone='Created' 144 145 renderables = [ 'dir' ] 146 147 haltOnFailure = True 148 flunkOnFailure = True 149
150 - def __init__(self, dir, **kwargs):
151 buildstep.BuildStep.__init__(self, **kwargs) 152 self.dir = dir
153
154 - def start(self):
155 slavever = self.slaveVersion('mkdir') 156 if not slavever: 157 raise BuildSlaveTooOldError("slave is too old, does not know " 158 "about mkdir") 159 cmd = buildstep.RemoteCommand('mkdir', {'dir': self.dir }) 160 d = self.runCommand(cmd) 161 d.addCallback(lambda res: self.commandComplete(cmd)) 162 d.addErrback(self.failed)
163
164 - def commandComplete(self, cmd):
165 if cmd.didFail(): 166 self.step_status.setText(["Create failed."]) 167 self.finished(FAILURE) 168 return 169 self.finished(SUCCESS)
170