def foreach(workspace: tsrc.Workspace, *args: Any, **kwargs: Any) -> None: cmd: List[str] = args # type: ignore shell: bool = kwargs["shell"] # Note: # we want to support both: # $ tsrc foreach -c 'shell command' # and # $ tsrc foreach -- some-cmd --some-opts # # Due to argparse limitations, `cmd` will always be a list, # but we need a *string* when using 'shell=True'. # # So transform use the value from `cmd` and `shell` to build: # * `subprocess_cmd`, suitable as argument to pass to subprocess.run() # * `cmd_as_str`, suitable for display purposes command: Command = [] if shell: if len(cmd) != 1: die("foreach -c must be followed by exactly one argument") command = cmd[0] description = cmd[0] else: if not cmd: die("needs a command to run") command = cmd description = " ".join(cmd) cmd_runner = CmdRunner(workspace.root_path, command, description, shell=shell) tsrc.run_sequence(workspace.repos, cmd_runner) ui.info("OK", ui.check)
def run(args: argparse.Namespace) -> None: # Note: # we want to support both: # $ tsrc foreach -c 'shell command' # and # $ tsrc foreach -- some-cmd --some-opts # # Due to argparse limitations, `cmd` will always be a list, # but we need a *string* when using 'shell=True'. # # So transform use the value from `cmd` and `shell` so that: # * action.command is suitable as argument to pass to subprocess.run() # * action.description is suitable for display purposes command: Command = [] if args.shell: if len(args.cmd) != 1: die("foreach -c must be followed by exactly one argument") command = args.cmd[0] description = args.cmd[0] else: if not args.cmd: die("needs a command to run") command = args.cmd description = " ".join(args.cmd) shell = args.shell command = command description = description workspace = get_workspace_with_repos(args) cmd_runner = CmdRunner(workspace.root_path, command, description, shell=shell) tsrc.run_sequence(workspace.repos, cmd_runner) ui.info("OK", ui.check)
def main(args: argparse.Namespace) -> None: workspace = tsrc.cli.get_workspace(args) cmd_runner = CmdRunner(workspace.root_path, args.cmd, args.cmd_as_str, shell=args.shell) manifest = workspace.local_manifest.get_manifest() workspace_config = workspace.config groups_from_config = workspace_config.repo_groups all_remote_repos = manifest.get_repos(all_=True) cloned_repos = [ x for x in all_remote_repos if (workspace.root_path / x.src).exists() ] if args.groups_from_config: requested_repos = manifest.get_repos(groups=groups_from_config) elif args.groups: requested_repos = manifest.get_repos(groups=args.groups) else: requested_repos = cloned_repos found = [x for x in requested_repos if x in cloned_repos] missing = [x for x in requested_repos if x not in cloned_repos] tsrc.run_sequence(found, cmd_runner) if missing: ui.warning( "The following repos were requested but missing from the workspace:" ) for repo in missing: ui.info("*", repo.src, fileobj=sys.stderr) raise MissingRepos(missing) else: ui.info("OK", ui.check)
def main(args: argparse.Namespace) -> None: workspace = tsrc.cli.get_workspace(args) workspace.load_manifest() cmd_runner = CmdRunner( workspace.root_path, args.cmd, args.cmd_as_str, shell=args.shell ) manifest = workspace.local_manifest.manifest assert manifest cloned_repos = workspace.get_repos() requested_repos = manifest.get_repos(groups=args.groups) found = [x for x in requested_repos if x in cloned_repos] missing = [x for x in requested_repos if x not in cloned_repos] tsrc.run_sequence(found, cmd_runner) if missing: ui.warning("The following repos were skipped:") for repo in missing: ui.info("*", repo.src, fileobj=sys.stderr) else: ui.info("OK", ui.check)
def test_collect_errors() -> None: task = FakeTask() with pytest.raises(tsrc.ExecutorFailed): tsrc.run_sequence(["foo", "bar"], task)
def test_happy() -> None: task = FakeTask() tsrc.run_sequence(["foo", "spam"], task)
def test_doing_nothing() -> None: task = FakeTask() tsrc.run_sequence(list(), task)
def run(args: argparse.Namespace) -> None: workspace = get_workspace_with_repos(args) status_collector = StatusCollector(workspace) tsrc.run_sequence(workspace.repos, status_collector)
def status(workspace: tsrc.Workspace, **kwargs: Any) -> None: """ display workspace status summary """ status_collector = StatusCollector(workspace) tsrc.run_sequence(workspace.repos, status_collector)
def main(args: argparse.Namespace) -> None: workspace = tsrc.cli.get_workspace(args) status_collector = StatusCollector(workspace) tsrc.run_sequence(workspace.get_repos(), status_collector)
def main(args: argparse.Namespace) -> None: workspace = tsrc.cli.get_workspace(args) status_collector = StatusCollector(workspace.root_path) workspace.load_manifest() tsrc.run_sequence(workspace.get_repos(), status_collector)