仓库同步脚本

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")
相关推荐
洛森唛6 小时前
ElasticSearch查询语句Query String详解:从入门到精通
后端·elasticsearch
字节跳动数据平台7 小时前
5000 字技术向拆解 | 火山引擎多模态数据湖如何释放模思智能的算法生产力
大数据
武子康12 小时前
大数据-239 离线数仓 - 广告业务实战:Flume 导入日志到 HDFS,并完成 Hive ODS/DWD 分层加载
大数据·后端·apache hive
洛森唛1 天前
Elasticsearch DSL 查询语法大全:从入门到精通
后端·elasticsearch
字节跳动数据平台1 天前
代码量减少 70%、GPU 利用率达 95%:火山引擎多模态数据湖如何释放模思智能的算法生产力
大数据
得物技术1 天前
深入剖析Spark UI界面:参数与界面详解|得物技术
大数据·后端·spark
武子康1 天前
大数据-238 离线数仓 - 广告业务 Hive分析实战:ADS 点击率、购买率与 Top100 排名避坑
大数据·后端·apache hive
武子康2 天前
大数据-237 离线数仓 - Hive 广告业务实战:ODS→DWD 事件解析、广告明细与转化分析落地
大数据·后端·apache hive
大大大大晴天2 天前
Flink生产问题排障-Kryo serializer scala extensions are not available
大数据·flink
Elasticsearch3 天前
如何使用 Agent Builder 排查 Kubernetes Pod 重启和 OOMKilled 事件
elasticsearch