仓库同步脚本

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")
相关推荐
wdfk_prog2 小时前
实战教程:从“对象文件为空“到仓库重生——修复 Git 仓库损坏全记录
大数据·网络·笔记·git·学习·elasticsearch·全文检索
杨荧2 小时前
基于大数据的美食视频播放数据可视化系统 Python+Django+Vue.js
大数据·前端·javascript·vue.js·spring boot·后端·python
Hello.Reader3 小时前
以 Eland 玩转 Elasticsearch 8.12 Learning-to-Rank
大数据·elasticsearch·jenkins
ALex_zry3 小时前
Git Status 命令深度指南:洞悉仓库状态的核心艺术
大数据·git·elasticsearch
ζั͡山 ั͡有扶苏 ั͡✾3 小时前
Elasticsearch 单节点迁移实战指南:从旧服务器到新环境的完整流程
服务器·elasticsearch·jenkins
weixin_425878235 小时前
AWS 可靠性工程深度实践: 从 Well-Architected 到“零失误”VPC 落地
大数据·云计算·aws
九河云5 小时前
华为云代理商的作用与价值解析
大数据·人工智能·华为云
SelectDB5 小时前
天翼云与飞轮科技达成战略合作,共筑云数融合新生态
大数据·数据库·数据分析
Sunhen_Qiletian6 小时前
机器学习实战:逻辑回归深度解析与欺诈检测评估指标详解(二)
大数据
Flink_China7 小时前
Flink 2.1 SQL:解锁实时数据与AI集成,实现可扩展流处理
大数据·flink