Exemplo n.º 1
0
 def process(self, index: int, count: int,
             item: tsrc.FileSystemOperation) -> None:
     ui.info_count(index, count, item)
     try:
         item.perform(self.workspace_path)
     except OSError as e:
         raise tsrc.Error(str(e))
Exemplo n.º 2
0
    def process(self, index: int, count: int, repo: tsrc.Repo) -> None:
        """Synchronize a repo given its configuration in the manifest.

        Always start by running `git fetch`, then either:

        * try resetting the repo to the given tag or sha1 (abort
          if the repo is dirty)

        * or try merging the local branch with its upstream (abort if not
          on on the correct branch, or if the merge is not fast-forward).
        """
        ui.info_count(index, count, repo.dest)
        repo_path = self.workspace_path / repo.dest
        self.fetch(repo)
        ref = None

        if repo.tag:
            ref = repo.tag
        elif repo.sha1:
            ref = repo.sha1

        if ref:
            self.sync_repo_to_ref(repo_path, ref)
        else:
            self.check_branch(repo, repo_path)
            self.sync_repo_to_branch(repo_path)
Exemplo n.º 3
0
    def process_item(self, index: int, count: int, item: T) -> Outcome:
        # We want to keep all output when processing items it parallel on just
        # one line (like ninja-build)
        #
        # To do that, we need a lock on stdout. We also need task.process() to
        # be silent, which should be the case if it is implemented correctly
        tokens = self.task.describe_process_start(item)
        if tokens:
            with self.lock:
                erase_last_line()
                ui.info_count(index, count, *tokens, end="\r")

        result = self.task.process(index, count, item)

        # Note: we don't know if tasks will be finished in the same order
        # they were started, so to keep the output relevant, we need a
        # done_count here.
        self.done_count += 1

        tokens = self.task.describe_process_end(item)
        if tokens:
            with self.lock:
                erase_last_line()
                ui.info_count(self.done_count - 1, count, *tokens, end="\r")
                if self.done_count == count:
                    ui.info()

        return result
Exemplo n.º 4
0
    def info_count(self, index: int, count: int, *args: Any, **kwargs: Any) -> None:
        """Same as cli_ui.info_count(), except this is a no-op if the
        task is run in parallel with other tasks.

        """
        if not self.parallel:
            ui.info_count(index, count, *args, **kwargs)
 def print_group(self, dry_run: bool = False) -> None:
     if not self.actions:
         return
     if dry_run:
         ui.info_2(self.dry_run_desc)
     else:
         ui.info_2(self.desc)
     for i, action in enumerate(self.actions):
         if self.should_enumerate:
             ui.info_count(i, len(self.actions), end="")
         action.print_self()
Exemplo n.º 6
0
def bump_files(new_version: str, repo_path: Path = None) -> None:
    repo_path = repo_path or Path(".")
    bumper = FileBumper(repo_path)
    cfg = tbump.config.parse(repo_path / "pyproject.toml")
    bumper.set_config(cfg)
    patches = bumper.get_patches(new_version=new_version)
    n = len(patches)
    for i, patch in enumerate(patches):
        ui.info_count(i, n, patch.src)
        patch.print_self()
        patch.apply()
Exemplo n.º 7
0
def bump_files(new_version: str, repo_path: Optional[Path] = None) -> None:
    repo_path = repo_path or Path(".")
    bumper = FileBumper(repo_path)
    config_file = tbump.config.get_config_file(repo_path)
    bumper.set_config_file(config_file)
    patches = bumper.get_patches(new_version=new_version)
    n = len(patches)
    for i, patch in enumerate(patches):
        ui.info_count(i, n, patch.src)
        patch.print_self()
        patch.apply()
Exemplo n.º 8
0
 def process(self, index: int, count: int, repo: tsrc.Repo) -> None:
     ui.info_count(index, count, repo.src)
     # fmt: off
     ui.info(ui.lightgray, "$ ", ui.reset, ui.bold, self.cmd_as_str, sep="")
     # fmt: on
     full_path = self.workspace_path / repo.src
     try:
         rc = subprocess.call(self.cmd, cwd=full_path, shell=self.shell)
     except OSError as e:
         raise CouldNotStartProcess("Error when starting process:", e)
     if rc != 0:
         raise CommandFailed()
Exemplo n.º 9
0
    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

        try:
            self.statuses[repo.src] = tsrc.git.get_status(full_path)
        except Exception as e:
            self.statuses[repo.src] = e
        erase_last_line()
