Example #1
0
    def print_validation(self):
        """Print validation message for project"""

        if not self.is_valid():
            print(self.status())
            repo = ProjectRepo(self.full_path(), self.remote, self.ref)
            print_validation(repo)
Example #2
0
    def get_yaml(self, resolved=False):
        """Return python object representation for saving yaml

        .. py:function:: get_yaml(resolved=False)

        :param Optional[bool] resolved: Return default ref rather than current commit sha
        :return: YAML python object
        :rtype: dict
        """

        if resolved:
            ref = self.ref
        else:
            repo = ProjectRepo(self.full_path(), self.remote, self.ref)
            ref = repo.sha()

        project = {
            'name': self.name,
            'path': self.path,
            'depth': self.depth,
            'recursive': self.recursive,
            'ref': ref,
            'remote': self.remote,
            'source': self.source.name
        }

        if self.fork:
            fork_yaml = self.fork.get_yaml()
            project['fork'] = fork_yaml

        if self._timestamp_author:
            project['timestamp_author'] = self._timestamp_author

        return project
Example #3
0
    def _prune_remote(self, branch):
        """Prune remote branch"""

        remote = self._remote if self.fork is None else self.fork.remote_name
        repo = ProjectRepo(self.full_path(), remote, self._ref)
        if repo.existing_remote_branch(branch, remote):
            repo.prune_branch_remote(branch, remote)
