Skip to content

Commit

Permalink
Merge branch 'rmdir' of git://github.com/in3xes/buildbot
Browse files Browse the repository at this point in the history
* 'rmdir' of git://github.com/in3xes/buildbot:
  Modify rmdir to remove multiple directories
  • Loading branch information
djmitche committed Jul 10, 2011
2 parents a3abed7 + 18a1f75 commit f6b2fc7
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 9 deletions.
3 changes: 2 additions & 1 deletion slave/buildslave/commands/base.py
Expand Up @@ -32,7 +32,7 @@
# this used to be a CVS $-style "Revision" auto-updated keyword, but since I
# moved to Darcs as the primary repository, this is updated manually each
# time this file is changed. The last cvs_ver that was here was 1.51 .
command_version = "2.13"
command_version = "2.14"

# version history:
# >=1.17: commands are interruptable
Expand Down Expand Up @@ -62,6 +62,7 @@
# >= 2.11: Arch, Bazaar, and Monotone removed
# >= 2.12: SlaveShellCommand no longer accepts 'keep_stdin_open'
# >= 2.13: SlaveFileUploadCommand supports option 'keepstamp'
# >= 2.14: RemoveDirectory can delete multiple directories

class Command:
implements(ISlaveCommand)
Expand Down
33 changes: 25 additions & 8 deletions slave/buildslave/commands/fs.py
Expand Up @@ -54,7 +54,9 @@ class RemoveDirectory(base.Command):
the following keys:
- ['dir'] (required): subdirectory which the command will create,
relative to the builder dir
relative to the builder dir. This argument
can be either a single directory name as a string
or list of directory names as a list.
- ['timeout']: seconds of silence tolerated before we kill off the
command
Expand All @@ -68,15 +70,35 @@ class RemoveDirectory(base.Command):

header = "rmdir"

@defer.deferredGenerator
def start(self):
args = self.args
# args['dir'] is relative to Builder directory, and is required.
assert args['dir'] is not None
dirname = args['dir']
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):
# TODO: remove the old tree in the background
self.dir = os.path.join(self.builder.basedir, dirname)
if runtime.platformType != "posix":
Expand All @@ -87,8 +109,6 @@ def start(self):
else:
d = self._clobber(None)

# always add the RC, regardless of platform
d.addCallbacks(self._sendRC, self._checkAbandoned)
return d

def _clobber(self, dummy, chmodDone = False):
Expand All @@ -105,9 +125,7 @@ def _clobber(self, dummy, chmodDone = False):
# 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 chmodDone:
d.addCallback(self._abandonOnFailure)
else:
if not chmodDone:
d.addCallback(self._tryChmod)
return d

Expand All @@ -130,7 +148,6 @@ def _tryChmod(self, rc):

self.command = c
d = c.start()
d.addCallback(self._abandonOnFailure)
d.addCallback(lambda dummy: self._clobber(dummy, True))
return d

Expand Down
15 changes: 15 additions & 0 deletions slave/buildslave/test/unit/test_commands_fs.py
Expand Up @@ -42,6 +42,21 @@ def check(_):
d.addCallback(check)
return d

def test_multiple_dirs(self):
self.make_command(fs.RemoveDirectory, dict(
dir=['workdir', 'sourcedir'],
), True)
d = self.run_command()

def check(_):
for dirname in ['workdir', 'sourcedir']:
self.assertFalse(os.path.exists(os.path.abspath(os.path.join(self.basedir, dirname))))
self.assertIn({'rc': 0},
self.get_updates(),
self.builder.show())
d.addCallback(check)
return d

class TestCopyDirectory(CommandTestMixin, unittest.TestCase):

def setUp(self):
Expand Down

0 comments on commit f6b2fc7

Please sign in to comment.