mirror of
https://git.alemi.dev/gitshell.git
synced 2024-11-21 23:14:53 +01:00
30 lines
874 B
Python
Executable file
30 lines
874 B
Python
Executable file
#!/usr/bin/env python
|
|
|
|
import os
|
|
from pathlib import Path
|
|
|
|
GIT_ROOT = Path(os.environ.get("GIT_ROOT_DIR") or "/srv/git/")
|
|
|
|
def pre(depth: int, last: bool = False) -> str:
|
|
return (': ' * (depth)) + ("'-" if last else '|-')
|
|
|
|
def print_dir(dir: str, depth: int):
|
|
print(f"{pre(depth)}+ {dir}/")
|
|
|
|
def print_repo(repo: str, depth: int, last: bool = False):
|
|
print(f"{pre(depth, last=last)} {repo.replace('.git','')}")
|
|
|
|
def run_on_all_repos(root: Path, depth: int = 0):
|
|
contents = os.listdir(root)
|
|
for element in contents:
|
|
full_path = root / element
|
|
if element.startswith("."):
|
|
pass # ignore hidden files
|
|
elif element.endswith(".git"):
|
|
print_repo(element, depth, last=element==contents[-1])
|
|
elif os.path.isdir(root / element):
|
|
print_dir(element, depth)
|
|
run_on_all_repos(root / element, depth=depth+1)
|
|
|
|
if __name__ == "__main__":
|
|
run_on_all_repos(GIT_ROOT)
|