Esempio n. 1
0
    def run(self, command: str, ignore_errors: bool) -> None:
        """Run commands or script in project directory

        :param str command: Commands to run
        :param bool ignore_errors: Whether to exit if command returns a non-zero exit code
        """

        if not existing_git_repo(self.full_path):
            CONSOLE.stdout(fmt.red(" - Project missing\n"))
            return

        forall_env = {
            'CLOWDER_PATH': ENVIRONMENT.clowder_dir,
            'PROJECT_PATH': self.full_path,
            'PROJECT_NAME': self.name,
            'PROJECT_REMOTE': self.remote,
            'PROJECT_REF': self.ref.formatted_ref
        }

        # TODO: Add tests for presence of these variables in test scripts
        # if self.branch:
        #     forall_env['UPSTREAM_BRANCH'] = self.branch
        # if self.tag:
        #     forall_env['UPSTREAM_TAG'] = self.tag
        # if self.commit:
        #     forall_env['UPSTREAM_COMMIT'] = self.commit

        if self.upstream:
            forall_env['UPSTREAM_REMOTE'] = self.upstream.remote
            forall_env['UPSTREAM_NAME'] = self.upstream.name
            forall_env['UPSTREAM_REF'] = self.upstream.ref.formatted_ref

        self._run_forall_command(command, forall_env, ignore_errors)
Esempio n. 2
0
    def exists(self) -> bool:
        """Check if project exists

        :return: True, if repo exists
        """

        return existing_git_repo(self.full_path)
Esempio n. 3
0
    def formatted_project_output(self) -> str:
        """Return formatted project path/name

        :return: Formatted string of full file path if cloned, otherwise project name
        """

        if existing_git_repo(self.full_path):
            return str(self.path)

        return self.name
Esempio n. 4
0
    def status(self) -> str:
        """Return formatted upstream status

        :return: Formatted upstream status
        """

        if not existing_git_repo(self.path):
            return fmt.green(self.path)

        repo = ProjectRepo(self.full_path, self.remote, self.ref)
        project_output = repo.format_project_string(self.path)
        return f"{project_output} {repo.formatted_ref}"
Esempio n. 5
0
    def _configure_directories(self) -> None:
        """Configure clowder directories environment variables"""

        # Walk up directory tree to find possible .clowder directory,
        # clowder.yml file, or clowder.yaml and set environment variables

        path = Path.cwd()
        while str(path) != path.root:
            clowder_repo_dir = path / '.clowder'
            clowder_yml = path / 'clowder.yml'
            clowder_yaml = path / 'clowder.yaml'
            clowder_yml_exists = clowder_yml.is_file(
            ) or clowder_yml.is_symlink()
            clowder_yaml_exists = clowder_yaml.is_file(
            ) or clowder_yaml.is_symlink()
            clowder_repo_file_exists = clowder_repo_dir.is_symlink(
            ) or clowder_repo_dir.is_file()
            if clowder_repo_dir.is_dir() and existing_git_repo(
                    clowder_repo_dir):
                self.clowder_dir: Optional[Path] = path
                self.clowder_repo_dir: Optional[
                    Path] = clowder_repo_dir.resolve()
                self.clowder_git_repo_dir: Optional[Path] = clowder_repo_dir
                break
            elif clowder_repo_dir.is_dir():
                self.clowder_dir: Optional[Path] = path
                self.clowder_repo_dir: Optional[
                    Path] = clowder_repo_dir.resolve()
                break
            elif clowder_yml_exists or clowder_yaml_exists or clowder_repo_file_exists:
                # FIXME: Is this right?
                if clowder_repo_file_exists:
                    message = f"Found non-directory file {fmt.path(clowder_repo_dir)} " \
                              f"where clowder repo directory should be"
                    self.existing_clowder_repo_file_error: Optional[
                        ExistingFileError] = ExistingFileError(message)
                self.clowder_dir: Optional[Path] = path
                break
            path = path.parent

        if self.clowder_dir is not None:
            self.clowder_config: Optional[
                Path] = self.clowder_dir / 'clowder.config'

        if self.clowder_repo_dir is not None:
            self.clowder_repo_versions_dir: Optional[
                Path] = self.clowder_repo_dir / 'versions'
            self.clowder_config_dir: Optional[
                Path] = self.clowder_repo_dir / "config"
            self.clowder_repo_plugins_dir: Optional[
                Path] = self.clowder_repo_dir / "plugins"
Esempio n. 6
0
    def status(self, padding: Optional[int] = None) -> str:
        """Return formatted status for project

        :param Optional[int] padding: Amount of padding to use for printing project on left and current ref on right
        :return: Formatting project name and status
        """

        if not existing_git_repo(self.full_path):
            project_output = self.name
            if padding:
                project_output = project_output.ljust(padding)
                project_output = fmt.green(project_output)
                missing_output = fmt.red('-')
                return f'{project_output} {missing_output}'
            project_output = fmt.green(project_output)
            return project_output

        project_output = self.repo.format_project_string(self.path)
        if padding:
            project_output = project_output.ljust(padding)
        project_output = self.repo.color_project_string(project_output)
        return f'{project_output} {self.repo.formatted_ref}'
Esempio n. 7
0
    def print_existence_message(self) -> None:
        """Print existence validation message for project"""

        if not existing_git_repo(self.full_path):
            CONSOLE.stdout(self.status())