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.addFactoryArguments(variables = variables, 34 source = source) 35 self.variables = variables 36 self.source = source
37
38 - def start(self):
39 # on Windows, environment variables are case-insensitive, but we have 40 # a case-sensitive dictionary in slave_environ. Fortunately, that 41 # dictionary is also folded to uppercase, so we can simply fold the 42 # variable names to uppercase to duplicate the case-insensitivity. 43 fold_to_uppercase = (self.buildslave.slave_system == 'win32') 44 45 properties = self.build.getProperties() 46 environ = self.build.slaveEnvironment 47 variables = self.variables 48 if isinstance(variables, str): 49 variables = [self.variables] 50 for variable in variables: 51 key = variable 52 if fold_to_uppercase: 53 key = variable.upper() 54 value = environ.get(key, None) 55 if value: 56 # note that the property is not uppercased 57 properties.setProperty(variable, value, self.source, 58 runtime=True) 59 self.finished(SUCCESS)
60
61 -class FileExists(buildstep.BuildStep):
62 """ 63 Check for the existence of a file on the slave. 64 """ 65 name='FileExists' 66 description='Checking' 67 descriptionDone='Checked' 68 69 renderables = [ 'file' ] 70 71 haltOnFailure = True 72 flunkOnFailure = True 73 74
75 - def __init__(self, file, **kwargs):
76 buildstep.BuildStep.__init__(self, **kwargs) 77 self.addFactoryArguments(file = file) 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.rc != 0: 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.addFactoryArguments(dir = dir) 119 self.dir = dir
120
121 - def start(self):
122 slavever = self.slaveVersion('rmdir') 123 if not slavever: 124 raise BuildSlaveTooOldError("slave is too old, does not know " 125 "about rmdir") 126 cmd = buildstep.RemoteCommand('rmdir', {'dir': self.dir }) 127 d = self.runCommand(cmd) 128 d.addCallback(lambda res: self.commandComplete(cmd)) 129 d.addErrback(self.failed)
130
131 - def commandComplete(self, cmd):
132 if cmd.rc != 0: 133 self.step_status.setText(["Delete failed."]) 134 self.finished(FAILURE) 135 return 136 self.finished(SUCCESS)
137
138 -class MakeDirectory(buildstep.BuildStep):
139 """ 140 Create a directory on the slave. 141 """ 142 name='MakeDirectory' 143 description='Creating' 144 desciprtionDone='Created' 145 146 renderables = [ 'dir' ] 147 148 haltOnFailure = True 149 flunkOnFailure = True 150
151 - def __init__(self, dir, **kwargs):
152 buildstep.BuildStep.__init__(self, **kwargs) 153 self.addFactoryArguments(dir = dir) 154 self.dir = dir
155
156 - def start(self):
157 slavever = self.slaveVersion('mkdir') 158 if not slavever: 159 raise BuildSlaveTooOldError("slave is too old, does not know " 160 "about mkdir") 161 cmd = buildstep.RemoteCommand('mkdir', {'dir': self.dir }) 162 d = self.runCommand(cmd) 163 d.addCallback(lambda res: self.commandComplete(cmd)) 164 d.addErrback(self.failed)
165
166 - def commandComplete(self, cmd):
167 if cmd.rc != 0: 168 self.step_status.setText(["Create failed."]) 169 self.finished(FAILURE) 170 return 171 self.finished(SUCCESS)
172