批量创建Android源码的本地仓库

本文指导如何批量创建Android源码的本地仓库。首先,你需要修改manifest.xml文件,在.repo目录中进行设置。接着,准备仓库,将源代码复制到指定路径并运行相应命令以初始化。最后,通过运行app.py源代码,可以开始拉取你的代码。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

批量创建Android源码仓库

修改manifest.xml文件

manifest.xml文件在源代码的.repo目录中

<manifest>
  <remote fetch="ssh://localhost/mnt/GitRepository/ANDROID7.1" name="ssh" review="remote"/>
  <remote fetch="/mnt/GitRepository/ANDROID7.1" name="local" review="local"/>
  
  <default remote="local" revision="master" sync-j="8" />
  
</manifest>

此处添加了两个仓库员,默认使用第二个仓库源,可以参考这里

准备仓库

将源代码复制到/mnt/GitRepository/ANDROID7.1中,并运行python3 app.py --xml_path 你修改后xml文件地址 --repo_path /mnt/GitRepository/ANDROID7.1
此时你的源代码仓库已经建立好,运行命令

repo init -u /mnt/GitRepository/ANDROID7.1/platform/manifest.git/

repo sync

就可以下拉你的代码

app.py源代码

#!/usr/bin/python3
# -*- coding: UTF-8 -*-
import os
import argparse
import xml.etree.ElementTree as ET

parser = argparse.ArgumentParser()
parser.add_argument("--xml_path", help="the path of the xml file", default="manifest.xml")
parser.add_argument("--repo_path", help="the path of the repo folder", default="project")
parser.add_argument("-j","--thread", help="the count of git thread, the default is 8", default=8, type=int)
args = parser.parse_args()
xml_path = args.xml_path
repo_path = args.repo_path
thread_count = args.thread


def _init_repo(sub_repo_path):
    os.chdir(sub_repo_path) # 切换工作目录
    print("==>git init " + os.getcwd())
    if not os.path.exists(".gitignore"): # 需要存在文件才能提交
        os.system("touch .gitignore")
    if os.path.exists(".git"):
        os.system("rm -rf .git")
    if 0 != os.system("git init"):
        print("Error(init):%s" % sub_repo_path)
        return False
    if 0 != os.system("git add ."):
        print("Error(add):%s" % sub_repo_path)
        return False
    if 0 != os.system("git commit -m \"init repo\""):
        print("Error(commit):%s" % sub_repo_path)
        return False
    return True


if __name__ == '__main__':
    tree = ET.parse(xml_path)
    root = tree.getroot()
    for child in root:
        if child.tag == "default":
            child.attrib["sync-j"] = str(thread_count)
        elif child.tag == "project":
            if "remote" in child.attrib.keys():
                child.attrib.pop("remote")
            if "revision" in child.attrib.keys():
                child.attrib.pop("revision")
            if "upstream" in child.attrib.keys():
                child.attrib.pop("upstream")
            if not _init_repo(repo_path + "/" + child.attrib["path"]):
                break
    if not os.path.exists(repo_path + "/platform/manifest.git"):
        os.makedirs(repo_path + "/platform/manifest.git")
    if os.path.exists(repo_path + "/platform/manifest.git/default.xml"):
        os.remove(repo_path + "/platform/manifest.git/default.xml")
    tree.write(repo_path + "/platform/manifest.git/default.xml", encoding="utf-8", xml_declaration=True)
    _init_repo(repo_path + "/platform/manifest.git")
    

# repo init -u git@localhost:$repo_path/platform/manifest.git/

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值