Exemplo n.º 10
0
 def process(self, index: int, count: int, item: Copy) -> None:
     src, dest = item
     ui.info_count(index, count, src, "->", dest)
     try:
         src_path = self.workspace_path / src
         dest_path = self.workspace_path / dest
         if dest_path.exists():
             # Re-set the write permissions on the file:
             dest_path.chmod(stat.S_IWRITE)
         src_path.copy(dest_path)
         # Make sure perms are read only for everyone
         dest_path.chmod(0o10444)
     except Exception as e:
         raise tsrc.Error(str(e))
Exemplo n.º 11
0
 def process(self, index: int, count: int, item: tsrc.Copy) -> None:
     known_sources = {x.src for x in self.repos}
     if item.repo not in known_sources:
         return
     ui.info_count(index, count, item.src, "->", item.dest)
     try:
         src_path = self.workspace_path / item.repo / item.src
         dest_path = self.workspace_path / item.dest
         if dest_path.exists():
             # Re-set the write permissions on the file:
             dest_path.chmod(stat.S_IWRITE)
         src_path.copy(dest_path)
         # Make sure perms are read only for everyone
         dest_path.chmod(0o10444)
     except Exception as e:
         raise tsrc.Error(str(e))
Exemplo n.º 12
0
    def process(self, items: List[T]) -> None:
        if not items:
            return
        self.task.on_start(num_items=len(items))

        self.errors = list()
        num_items = len(items)
        for i, item in enumerate(items):
            if not self.task.quiet():
                ui.info_count(i, num_items, end="")
            self.process_one(item)

        if self.errors:
            self.handle_errors()
        else:
            self.task.on_success()
Exemplo n.º 13
0
    def process(self, index: int, count: int, repo: tsrc.Repo) -> None:
        ui.info_count(index, count, repo.src)
        repo_path = self.workspace_path / repo.src
        self.fetch(repo)
        ref = None

        if repo.tag:
            ref = repo.tag
        elif repo.sha1:
            ref = repo.sha1

        if ref:
            self.sync_repo_to_ref(repo_path, ref)
        else:
            self.check_branch(repo, repo_path)
            self.sync_repo_to_branch(repo_path)
Exemplo n.º 14
0
    def process(self, index: int, total: int, repo: tsrc.Repo) -> None:
        ui.info_count(index, total, repo.dest, end="\r")
        full_path = self.workspace.root_path / repo.dest

        if not full_path.exists():
            self.statuses[repo.dest] = tsrc.errors.MissingRepo(repo.dest)
            return

        try:
            git_status = tsrc.git.get_status(full_path)
            manifest_status = ManifestStatus(repo, manifest=self.manifest)
            manifest_status.update(git_status)
            status = Status(git=git_status, manifest=manifest_status)
            self.statuses[repo.dest] = status
        except Exception as e:
            self.statuses[repo.dest] = e
        erase_last_line()
Exemplo n.º 15
0
 def process(self, index: int, count: int, repo: tsrc.Repo) -> None:
     ui.info_count(index, count, repo.dest)
     full_path = self.workspace_path / repo.dest
     if not full_path.exists():
         raise MissingRepo(repo.dest)
     # fmt: off
     ui.info(
         ui.lightgray, "$ ",
         ui.reset, ui.bold, self.description,
         sep=""
     )
     # fmt: on
     full_path = self.workspace_path / repo.dest
     try:
         rc = subprocess.call(self.command, cwd=full_path, shell=self.shell)
     except OSError as e:
         raise CouldNotStartProcess("Error when starting process:", e)
     if rc != 0:
         raise CommandFailed()
Exemplo n.º 16
0
def collect_statuses(
        workspace: tsrc.Workspace) -> List[Tuple[str, tsrc.git.Status]]:
    result = list()  # type: List[Tuple[str, tsrc.git.Status]]
    repos = workspace.get_repos()

    if not repos:
        return result

    num_repos = len(repos)
    max_len = max((len(x.src) for x in repos))
    for i, repo, full_path in workspace.enumerate_repos():
        ui.info_count(i,
                      num_repos,
                      "Checking",
                      repo.src.ljust(max_len + 1),
                      end="\r")
        status = tsrc.git.get_status(full_path)
        result.append((repo.src, status))

    terminal_size = shutil.get_terminal_size()
    ui.info(" " * terminal_size.columns, end="\r")
    return result
Exemplo n.º 17
0
 def process(self, index: int, count: int, item: str) -> None:
     ui.info_count(index, count, "frobnicate", item)
     if item == "bar":
         print("ko :/")
         raise Kaboom()
     ui.info("ok !")
Exemplo n.º 18
0
 def process(self, index: int, count: int, repo: tsrc.Repo) -> None:
     ui.info_count(index, count, repo.dest)
     self.check_shallow_with_sha1(repo)
     self.clone_repo(repo)
     self.reset_repo(repo)