Example #4
0
    def diff(self):
        """Show git diff for project

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

        ProjectRepo(self.full_path(), self.remote, self.ref).status_verbose()
Example #5
0
    def get_yaml(self, resolved=False):
        """Return python object representation for saving yaml"""

        if resolved:
            ref = self._ref
        else:
            repo = ProjectRepo(self.full_path(), self._remote, self._ref)
            ref = repo.sha()

        project = {
            'name': self.name,
            'path': self.path,
            'depth': self._depth,
            'recursive': self._recursive,
            'ref': ref,
            'remote': self._remote,
            'source': self._source.name
        }

        if self.fork:
            fork_yaml = self.fork.get_yaml()
            project['fork'] = fork_yaml

        if self._timestamp_author:
            project['timestamp_author'] = self._timestamp_author

        return project
    def print_status(self, fetch=False):
        """Print clowder repo status"""

        repo_path = os.path.join(self.root_directory, '.clowder')
        if not ProjectRepo.existing_git_repository(repo_path):
            output = colored('.clowder', 'green')
            print(output)
            return

        if not is_offline() and fetch:
            print(' - Fetch upstream changes for clowder repo')
            repo = ProjectRepo(self.clowder_path, self.remote, self.default_ref)
            repo.fetch(self.remote)

        project_output = ProjectRepo.format_project_string(repo_path, '.clowder')
        current_ref_output = ProjectRepo.format_project_ref_string(repo_path)

        clowder_symlink = os.path.join(self.root_directory, 'clowder.yaml')
        if not os.path.islink(clowder_symlink):
            print(project_output + ' ' + current_ref_output)
            return

        real_path = os.path.realpath(clowder_symlink)
        symlink_output = fmt.path('clowder.yaml')
        clowder_path = fmt.remove_prefix(real_path + '/', self.root_directory)
        path_output = fmt.path(clowder_path[1:-1])
        print(project_output + ' ' + current_ref_output)
        print(symlink_output + ' -> ' + path_output + '\n')
    def _validate_groups(self):
        """Validate status of clowder repo"""

        clowder = ProjectRepo(self.clowder_path, self.remote, self.default_ref)
        if not clowder.validate_repo():
            ProjectRepo.validation(self.clowder_path)
            print()
            sys.exit(1)
Example #8
0
    def existing_branch(self, branch, is_remote):
        """Check if branch exists"""

        repo = ProjectRepo(self.full_path(), self._remote, self._ref)
        if not is_remote:
            return repo.existing_local_branch(branch)

        rem = self._remote if self.fork is None else self.fork.remote_name
        return repo.existing_remote_branch(branch, rem)
Example #9
0
    def is_valid(self):
        """Validate status of project

        :return: True, if not dirty or if the project doesn't exist on disk
        :rtype: bool
        """

        return ProjectRepo(self.full_path(), self.remote,
                           self.ref).validate_repo()
Example #10
0
    def get_current_timestamp(self):
        """Return timestamp of current HEAD commit

        :return: HEAD commit timestamp
        :rtype: str
        """

        repo = ProjectRepo(self.full_path(), self.remote, self.ref)
        return repo.get_current_timestamp()
Example #11
0
    def formatted_project_path(self):
        """Return formatted project path

        :return: Formatted string of full file path
        :rtype: str
        """

        repo = ProjectRepo(self.full_path(), self.remote, self.ref)
        return format_project_string(repo, self.path)
Example #12
0
    def checkout(self, ref):
        """Checkout ref in clowder repo"""

        repo = ProjectRepo(self.clowder_path, self.remote, self.default_ref)
        if self.is_dirty():
            print(' - Dirty repo. Please stash, commit, or discard your changes')
            repo.status_verbose()
            return
        repo.checkout(ref)
Example #13
0
    def init(self, url, branch):
        """Clone clowder repo from url"""

        # Register exit handler to remove files if cloning repo fails
        atexit.register(self.init_exit_handler)

        repo = ProjectRepo(self.clowder_path, self.remote, self.default_ref)
        repo.create_clowder_repo(url, branch)
        self.link()
Example #14
0
    def diff(self):
        """Show git diff for project"""

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

        repo = ProjectRepo(self.full_path(), self._remote, self._ref)
        repo.status_verbose()
Example #15
0
    def fetch_all(self):
        """Fetch upstream changes if project exists on disk"""

        repo = ProjectRepo(self.full_path(), self.remote, self.ref)
        if self.fork is None:
            repo.fetch(self.remote, depth=self.depth)
            return

        repo.fetch(self.fork.remote_name)
        repo.fetch(self.remote)
Example #16
0
    def clean(self):
        """Discard changes in clowder repo"""

        repo = ProjectRepo(self.clowder_path, self.remote, self.default_ref)
        if self.is_dirty():
            print(' - Discard current changes')
            repo.clean(args='fdx')
            return

        print(' - No changes to discard')
Example #17
0
    def start(self, branch, tracking):
        """Start a new feature branch

        :param str branch: Local branch name to create
        :param bool tracking: Whether to create a remote branch with tracking relationship
        """

        remote = self.remote if self.fork is None else self.fork.remote_name
        depth = self.depth if self.fork is None else 0
        repo = ProjectRepo(self.full_path(), self.remote, self.ref)
        repo.start(remote, branch, depth, tracking)
Example #18
0
    def start(self, branch, tracking):
        """Start a new feature branch"""

        if not ProjectRepo.existing_git_repository(self.full_path()):
            print(colored(" - Directory doesn't exist", 'red'))
            return

        remote = self._remote if self.fork is None else self.fork.remote_name
        depth = self._depth if self.fork is None else 0

        repo = ProjectRepo(self.full_path(), self._remote, self._ref)
        repo.start(remote, branch, depth, tracking)
Example #19
0
    def status(self):
        """Return formatted fork status

        :return: Formatted fork status
        :rtype: str
        """

        if not existing_git_repository(self.path):
            return colored(self.path, 'green')

        repo = ProjectRepo(self.full_path(), self.remote_name, 'refs/heads/master')
        project_output = format_project_string(repo, self.path)
        current_ref_output = format_project_ref_string(repo)
        return project_output + ' ' + current_ref_output
Example #20
0
    def existing_branch(self, branch, is_remote):
        """Check if branch exists

        :param str branch: Branch to check for
        :param bool is_remote: Check for remote branch
        :return: True, if branch exists
        :rtype: bool
        """

        repo = ProjectRepo(self.full_path(), self.remote, self.ref)
        if not is_remote:
            return repo.existing_local_branch(branch)

        remote = self.remote if self.fork is None else self.fork.remote_name
        return repo.existing_remote_branch(branch, remote)
Example #21
0
    def _repo(path, remote, ref, recursive, **kwargs):
        """Return ProjectRepo or ProjectRepoRecursive instance

        :param str path: Repo path
        :param str remote: Default repo remote
        :param str ref: Default repo ref
        :param bool recursive: Whether to handle submodules

        Keyword Args:
            parallel (bool): Whether command is being run in parallel
            print_output (bool): Whether to print output
        """

        if recursive:
            return ProjectRepoRecursive(path, remote, ref, **kwargs)
        return ProjectRepo(path, remote, ref, **kwargs)
Example #22
0
    def branch(self, local=False, remote=False):
        """Print branches for project"""

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

        repo = ProjectRepo(self.full_path(), self._remote, self._ref)
        if not is_offline():
            if remote:
                if self.fork is None:
                    repo.fetch(self._remote, depth=self._depth)
                else:
                    repo.fetch(self.fork.remote_name)
                    repo.fetch(self._remote)

        repo.print_branches(local=local, remote=remote)
Example #23
0
    def branch(self, local=False, remote=False):
        """Print branches for project

        .. py:function:: branch(local=False, remote=False)

        :param Optional[bool] local: Print local branches
        :param Optional[bool] remote: Print remote branches
        """

        repo = ProjectRepo(self.full_path(), self.remote, self.ref)
        if not is_offline() and remote:
            if self.fork is None:
                repo.fetch(self.remote, depth=self.depth)
            else:
                repo.fetch(self.fork.remote_name)
                repo.fetch(self.remote)

        repo.print_branches(local=local, remote=remote)
Example #24
0
    def status(self, padding=None):
        """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
        :rtype: str
        """

        if not existing_git_repository(self.full_path()):
            return colored(self.name, 'green')

        repo = ProjectRepo(self.full_path(), self.remote, self.ref)
        project_output = format_project_string(repo, self.path)
        current_ref_output = format_project_ref_string(repo)

        if padding:
            project_output = project_output.ljust(padding)

        return project_output + ' ' + current_ref_output
Example #25
0
    def prune(self, branch, force=False, local=False, remote=False):
        """Prune branch

        .. py:function:: prune(branch, force=False, local=False, remote=False)

        :param str branch: Branch to prune
        :param Optional[bool] force: Force delete branch
        :param Optional[bool] local: Delete local branch
        :param Optional[bool] remote: Delete remote branch
        """

        repo = ProjectRepo(self.full_path(), self.remote, self.ref)

        if local and repo.existing_local_branch(branch):
            repo.prune_branch_local(branch, force)

        if remote:
            git_remote = self.remote if self.fork is None else self.fork.remote_name
            if repo.existing_remote_branch(branch, git_remote):
                repo.prune_branch_remote(branch, git_remote)
Example #26
0
    def is_dirty(self):
        """Check if project is dirty"""

        repo = ProjectRepo(self.clowder_path, self.remote, self.default_ref)
        return repo.is_dirty()
Example #27
0
    def commit(self, message):
        """Commit current changes in clowder repo"""

        repo = ProjectRepo(self.clowder_path, self.remote, self.default_ref)
        repo.commit(message)
Example #28
0
    def branches(self):
        """Return current local branches"""

        repo = ProjectRepo(self.clowder_path, self.remote, self.default_ref)
        return repo.print_branches(local=True, remote=True)
Example #29
0
    def add(self, files):
        """Add files in clowder repo to git index"""

        repo = ProjectRepo(self.clowder_path, self.remote, self.default_ref)
        repo.add(files)
Example #30
0
    def git_status(self):
        """Print clowder repo git status"""

        repo = ProjectRepo(self.clowder_path, self.remote, self.default_ref)
        repo.status_verbose()