| """Utility functions for running the LUCI Recipe script.""" |
| from __future__ import absolute_import |
| import os |
| |
| |
| class LUCIRecipeRunner(object): |
| |
| def __init__(self, executor, script_path, package_path=None): |
| self._executor = executor |
| self._script_path = script_path |
| self._base_command = [self._script_path] |
| if package_path: |
| self._base_command.extend(['--package', package_path]) |
| |
| def run_tests(self, verbose=True): |
| """Run recipe expectation tests.""" |
| cmd = ['test', 'run'] |
| return self.run_command(cmd, verbose=verbose) |
| |
| def bundle(self, destination, verbose=True): |
| """Generate a recipe bundle at the specified destination.""" |
| cmd = ['bundle', '--destination', destination] |
| return self.run_command(cmd, verbose=verbose) |
| |
| def run_command(self, cmd, verbose=True): |
| """Execute a LUCI recipes command.""" |
| full_command = self._base_command[:] |
| |
| if verbose: |
| full_command.append('--verbose') |
| full_command.extend(cmd) |
| |
| try: |
| return self._executor.exec_subprocess(full_command) |
| finally: |
| self.cleanup() |
| |
| def cleanup(self): |
| """Delete generated dependencies left from recipe run.""" |
| deps_path = os.path.join(os.path.dirname(self._script_path), '.recipe_deps') |
| self._executor.exec_subprocess(['rm', '-rf', deps_path]) |