예제 #1
0
    def forall_parallel(commands, skip, ignore_errors, projects):
        """Runs command or script for projects in parallel

        :param list[str] commands: Command to run
        :param list[str] skip: Project names to skip
        :param bool ignore_errors: Whether to exit if command returns a non-zero exit code
        :param list[Project] projects: Projects to run command for
        """

        print(' - Run forall commands in parallel\n')
        for project in projects:
            if project.name in skip:
                continue
            print(project.status())
            if not os.path.isdir(project.full_path()):
                cprint(" - Project is missing", 'red')

        for cmd in commands:
            print('\n' + fmt.command(cmd))

        for project in projects:
            if project.name in skip:
                continue
            result = __clowder_pool__.apply_async(run_project, args=(project, commands, ignore_errors),
                                                  callback=async_callback)
            __clowder_results__.append(result)

        pool_handler(len(projects))
예제 #2
0
    def run(self, command, ignore_errors, parallel=False):
        """Run command or script in project directory"""

        if not parallel:
            if not os.path.isdir(self.full_path()):
                print(colored(" - Project is missing\n", 'red'))
                return

        self._print_output = not parallel
        self._print(fmt.command(command))

        forall_env = {
            'CLOWDER_PATH': self._root_directory,
            'PROJECT_PATH': self.full_path(),
            'PROJECT_NAME': self.name,
            'PROJECT_REMOTE': self._remote,
            'PROJECT_REF': self._ref
        }

        if self.fork:
            forall_env['FORK_REMOTE'] = self.fork.remote_name

        return_code = execute_forall_command(command.split(), self.full_path(),
                                             forall_env, self._print_output)
        if not ignore_errors:
            err = fmt.command_failed_error(command)
            if return_code != 0:
                self._print(err)
                self._exit(err, return_code=return_code, parallel=parallel)
예제 #3
0
    def run_command(self, command):
        """Run command in clowder repo"""

        print(fmt.command(command))
        return_code = execute_command(command.split(), self.clowder_path)
        if return_code != 0:
            print(fmt.command_failed_error(command))
            sys.exit(return_code)
예제 #4
0
    def run_command(self, command: str) -> None:
        """Run command in clowder repo

        :param str command: Command to run
        """

        CONSOLE.stdout(fmt.command(command))
        execute_command(command.split(), self.repo_path)
예제 #5
0
    def status_verbose(self):
        """Print git status"""

        command = 'git status -vv'
        self._print(fmt.command(command))

        return_code = execute_command(command, self.repo_path)
        if return_code != 0:
            message = colored(' - Failed to print status\n',
                              'red') + fmt.command_failed_error(command)
            self._print(message)
            self._exit(message, return_code=return_code)
예제 #6
0
    def status_verbose(self) -> None:
        """Print git status

        Equivalent to: ``git status -vv``
        """

        command = 'git status -vv'
        CONSOLE.stdout(fmt.command(command))
        try:
            execute_command(command, self.repo_path)
        except CalledProcessError:
            LOG.error('Failed to print verbose status')
            raise
예제 #7
0
    def status_verbose(self):
        """Print git status

        Equivalent to: ``git status -vv``
        """

        command = 'git status -vv'
        self._print(fmt.command(command))

        try:
            execute_command(command, self.repo_path)
        except ClowderError:
            message = colored(' - Failed to print status\n', 'red') + fmt.command_failed_error(command)
            self._print(message)
            self._exit(message)
예제 #8
0
    def _run_forall_command(self, command: str, env: dict,
                            ignore_errors: bool) -> None:
        """Run command or script in project directory

        :param str command: Command to run
        :param dict env: Environment variables
        :param bool ignore_errors: Whether to exit if command returns a non-zero exit code
        """

        CONSOLE.stdout(fmt.command(command))
        try:
            execute_forall_command(command, self.full_path, env)
        except CalledProcessError as err:
            if ignore_errors:
                LOG.debug(f'Command failed: {command}', err)
            else:
                LOG.error(f'Command failed: {command}')
                raise
    def _forall_parallel(command, skip, ignore_errors, projects):
        """Runs command or script in project directories specified"""

        print(' - Run forall commands in parallel\n')
        for project in projects:
            if project.name in skip:
                continue
            print(project.status())
            if not os.path.isdir(project.full_path()):
                cprint(" - Project is missing", 'red')

        print('\n' + fmt.command(command))
        for project in projects:
            if project.name in skip:
                continue
            result = __clowder_pool__.apply_async(run_project,
                                                  args=(project, command,
                                                        ignore_errors),
                                                  callback=async_callback)
            __clowder_results__.append(result)

        pool_handler(len(projects))
예제 #10
0
    def _run_forall_command(self, command, env, ignore_errors, parallel):
        """Run command or script in project directory

        :param str command: Command to run
        :param dict env: Environment variables
        :param bool ignore_errors: Whether to exit if command returns a non-zero exit code
        :param bool parallel: Whether command is being run in parallel, affects output

        Raises:
            ClowderError
            ClowderExit
        """

        self._print(fmt.command(command))
        try:
            execute_forall_command(command, self.full_path(), env,
                                   self._print_output)
        except ClowderError:
            if not ignore_errors:
                err = fmt.command_failed_error(command)
                self._print(err)
                if parallel:
                    raise ClowderError(err)
                raise ClowderExit(1)