diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2021-01-25 12:57:06 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2021-01-25 12:57:15 +0000 |
commit | 85cebf7af1712dfc8214564045d68317656cf03b (patch) | |
tree | abd3aa80bb35025159939826e1ee75c430fa7522 /gita/utils.py | |
parent | Releasing debian version 0.11.9-1. (diff) | |
download | gita-85cebf7af1712dfc8214564045d68317656cf03b.tar.xz gita-85cebf7af1712dfc8214564045d68317656cf03b.zip |
Merging upstream version 0.12.9.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'gita/utils.py')
-rw-r--r-- | gita/utils.py | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/gita/utils.py b/gita/utils.py index d30a82e..9572f02 100644 --- a/gita/utils.py +++ b/gita/utils.py @@ -4,7 +4,7 @@ import asyncio import platform from functools import lru_cache, partial from pathlib import Path -from typing import List, Dict, Coroutine, Union +from typing import List, Dict, Coroutine, Union, Iterator from . import info from . import common @@ -60,7 +60,6 @@ def get_groups() -> Dict[str, List[str]]: return groups - def get_choices() -> List[Union[str, None]]: """ Return all repo names, group names, and an additional empty list. The empty @@ -128,6 +127,8 @@ def write_to_groups_file(groups: Dict[str, List[str]], mode: str): def add_repos(repos: Dict[str, str], new_paths: List[str]): """ Write new repo paths to file + + @param repos: name -> path """ existing_paths = set(repos.values()) new_paths = set(os.path.abspath(p) for p in new_paths if is_git(p)) @@ -142,6 +143,15 @@ def add_repos(repos: Dict[str, str], new_paths: List[str]): print('No new repos found!') +def parse_clone_config(fname: str) -> Iterator[List[str]]: + """ + Return the url, name, and path of all repos in `fname`. + """ + with open(fname) as f: + for line in f: + yield line.strip().split(',') + + async def run_async(repo_name: str, path: str, cmds: List[str]) -> Union[None, str]: """ Run `cmds` asynchronously in `path` directory. Return the `path` if @@ -157,7 +167,7 @@ async def run_async(repo_name: str, path: str, cmds: List[str]) -> Union[None, s stdout, stderr = await process.communicate() for pipe in (stdout, stderr): if pipe: - print(format_output(pipe.decode(), f'{repo_name}: ')) + print(format_output(pipe.decode(), repo_name)) # The existence of stderr is not good indicator since git sometimes write # to stderr even if the execution is successful, e.g. git fetch if process.returncode != 0: @@ -168,7 +178,7 @@ def format_output(s: str, prefix: str): """ Prepends every line in given string with the given prefix. """ - return ''.join([f'{prefix}{line}' for line in s.splitlines(keepends=True)]) + return ''.join([f'{prefix}: {line}' for line in s.splitlines(keepends=True)]) def exec_async_tasks(tasks: List[Coroutine]) -> List[Union[None, str]]: |