/usr/share/pyshared/buildslave/commands/fs.py is in buildbot-slave 0.8.8-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 | # This file is part of Buildbot. Buildbot is free software: you can
# redistribute it and/or modify it under the terms of the GNU General Public
# License as published by the Free Software Foundation, version 2.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
# details.
#
# You should have received a copy of the GNU General Public License along with
# this program; if not, write to the Free Software Foundation, Inc., 51
# Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Copyright Buildbot Team Members
import os
import sys
import shutil
from twisted.internet import threads, defer
from twisted.python import runtime, log
from buildslave import runprocess
from buildslave.commands import base, utils
class MakeDirectory(base.Command):
header = "mkdir"
def start(self):
args = self.args
# args['dir'] is relative to Builder directory, and is required.
assert args['dir'] is not None
dirname = os.path.join(self.builder.basedir, args['dir'])
try:
if not os.path.isdir(dirname):
os.makedirs(dirname)
self.sendStatus({'rc': 0})
except:
self.sendStatus({'rc': 1})
class RemoveDirectory(base.Command):
header = "rmdir"
def setup(self,args):
self.logEnviron = args.get('logEnviron',True)
@defer.deferredGenerator
def start(self):
args = self.args
# args['dir'] is relative to Builder directory, and is required.
assert args['dir'] is not None
dirnames = args['dir']
self.timeout = args.get('timeout', 120)
self.maxTime = args.get('maxTime', None)
self.rc = 0
if type(dirnames) is list:
assert len(dirnames) != 0
for dirname in dirnames:
wfd = defer.waitForDeferred(self.removeSingleDir(dirname))
yield wfd
res = wfd.getResult()
# Even if single removal of single file/dir consider it as
# failure of whole command, but continue removing other files
# Send 'rc' to master to handle failure cases
if res != 0:
self.rc = res
else:
wfd = defer.waitForDeferred(self.removeSingleDir(dirnames))
yield wfd
self.rc = wfd.getResult()
self.sendStatus({'rc': self.rc})
def removeSingleDir(self, dirname):
self.dir = os.path.join(self.builder.basedir, dirname)
if runtime.platformType != "posix":
d = threads.deferToThread(utils.rmdirRecursive, self.dir)
def cb(_):
return 0 # rc=0
def eb(f):
self.sendStatus({'header' : 'exception from rmdirRecursive\n' + f.getTraceback()})
return -1 # rc=-1
d.addCallbacks(cb, eb)
else:
d = self._clobber(None)
return d
def _clobber(self, dummy, chmodDone = False):
command = ["rm", "-rf", self.dir]
c = runprocess.RunProcess(self.builder, command, self.builder.basedir,
sendRC=0, timeout=self.timeout, maxTime=self.maxTime,
logEnviron=self.logEnviron, usePTY=False)
self.command = c
# sendRC=0 means the rm command will send stdout/stderr to the
# master, but not the rc=0 when it finishes. That job is left to
# _sendRC
d = c.start()
# The rm -rf may fail if there is a left-over subdir with chmod 000
# permissions. So if we get a failure, we attempt to chmod suitable
# permissions and re-try the rm -rf.
if not chmodDone:
d.addCallback(self._tryChmod)
return d
def _tryChmod(self, rc):
assert isinstance(rc, int)
if rc == 0:
return defer.succeed(0)
# Attempt a recursive chmod and re-try the rm -rf after.
command = ["chmod", "-Rf", "u+rwx", os.path.join(self.builder.basedir, self.dir)]
if sys.platform.startswith('freebsd'):
# Work around a broken 'chmod -R' on FreeBSD (it tries to recurse into a
# directory for which it doesn't have permission, before changing that
# permission) by running 'find' instead
command = ["find", os.path.join(self.builder.basedir, self.dir),
'-exec', 'chmod', 'u+rwx', '{}', ';' ]
c = runprocess.RunProcess(self.builder, command, self.builder.basedir,
sendRC=0, timeout=self.timeout, maxTime=self.maxTime,
logEnviron=self.logEnviron, usePTY=False)
self.command = c
d = c.start()
d.addCallback(lambda dummy: self._clobber(dummy, True))
return d
class CopyDirectory(base.Command):
header = "cpdir"
def setup(self,args):
self.logEnviron = args.get('logEnviron',True)
def start(self):
args = self.args
# args['todir'] is relative to Builder directory, and is required.
# args['fromdir'] is relative to Builder directory, and is required.
assert args['todir'] is not None
assert args['fromdir'] is not None
fromdir = os.path.join(self.builder.basedir, args['fromdir'])
todir = os.path.join(self.builder.basedir, args['todir'])
self.timeout = args.get('timeout', 120)
self.maxTime = args.get('maxTime', None)
if runtime.platformType != "posix":
d = threads.deferToThread(shutil.copytree, fromdir, todir)
def cb(_):
return 0 # rc=0
def eb(f):
self.sendStatus({'header' : 'exception from copytree\n' + f.getTraceback()})
return -1 # rc=-1
d.addCallbacks(cb, eb)
@d.addCallback
def send_rc(rc):
self.sendStatus({'rc' : rc})
else:
if not os.path.exists(os.path.dirname(todir)):
os.makedirs(os.path.dirname(todir))
if os.path.exists(todir):
# I don't think this happens, but just in case..
log.msg("cp target '%s' already exists -- cp will not do what you think!" % todir)
command = ['cp', '-R', '-P', '-p', '-v', fromdir, todir]
c = runprocess.RunProcess(self.builder, command, self.builder.basedir,
sendRC=False, timeout=self.timeout, maxTime=self.maxTime,
logEnviron=self.logEnviron, usePTY=False)
self.command = c
d = c.start()
d.addCallback(self._abandonOnFailure)
d.addCallbacks(self._sendRC, self._checkAbandoned)
return d
class StatFile(base.Command):
header = "stat"
def start(self):
args = self.args
# args['dir'] is relative to Builder directory, and is required.
assert args['file'] is not None
filename = os.path.join(self.builder.basedir, args['file'])
try:
stat = os.stat(filename)
self.sendStatus({'stat': tuple(stat)})
self.sendStatus({'rc': 0})
except:
self.sendStatus({'rc': 1})
|