python
#!/home/labstation/.local/anaconda3/bin/python3
from paramiko import SSHClient as ssh
from paramiko import AutoAddPolicy
from rich.console import Console
import os
import time
cli = ssh()
cli.load_system_host_keys()
cli.set_missing_host_key_policy(AutoAddPolicy())
cli.connect("128.0.0.1", username="git")
stdin, stdout, stderr = cli.exec_command("")
repos = list(
filter(
lambda x: x.startswith("sw"),
map(
lambda x: x[x.find("sw") :],
filter(
lambda x: x.startswith("R") or x.startswith("W"),
map(lambda x: x.strip(" "), stdout.read().decode("utf-8").split("\n")),
),
),
)
)
richConsole = Console()
richConsole.print()
with richConsole.status("[red] company repos backup working[/]") as status:
for repo in repos:
if os.access("/home/labstation/workqueue/%s" % (repo), os.F_OK):
print(f"{repo} fetch from remote start")
os.system(
"cd /home/labstation/workqueue/%s && git fetch 2>/dev/null 1>/dev/null"
% (repo)
)
print(f"{repo} fetch from remote complete")
else:
print(f"{repo} clone from remote start")
os.system(
"git clone git@128.0.0.1:%s /home/labstation/workqueue/%s \
2>/dev/null 1>/dev/null"
% (repo, repo),
)
print(f"{repo} clone from remote complete")