仓库同步脚本

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 [email protected]:%s /home/labstation/workqueue/%s \
                2>/dev/null 1>/dev/null"
                % (repo, repo),
            )
            print(f"{repo} clone from remote complete")
相关推荐
大霸王龙25 分钟前
软件工程的软件生命周期通常分为以下主要阶段
大数据·人工智能·旅游
点赋科技1 小时前
沙市区举办资本市场赋能培训会 点赋科技分享智能消费新实践
大数据·人工智能
YSGZJJ1 小时前
股指期货技术分析与短线操作方法介绍
大数据·人工智能
Doker 多克1 小时前
Flink CDC —部署模式
大数据·flink
Guheyunyi2 小时前
监测预警系统重塑隧道安全新范式
大数据·运维·人工智能·科技·安全
Channing Lewis3 小时前
如果科技足够发达,是否还需要维持自然系统(例如生物多样性)中那种‘冗余’和‘多样性’,还是可以只保留最优解?
大数据·人工智能·科技
禺垣3 小时前
区块链技术概述
大数据·人工智能·分布式·物联网·去中心化·区块链
IvanCodes4 小时前
七、Sqoop Job:简化与自动化数据迁移任务及免密执行
大数据·数据库·hadoop·sqoop
冬至喵喵5 小时前
【hive】函数集锦:窗口函数、列转行、日期函数
大数据·数据仓库·hive·hadoop