仓库同步脚本

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")
相关推荐
Elasticsearch10 小时前
AI 购物 agent:为什么上下文比查询更重要
elasticsearch
乐观的Terry10 小时前
5、发布系统-Git 集成
大数据·git·elasticsearch
真上帝的左手10 小时前
19. 大数据-概念
大数据·big data
法雅特吉他11 小时前
吉他日常保养完全指南:从环境参数到部位养护的系统化方案
大数据·经验分享·新媒体运营·学习方法·材质
xiancai_xianyu11 小时前
企业本体语义:设备保养与供应商评估,为什么需要统一的语义模型?
大数据·人工智能
shujudang11 小时前
企业级 APP 数据分析平台选型指南:业务评估与落地路径
大数据·数据挖掘·数据分析·移动开发
laboratory agent开发11 小时前
AI agent多知识源并存时,一致性为何总出偏差
大数据·人工智能
liuxiaowei311 小时前
Winform+WPF双框架实战:喷涂工艺SCADA上位机从0到1搭建(附采集监控源码+车间踩坑实录)
大数据·hadoop·wpf
黄焖鸡能干四碗11 小时前
IT数据架构规划设计方案(PPT文件)
大数据·网络·数据库·人工智能·架构·区块链
无忧.芙桃11 小时前
Kobbe 智能应用场景落地指南
大数据·人工智能