class DiffController(ArgparseController): """Clowder diff command controller""" class Meta: """Clowder diff Meta configuration""" label = 'diff' stacked_on = 'base' stacked_type = 'embedded' description = 'Show git diff for projects' @expose( help='Show git diff for projects', arguments=[ (['--groups', '-g'], dict(choices=CLOWDER_CONTROLLER.get_all_group_names(), default=CLOWDER_CONTROLLER.get_all_group_names(), nargs='+', metavar='GROUP', help=options_help_message(CLOWDER_CONTROLLER.get_all_group_names(), 'groups to show diff for'))), (['--projects', '-p'], dict(choices=CLOWDER_CONTROLLER.get_all_project_names(), nargs='+', metavar='PROJECT', help=options_help_message(CLOWDER_CONTROLLER.get_all_project_names(), 'projects to show diff for'))), (['--skip', '-s'], dict(choices=CLOWDER_CONTROLLER.get_all_project_names(), nargs='+', metavar='PROJECT', default=[], help=options_help_message(CLOWDER_CONTROLLER.get_all_project_names(), 'projects to skip'))) ] ) def diff(self): """Clowder diff command entry point""" self._diff() @valid_clowder_yaml_required @print_clowder_repo_status 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')
class LinkController(ArgparseController): """Clowder link command controller""" class Meta: """Clowder link Meta configuration""" label = 'link' stacked_on = 'base' stacked_type = 'embedded' description = 'Symlink clowder.yaml version' @expose(help='Symlink clowder.yaml version', arguments=[ (['--version', '-v'], dict(choices=get_saved_version_names(), nargs=1, default=None, metavar='VERSION', help=options_help_message(get_saved_version_names(), 'version to symlink'))) ]) def link(self): """Clowder link command entry point""" self._link() @clowder_required @print_clowder_repo_status def _link(self): """Clowder link command private implementation""" if self.app.pargs.version is None: version = None else: version = self.app.pargs.version[0] link_clowder_yaml(version)
class SyncController(ArgparseController): """Clowder sync command controller""" class Meta: """Clowder sync Meta configuration""" label = 'sync' stacked_on = 'base' stacked_type = 'embedded' description = 'Sync fork with upstream remote' @expose(help='Sync fork with upstream remote', arguments=[ (['--projects', '-p'], dict(choices=CLOWDER_CONTROLLER.get_all_fork_project_names(), nargs='+', metavar='PROJECT', help=options_help_message( CLOWDER_CONTROLLER.get_all_fork_project_names(), 'projects to sync'))), (['--protocol'], dict(choices=['https', 'ssh'], nargs=1, default=None, metavar='PROTOCOL', help='Protocol to clone new repos with')), (['--rebase', '-r'], dict(action='store_true', help='use rebase instead of pull')), (['--parallel'], dict(action='store_true', help='run commands in parallel')) ]) def sync(self): """Clowder sync command entry point""" self._sync() @network_connection_required @valid_clowder_yaml_required @print_clowder_repo_status_fetch def _sync(self): """Clowder sync command private implementation""" protocol = None if self.app.pargs.protocol is None else self.app.pargs.protocol[ 0] all_fork_projects = CLOWDER_CONTROLLER.get_all_fork_project_names() if all_fork_projects == '': cprint(' - No forks to sync\n', 'red') return sync(CLOWDER_CONTROLLER, all_fork_projects, protocol=protocol, rebase=self.app.pargs.rebase, parallel=self.app.pargs.parallel)
class StartController(ArgparseController): """Clowder start command controller""" class Meta: """Clowder start Meta configuration""" label = 'start' stacked_on = 'base' stacked_type = 'embedded' description = 'Start a new branch' @expose( help='Start a new branch', arguments=[ (['branch'], dict(help='name of branch to create', metavar='BRANCH')), (['--tracking', '-t'], dict(action='store_true', help='create remote tracking branch')), (['--groups', '-g'], dict(choices=CLOWDER_CONTROLLER.get_all_group_names(), default=CLOWDER_CONTROLLER.get_all_group_names(), nargs='+', metavar='GROUP', help=options_help_message(CLOWDER_CONTROLLER.get_all_group_names(), 'groups to start'))), (['--projects', '-p'], dict(choices=CLOWDER_CONTROLLER.get_all_project_names(), nargs='+', metavar='PROJECT', help=options_help_message(CLOWDER_CONTROLLER.get_all_project_names(), 'projects to start'))), (['--skip', '-s'], dict(choices=CLOWDER_CONTROLLER.get_all_project_names(), nargs='+', metavar='PROJECT', default=[], help=options_help_message(CLOWDER_CONTROLLER.get_all_project_names(), 'projects to skip'))) ] ) def start(self): """Clowder start command entry point""" self._start() @valid_clowder_yaml_required @print_clowder_repo_status def _start(self): """Clowder start command private implementation""" if self.app.pargs.tracking: self._start_tracking() return self._start_branches(False) @network_connection_required def _start_tracking(self): """clowder start tracking command""" self._start_branches(True) 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)
class CheckoutController(ArgparseController): """Clowder checkout command controller""" class Meta: """Clowder checkout Meta configuration""" label = 'checkout' stacked_on = 'base' stacked_type = 'embedded' description = 'Checkout local branch in projects' @expose(help='Checkout local branch in projects', arguments=[ (['branch'], dict(nargs=1, action='store', help='branch to checkout', metavar='BRANCH')), (['--groups', '-g'], dict(choices=CLOWDER_CONTROLLER.get_all_group_names(), default=CLOWDER_CONTROLLER.get_all_group_names(), nargs='+', metavar='GROUP', help=options_help_message( CLOWDER_CONTROLLER.get_all_group_names(), 'groups to checkout branches for'))), (['--projects', '-p'], dict(choices=CLOWDER_CONTROLLER.get_all_project_names(), nargs='+', metavar='PROJECT', help=options_help_message( CLOWDER_CONTROLLER.get_all_project_names(), 'projects to checkout branches for'))), (['--skip', '-s'], dict(choices=CLOWDER_CONTROLLER.get_all_project_names(), nargs='+', metavar='PROJECT', default=[], help=options_help_message( CLOWDER_CONTROLLER.get_all_project_names(), 'projects to skip'))) ]) def checkout(self): """Clowder checkout command entry point""" self._checkout() @valid_clowder_yaml_required @print_clowder_repo_status def _checkout(self): """Clowder checkout 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, 'checkout', self.app.pargs.branch[0]) 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, 'checkout', self.app.pargs.branch[0])
class BranchController(ArgparseController): """Clowder branch command controller""" class Meta: """Clowder branch Meta configuration""" label = 'branch' stacked_on = 'base' stacked_type = 'embedded' description = 'Display current branches' @expose(help='Display current branches', arguments=[ (['--all', '-a'], dict(action='store_true', help='show local and remote branches')), (['--remote', '-r'], dict(action='store_true', help='show remote branches')), (['--groups', '-g'], dict(choices=CLOWDER_CONTROLLER.get_all_group_names(), default=CLOWDER_CONTROLLER.get_all_group_names(), nargs='+', metavar='GROUP', help=options_help_message( CLOWDER_CONTROLLER.get_all_group_names(), 'groups to show branches for'))), (['--projects', '-p'], dict(choices=CLOWDER_CONTROLLER.get_all_project_names(), nargs='+', metavar='PROJECT', help=options_help_message( CLOWDER_CONTROLLER.get_all_project_names(), 'projects to show branches for'))), (['--skip', '-s'], dict(choices=CLOWDER_CONTROLLER.get_all_project_names(), nargs='+', metavar='PROJECT', default=[], help=options_help_message( CLOWDER_CONTROLLER.get_all_project_names(), 'projects to skip'))) ]) def branch(self): """Clowder branch command entry point""" self._branch() @valid_clowder_yaml_required @print_clowder_repo_status 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)
class ForallController(ArgparseController): """Clowder forall command controller""" class Meta: """Clowder forall Meta configuration""" label = 'forall' stacked_on = 'base' stacked_type = 'embedded' description = 'Run command or script in project directories' @expose(help='Run command or script in project directories', arguments=[ (['--command', '-c'], dict(nargs='+', metavar='COMMAND', default=None, help='command or script to run in project directories')), (['--ignore-errors', '-i'], dict(action='store_true', help='ignore errors in command or script')), (['--parallel'], dict(action='store_true', help='run commands in parallel')), (['--groups', '-g'], dict(choices=CLOWDER_CONTROLLER.get_all_group_names(), default=CLOWDER_CONTROLLER.get_all_group_names(), nargs='+', metavar='GROUP', help=options_help_message( CLOWDER_CONTROLLER.get_all_group_names(), 'groups to run command for'))), (['--projects', '-p'], dict(choices=CLOWDER_CONTROLLER.get_all_project_names(), nargs='+', metavar='PROJECT', help=options_help_message( CLOWDER_CONTROLLER.get_all_project_names(), 'projects to run command for'))), (['--skip', '-s'], dict(choices=CLOWDER_CONTROLLER.get_all_project_names(), nargs='+', metavar='PROJECT', default=[], help=options_help_message( CLOWDER_CONTROLLER.get_all_project_names(), 'projects to skip'))) ]) def forall(self): """Clowder forall command entry point""" self._forall() @valid_clowder_yaml_required @print_clowder_repo_status def _forall(self): """Clowder forall command private implementation""" forall(CLOWDER_CONTROLLER, self.app.pargs.command, self.app.pargs.ignore_errors, group_names=self.app.pargs.groups, project_names=self.app.pargs.projects, skip=self.app.pargs.skip, parallel=self.app.pargs.parallel)
class PruneController(ArgparseController): """Clowder prune command controller""" class Meta: """Clowder prune Meta configuration""" label = 'prune' stacked_on = 'base' stacked_type = 'embedded' description = 'Prune branches' @expose(help='Prune branches', arguments=[ (['branch'], dict(help='name of branch to remove', metavar='BRANCH')), (['--force', '-f'], dict(action='store_true', help='force prune branches')), (['--all', '-a'], dict(action='store_true', help='prune local and remote branches')), (['--remote', '-r'], dict(action='store_true', help='prune remote branches')), (['--groups', '-g'], dict(choices=CLOWDER_CONTROLLER.get_all_group_names(), default=CLOWDER_CONTROLLER.get_all_group_names(), nargs='+', metavar='GROUP', help=options_help_message( CLOWDER_CONTROLLER.get_all_group_names(), 'groups to prune'))), (['--projects', '-p'], dict(choices=CLOWDER_CONTROLLER.get_all_project_names(), nargs='+', metavar='PROJECT', help=options_help_message( CLOWDER_CONTROLLER.get_all_project_names(), 'projects to prune'))), (['--skip', '-s'], dict(choices=CLOWDER_CONTROLLER.get_all_project_names(), nargs='+', metavar='PROJECT', default=[], help=options_help_message( CLOWDER_CONTROLLER.get_all_project_names(), 'projects to skip'))) ]) def prune(self): """Clowder prune command entry point""" self._prune() @valid_clowder_yaml_required @print_clowder_repo_status def _prune(self): """Clowder prune command private implementation""" if self.app.pargs.all: self._prune_all() return if self.app.pargs.remote: self._prune_remote() return _prune(CLOWDER_CONTROLLER, self.app.pargs.groups, self.app.pargs.branch, project_names=self.app.pargs.projects, skip=self.app.pargs.skip, force=self.app.pargs.force, local=True) @network_connection_required def _prune_all(self): """clowder prune all command""" _prune(CLOWDER_CONTROLLER, self.app.pargs.groups, self.app.pargs.branch, project_names=self.app.pargs.projects, skip=self.app.pargs.skip, force=self.app.pargs.force, local=True, remote=True) @network_connection_required def _prune_remote(self): """clowder prune remote command""" _prune(CLOWDER_CONTROLLER, self.app.pargs.groups, self.app.pargs.branch, project_names=self.app.pargs.projects, skip=self.app.pargs.skip, remote=True)
class ResetController(ArgparseController): """Clowder reset command controller""" class Meta: """Clowder reset Meta configuration""" label = 'reset' stacked_on = 'base' stacked_type = 'embedded' description = 'Reset branches to upstream commits or check out detached HEADs for tags and shas' @expose( help= 'Reset branches to upstream commits or check out detached HEADs for tags and shas', arguments=[(['--parallel'], dict(action='store_true', help='run commands in parallel')), (['--timestamp', '-t'], dict(choices=CLOWDER_CONTROLLER.get_all_project_names(), default=None, nargs=1, metavar='TIMESTAMP', help='project to reset timestamps relative to')), (['--groups', '-g'], dict(choices=CLOWDER_CONTROLLER.get_all_group_names(), default=CLOWDER_CONTROLLER.get_all_group_names(), nargs='+', metavar='GROUP', help=options_help_message( CLOWDER_CONTROLLER.get_all_group_names(), 'groups to reset'))), (['--projects', '-p'], dict(choices=CLOWDER_CONTROLLER.get_all_project_names(), nargs='+', metavar='PROJECT', help=options_help_message( CLOWDER_CONTROLLER.get_all_project_names(), 'projects to reset'))), (['--skip', '-s'], dict(choices=CLOWDER_CONTROLLER.get_all_project_names(), nargs='+', metavar='PROJECT', default=[], help=options_help_message( CLOWDER_CONTROLLER.get_all_project_names(), 'projects to skip')))]) def reset(self): """Clowder reset command entry point""" self._reset() @network_connection_required @valid_clowder_yaml_required @print_clowder_repo_status_fetch def _reset(self): """Clowder reset command private implementation""" timestamp_project = None if self.app.pargs.timestamp: timestamp_project = self.app.pargs.timestamp[0] reset(CLOWDER_CONTROLLER, group_names=self.app.pargs.groups, project_names=self.app.pargs.projects, skip=self.app.pargs.skip, timestamp_project=timestamp_project, parallel=self.app.pargs.parallel)
class HerdController(ArgparseController): """Clowder herd command controller""" class Meta: """Clowder herd Meta configuration""" label = 'herd' stacked_on = 'base' stacked_type = 'embedded' description = 'Clone and update projects with latest changes' @expose(help='Clone and update projects with latest changes', arguments=[ (['--parallel'], dict(action='store_true', help='run commands in parallel')), (['--protocol'], dict(choices=['https', 'ssh'], nargs=1, default=None, metavar='PROTOCOL', help='Protocol to clone new repos with')), (['--rebase', '-r'], dict(action='store_true', help='use rebase instead of pull')), (['--depth', '-d'], dict(default=None, type=int, nargs=1, metavar='DEPTH', help='depth to herd')), (['--branch', '-b'], dict(nargs=1, default=None, metavar='BRANCH', help='branch to herd if present')), (['--tag', '-t'], dict(nargs=1, default=None, metavar='TAG', help='tag to herd if present')), (['--groups', '-g'], dict(choices=CLOWDER_CONTROLLER.get_all_group_names(), default=CLOWDER_CONTROLLER.get_all_group_names(), nargs='+', metavar='GROUP', help=options_help_message( CLOWDER_CONTROLLER.get_all_group_names(), 'groups to herd'))), (['--projects', '-p'], dict(choices=CLOWDER_CONTROLLER.get_all_project_names(), nargs='+', metavar='PROJECT', help=options_help_message( CLOWDER_CONTROLLER.get_all_project_names(), 'projects to herd'))), (['--skip', '-s'], dict(choices=CLOWDER_CONTROLLER.get_all_project_names(), nargs='+', metavar='PROJECT', default=[], help=options_help_message( CLOWDER_CONTROLLER.get_all_project_names(), 'projects to skip'))) ]) def herd(self): """Clowder herd command entry point""" self._herd() @network_connection_required @valid_clowder_yaml_required @print_clowder_repo_status_fetch def _herd(self): """Clowder herd command private implementation""" branch = None if self.app.pargs.branch is None else self.app.pargs.branch[ 0] tag = None if self.app.pargs.tag is None else self.app.pargs.tag[0] depth = None if self.app.pargs.depth is None else self.app.pargs.depth[ 0] protocol = None if self.app.pargs.protocol is None else self.app.pargs.protocol[ 0] kwargs = { 'group_names': self.app.pargs.groups, 'project_names': self.app.pargs.projects, 'skip': self.app.pargs.skip, 'branch': branch, 'tag': tag, 'depth': depth, 'rebase': self.app.pargs.rebase, 'protocol': protocol } if self.app.pargs.parallel: herd_parallel(CLOWDER_CONTROLLER, **kwargs) if os.name == "posix": return herd(CLOWDER_CONTROLLER, **kwargs)
class CleanController(ArgparseController): """Clowder clean command controller""" class Meta: """Clowder clean Meta configuration""" label = 'clean' stacked_on = 'base' stacked_type = 'embedded' description = 'Discard current changes in projects' @expose( help='Discard current changes in projects', arguments=[ (['--all', '-a'], dict(action='store_true', help='clean all the things')), (['--recursive', '-r'], dict(action='store_true', help='clean submodules recursively')), (['-d'], dict(action='store_true', help='remove untracked directories')), (['-f'], dict(action='store_true', help='remove directories with .git subdirectory or file')), (['-X'], dict(action='store_true', help='remove only files ignored by git')), (['-x'], dict(action='store_true', help='remove all untracked files')), (['--groups', '-g'], dict(choices=CLOWDER_CONTROLLER.get_all_group_names(), default=CLOWDER_CONTROLLER.get_all_group_names(), nargs='+', metavar='GROUP', help=options_help_message(CLOWDER_CONTROLLER.get_all_group_names(), 'groups to clean'))), (['--projects', '-p'], dict(choices=CLOWDER_CONTROLLER.get_all_project_names(), nargs='+', metavar='PROJECT', help=options_help_message(CLOWDER_CONTROLLER.get_all_project_names(), 'projects to clean'))), (['--skip', '-s'], dict(choices=CLOWDER_CONTROLLER.get_all_project_names(), nargs='+', metavar='PROJECT', default=[], help=options_help_message(CLOWDER_CONTROLLER.get_all_project_names(), 'projects to skip'))) ] ) def clean(self): """Clowder clean command entry point""" self._clean() @valid_clowder_yaml_required @print_clowder_repo_status def _clean(self): """Clowder clean command private implementation""" if self.app.pargs.all: _clean_all(CLOWDER_CONTROLLER, group_names=self.app.pargs.groups, project_names=self.app.pargs.projects, skip=self.app.pargs.skip) return clean_args = '' if self.app.pargs.d: clean_args += 'd' if self.app.pargs.f: clean_args += 'f' if self.app.pargs.X: clean_args += 'X' if self.app.pargs.x: clean_args += 'x' _clean(CLOWDER_CONTROLLER, group_names=self.app.pargs.groups, project_names=self.app.pargs.projects, skip=self.app.pargs.skip, args=clean_args, recursive=self.app.pargs.recursive)