| """Git clean step.""" |
| |
| from __future__ import absolute_import |
| import logging |
| |
| from helpers import branch_utils |
| from slave import base_step |
| |
| |
| class GitCleanStep(base_step.BaseStep): |
| """git clean step class.""" |
| |
| def __init__(self, **kwargs): |
| """Creates a GitCleanStep instance. |
| |
| Args: |
| **kwargs: Any additional args to pass to BaseStep. |
| """ |
| base_step.BaseStep.__init__(self, name='git_clean', **kwargs) |
| self._clean_project = self.get_property('git_clean_project') |
| self._min_branch = self.get_property('git_clean_min_branch') |
| |
| def run(self): |
| # Do all the cleaning. |
| command = ['git', 'clean', '-x', '-f', '-d'] |
| |
| if not branch_utils.is_branch_equal_to_or_later_than( |
| self.manifest_branch, self._min_branch): |
| logging.info('Branch is older than %s, nothing to do.', self._min_branch) |
| return True |
| |
| logging.info("Clean project is '%s'", self._clean_project) |
| if not self._clean_project: |
| return True |
| projects = [p.strip() for p in self._clean_project.split(',')] |
| |
| for project in projects: |
| if project: |
| clean_dir = self.get_project_path(project) |
| else: |
| clean_dir = None |
| logging.info("Cleaning project '%s' at '%s'", project, clean_dir) |
| returncode, _, _ = self.exec_subprocess(command, cwd=clean_dir) |
| if returncode != 0: |
| return False |
| return True |