在window系统下,下载多个GitLab模块指定tag代码并放在相应的模块加上tag号的文件夹内

下面是一个在Windows系统下下载两个模块为例,可以适配到自己的项目中

import subprocess
import os

# 配置模块信息:模块名称、仓库地址和指定标签
modules = [
    {
        "name": "ArbitrationManager",  # 模块名称
        "repo_url": r"https://git.ecarxgroup.com/jica/adcu/asw/asw_pilot_mcu/ArbitrationManager.git",  # 替换为你的GitLab模块1仓库地址
        "tag_name": "AM_V8-4-1_R_V1.00"  # 替换为模块1要下载的tag
    },
    {
        "name": "AnotherModule",  # 替换为你的模块名称
        "repo_url": r"https://git.ecarxgroup.com/jica/adcu/asw/asw_pilot_mcu/AnotherModule.git",  # 替换为你的GitLab模块2仓库地址
        "tag_name": "TAG_V1.0"  # 替换为模块2要下载的tag
    },
    # 可以继续添加更多模块
]

for module in modules:
    module_name = module['name']
    repo_url = module['repo_url']
    tag_name = module['tag_name']
    clone_dir = os.path.join(os.getcwd(), f"{module_name}_{tag_name}")  # 使用模块名称和tag作为文件夹名

    # 检查克隆目录是否已存在,若存在则删除
    if os.path.exists(clone_dir):
        subprocess.run(["rmdir", "/s", "/q", clone_dir], shell=True)

    # 执行git clone命令
    try:
        subprocess.run(["git", "clone", "--branch", tag_name, repo_url, clone_dir], check=True)
        print(f"{module_name} 下载成功,代码已保存到 {clone_dir} 文件夹中。")
    except subprocess.CalledProcessError:
        print(f"{module_name} 下载失败,请检查仓库地址和tag名。")

使用说明:

  1. 将上述代码复制到一个新的文本文件中,并保存为 download_multiple_gitlab_modules.py
  2. 在 modules 列表中配置你的GitLab模块信息。每个模块包括模块名称、仓库地址和要下载的tag。可以根据需要添加或修改模块。
  3. 运行该Python脚本,脚本将自动下载每个模块的代码到以模块名称和tag命名的文件夹中。

注意:

  • 确保你的计算机已安装Python,并且已安装Git,且Git的命令行工具已添加到系统的PATH环境变量中,以便在Python中使用git命令。
  • 在执行此脚本时,请确保你有必要的权限和网络连接,能够访问所提供的GitLab仓库。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值