Example #1
0
    def _save(self):
        """Clowder save command private implementation

        :raise ClowderExit:
        """

        if self.app.pargs.version.lower() == 'default':
            print(fmt.save_default_error(self.app.pargs.version))
            raise ClowderExit(1)

        CLOWDER_REPO.print_status()
        validate_projects_exist(CLOWDER_CONTROLLER)
        validate_groups(CLOWDER_CONTROLLER.groups)

        version_name = self.app.pargs.version.replace(
            '/', '-')  # Replace path separators with dashes
        version_dir = os.path.join(ROOT_DIR, '.clowder', 'versions',
                                   version_name)
        _make_dir(version_dir)

        yaml_file = os.path.join(version_dir, 'clowder.yaml')
        if os.path.exists(yaml_file):
            print(
                fmt.save_version_exists_error(version_name, yaml_file) + '\n')
            raise ClowderExit(1)

        print(fmt.save_version(version_name, yaml_file))
        save_yaml(CLOWDER_CONTROLLER.get_yaml(), yaml_file)
Example #2
0
def herd(clowder, group_names, **kwargs):
    """Clone projects or update latest from upstream

    .. py:function:: herd(clowder, group_names, branch=None, tag=None, depth=0, rebase=False, project_names=None, skip=[], protocol=None)

    :param ClowderController clowder: ClowderController instance
    :param list[str] group_names: Group names to herd

    Keyword Args:
        branch (str): Branch to attempt to herd
        tag (str): Tag to attempt to herd
        depth (int): Git clone depth. 0 indicates full clone, otherwise must be a positive integer
        protocol (str): Git protocol ('ssh' or 'https')
        rebase (bool): Whether to use rebase instead of pulling latest changes
        project_names (list[str]) project_names: Project names to herd
        skip (list[str]): Project names to skip
    """

    project_names = kwargs.get('project_names', None)
    skip = kwargs.get('skip', [])
    branch = kwargs.get('branch', None)
    tag = kwargs.get('tag', None)
    depth = kwargs.get('depth', None)
    rebase = kwargs.get('rebase', False)
    protocol = kwargs.get('protocol', None)

    if project_names is None:
        groups = filter_groups(clowder.groups, group_names)
        validate_groups(groups)
        for group in groups:
            run_group_command(group,
                              skip,
                              'herd',
                              branch=branch,
                              tag=tag,
                              depth=depth,
                              rebase=rebase,
                              protocol=protocol)
        return

    projects = filter_projects(clowder.groups, project_names=project_names)
    validate_projects(projects)
    for project in projects:
        run_project_command(project,
                            skip,
                            'herd',
                            branch=branch,
                            tag=tag,
                            depth=depth,
                            rebase=rebase,
                            protocol=protocol)
Example #3
0
    def _start_branches(self, tracking):
        """clowder start branches command"""

        if self.app.pargs.projects is None:
            groups = filter_groups(CLOWDER_CONTROLLER.groups, self.app.pargs.groups)
            validate_groups(groups)
            for group in groups:
                run_group_command(group, self.app.pargs.skip, 'start', self.app.pargs.branch, tracking)
            return

        projects = filter_projects(CLOWDER_CONTROLLER.groups, project_names=self.app.pargs.projects)
        validate_projects(projects)
        for project in projects:
            run_project_command(project, self.app.pargs.skip, 'start', self.app.pargs.branch, tracking)
Example #4
0
def _prune(clowder, group_names, branch, **kwargs):
    """Prune branches

    .. py:function:: prune(group_names, local=False, remote=False, force=False, project_names=None, skip=[])

    :param ClowderController clowder: ClowderController instance
    :param list[str] group_names: Group names to prune branches for
    :param str branch: Branch to prune

    Keyword Args:
        force (bool): Force delete branch
        local (bool): Delete local branch
        remote (bool): Delete remote branch
        project_names (list[str]): Project names to prune
        skip (list[str]): Project names to skip
    """

    project_names = kwargs.get('project_names', None)
    skip = kwargs.get('skip', [])
    force = kwargs.get('force', False)
    local = kwargs.get('local', False)
    remote = kwargs.get('remote', False)

    if project_names is None:
        groups = filter_groups(clowder.groups, group_names)
        validate_groups(groups)
        _prune_groups(groups,
                      branch,
                      skip=skip,
                      force=force,
                      local=local,
                      remote=remote)
        return

    projects = filter_projects(clowder.groups, project_names=project_names)
    validate_projects(projects)
    _prune_projects(projects,
                    branch,
                    skip=skip,
                    force=force,
                    local=local,
                    remote=remote)
Example #5
0
def reset(clowder, group_names, **kwargs):
    """Reset project branches to upstream or checkout tag/sha as detached HEAD

    .. py:function:: reset(clowder, group_names, timestamp_project=None, parallel=False, project_names=None, skip=[])

    :param ClowderController clowder: ClowderController instance
    :param list[str] group_names: Group names to reset

    Keyword Args:
        timestamp_project (str): Reference project to checkout commit timestamps of other projects relative to
        parallel (bool): Whether command is being run in parallel, affects output
        project_names (list[str]): Project names to reset
        skip (list[str]): Project names to skip
    """

    project_names = kwargs.get('project_names', None)
    skip = kwargs.get('skip', [])
    timestamp_project = kwargs.get('timestamp_project', None)
    parallel = kwargs.get('parallel', False)

    if parallel:
        reset_parallel(clowder,
                       group_names,
                       skip=skip,
                       timestamp_project=timestamp_project)
        if os.name == "posix":
            return

    timestamp = None
    if timestamp_project:
        timestamp = clowder.get_timestamp(timestamp_project)
    if project_names is None:
        groups = filter_groups(clowder.groups, group_names)
        validate_groups(groups)
        for group in groups:
            run_group_command(group, skip, 'reset', timestamp=timestamp)
        return

    projects = filter_projects(clowder.groups, project_names=project_names)
    validate_projects(projects)
    for project in projects:
        run_project_command(project, skip, 'reset', timestamp=timestamp)