Esempio n. 1
0
def forall(clowder, command, ignore_errors, group_names, **kwargs):
    """Runs script in project directories specified

    .. py:function:: forall_script(clowder, command, ignore_errors, group_names, project_names=None, skip=[], parallel=False)

    :param ClowderController clowder: ClowderController instance
    :param list[str] command: Command or script and optional arguments
    :param bool ignore_errors: Whether to exit if command returns a non-zero exit code
    :param list[str] group_names: Group names to run command for

    Keyword Args:
        project_names (list[str]): Project names to clean
        skip list[str]: Project names to skip
        parallel bool: Whether command is being run in parallel, affects output
    """

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

    projects = filter_projects(clowder.groups,
                               group_names=group_names,
                               project_names=project_names)

    if parallel:
        forall_parallel([" ".join(command)], skip, ignore_errors, projects)
        if os.name == "posix":
            return

    for project in projects:
        run_project_command(project, skip, 'run', [" ".join(command)],
                            ignore_errors)
Esempio n. 2
0
    def _branch(self):
        """Clowder branch command private implementation"""
        local = True
        remote = False
        if self.app.pargs.all:
            local = True
            remote = True
        elif self.app.pargs.remote:
            remote = True

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

        projects = filter_projects(CLOWDER_CONTROLLER.groups,
                                   project_names=self.app.pargs.projects)
        for project in projects:
            run_project_command(project,
                                self.app.pargs.skip,
                                'branch',
                                local=local,
                                remote=remote)
Esempio n. 3
0
def _clean(clowder, group_names, **kwargs):
    """Discard changes

    .. py:function:: clean(group_names, args='', recursive=False, project_names=None, skip=[])

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

    Keyword Args:
        args (str): Git clean options
            - ``d`` Remove untracked directories in addition to untracked files
            - ``f`` Delete directories with .git sub directory or file
            - ``X`` Remove only files ignored by git
            - ``x`` Remove all untracked files
        recursive (bool): Clean submodules recursively
        project_names (list[str]): Project names to clean
        skip (list[str]): Project names to skip
    """

    project_names = kwargs.get('project_names', None)
    skip = kwargs.get('skip', [])
    args = kwargs.get('args', '')
    recursive = kwargs.get('recursive', False)

    if project_names is None:
        groups = filter_groups(clowder.groups, group_names)
        for group in groups:
            run_group_command(group, skip, 'clean', args=args, recursive=recursive)
        return

    projects = filter_projects(clowder.groups, project_names=project_names)
    for project in projects:
        run_project_command(project, skip, 'clean', args=args, recursive=recursive)
Esempio n. 4
0
def _clean_all(clowder, group_names, **kwargs):
    """Discard all changes

    .. py:function:: clean_all(group_names, project_names=None, skip=[])

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

    Keyword Args:
        project_names (list[str]): Project names to clean
        skip (list[str]): Project names to skip
    """

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

    if project_names is None:
        groups = filter_groups(clowder.groups, group_names)
        for group in groups:
            run_group_command(group, skip, 'clean_all')
        return

    projects = filter_projects(clowder.groups, project_names=project_names)
    for project in projects:
        run_project_command(project, skip, 'clean_all')
Esempio n. 5
0
    def _diff(self):
        """Clowder diff command private implementation"""

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

        projects = filter_projects(CLOWDER_CONTROLLER.groups, project_names=self.app.pargs.projects)
        for project in projects:
            run_project_command(project, self.app.pargs.skip, 'diff')
Esempio n. 6
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)
Esempio n. 7
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)
Esempio n. 8
0
    def _stash(self):
        """Clowder stash command private implementation"""

        if not any([g.is_dirty() for g in CLOWDER_CONTROLLER.groups]):
            print('No changes to stash')
            return

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

        projects = filter_projects(CLOWDER_CONTROLLER.groups,
                                   project_names=self.app.pargs.projects)
        for project in projects:
            run_project_command(project, self.app.pargs.skip, 'stash')
Esempio n. 9
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)
Esempio n. 10
0
def _prune_projects(projects, branch, **kwargs):
    """Prune project branches

    .. py:function:: _prune_projects(projects, branch, local=False, remote=False, force=False, skip=[])

    :param list[Project] projects: Projects to prune
    :param str branch: Branch to prune

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

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

    local_branch_exists = existing_branch_projects(projects,
                                                   branch,
                                                   is_remote=False)
    remote_branch_exists = existing_branch_projects(projects,
                                                    branch,
                                                    is_remote=True)

    try:
        _validate_branches(local, remote, local_branch_exists,
                           remote_branch_exists)
    except ClowderError:
        pass
    else:
        for project in projects:
            run_project_command(project,
                                skip,
                                'prune',
                                branch,
                                force=force,
                                local=local,
                                remote=remote)