Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def _handle_repo(self, repo_config: Any) -> None:
src = repo_config["src"]
branch = repo_config.get("branch", "master")
tag = repo_config.get("tag")
sha1 = repo_config.get("sha1")
url = repo_config.get("url")
if url:
origin = tsrc.Remote(name="origin", url=url)
remotes = [origin]
else:
remotes = self._handle_remotes(repo_config)
repo = tsrc.Repo(src=src, branch=branch, sha1=sha1, tag=tag, remotes=remotes)
self._repos.append(repo)
from path import Path
import cli_ui as ui
import tsrc
import tsrc.cli
class CommandFailed(tsrc.Error):
pass
class CouldNotStartProcess(tsrc.Error):
pass
class CmdRunner(tsrc.Task[tsrc.Repo]):
def __init__(
self, workspace_path: Path, cmd: List[str], cmd_as_str: str, shell: bool = False
) -> None:
self.workspace_path = workspace_path
self.cmd = cmd
self.cmd_as_str = cmd_as_str
self.shell = shell
def display_item(self, repo: tsrc.Repo) -> str:
return repo.src
def on_start(self, *, num_items: int) -> None:
ui.info_1("Running `%s` on %d repos" % (self.cmd_as_str, num_items))
def on_failure(self, *, num_errors: int) -> None:
ui.error("Command failed for %s repo(s)" % num_errors)
return res
def describe_dirty(git_status: tsrc.git.Status) -> List[ui.Token]:
res = [] # type: List[ui.Token]
if git_status.dirty:
res += [ui.red, "(dirty)"]
return res
def erase_last_line() -> None:
terminal_size = shutil.get_terminal_size()
ui.info(" " * terminal_size.columns, end="\r")
class StatusCollector(tsrc.Task[tsrc.Repo]):
def __init__(self, workspace_path: Path) -> None:
self.workspace_path = workspace_path
self.statuses = collections.OrderedDict() # type: CollectedStatuses
self.num_repos = 0
def display_item(self, repo: tsrc.Repo) -> str:
return repo.src
def process(self, index: int, total: int, repo: tsrc.Repo) -> None:
ui.info_count(index, total, repo.src, end="\r")
full_path = self.workspace_path / repo.src
if not full_path.exists():
self.statuses[repo.src] = tsrc.errors.MissingRepo(repo.src)
return