Skip to content

Commit

Permalink
Incorporate improvements from #1066
Browse files Browse the repository at this point in the history
* rename sent updates `glob` -> `files` (as in ListDir)
* drop the asserts, use base.Command.requiredArgs
* catch only OSError (even that one is quite unlikely to appear) and
  send the appropriate `rc` to master
* rename `globpath` -> `globname` (as in the python docs:
  http://docs.python.org/2/library/glob.html)
  • Loading branch information
jpommerening committed Feb 17, 2014
1 parent 87cca92 commit 32f314e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
18 changes: 10 additions & 8 deletions slave/buildslave/commands/fs.py
Expand Up @@ -218,18 +218,20 @@ class GlobPath(base.Command):

header = "glob"

# args['path'] is relative to Builder directory, and is required.
requiredArgs = ['path']

def start(self):
args = self.args
# args['path'] is relative to Builder directory, and is required.
assert args['path'] is not None
globpath = os.path.join(self.builder.basedir, args['path'])
pathname = os.path.join(self.builder.basedir, self.args['path'])

try:
files = glob.glob(globpath)
self.sendStatus({'glob': files})
files = glob.glob(pathname)
self.sendStatus({'files': files})
self.sendStatus({'rc': 0})
except:
self.sendStatus({'rc': 1})
except OSError, e:
log.msg("GlobPath %s failed" % pathname, e)
self.sendStatus({'header': '%s: %s: %s' % (self.header, e.strerror, pathname)})
self.sendStatus({'rc': e.errno})


class ListDir(base.Command):
Expand Down
6 changes: 3 additions & 3 deletions slave/buildslave/test/unit/test_commands_fs.py
Expand Up @@ -243,7 +243,7 @@ def test_non_existant(self):
d = self.run_command()

def check(_):
self.assertTrue(self.get_updates()[0]['glob'] == [])
self.assertEqual(self.get_updates()[0]['files'], [])
self.assertIn({'rc': 0},
self.get_updates(),
self.builder.show())
Expand All @@ -257,7 +257,7 @@ def test_directory(self):
d = self.run_command()

def check(_):
self.assertTrue(self.get_updates()[0]['glob'] == [os.path.join(self.basedir, 'workdir')])
self.assertEqual(self.get_updates()[0]['files'], [os.path.join(self.basedir, 'workdir')])
self.assertIn({'rc': 0},
self.get_updates(),
self.builder.show())
Expand All @@ -273,7 +273,7 @@ def test_file(self):
d = self.run_command()

def check(_):
self.assertTrue(self.get_updates()[0]['glob'] == [os.path.join(self.basedir, 'test-file')])
self.assertEqual(self.get_updates()[0]['files'], [os.path.join(self.basedir, 'test-file')])
self.assertIn({'rc': 0},
self.get_updates(),
self.builder.show())
Expand Down

0 comments on commit 32f314e

Please sign in to comment.