Android 源码拉取脚本

import xml.dom.minidom
import os
from subprocess import call

"""
git clone https://aosp.tuna.tsinghua.edu.cn/platform/manifest.git
克隆manifest.git仓库,可以git branch -a 查看所有Android源码的分支。
git checkout 切换到自己想要下载的对应源码分支。
这时可以看到manifest/default.xml该文件里面就有对应的project name,这些都是仓库名,利用python脚本来组件git clone 仓库命令。
"""

# 1. 修改为源码要保存的路径
rootdir = "E:/Android_Source"

# 2. 设置 git 安装的路径
git = "C:/Users/asus/AppData/Local/GitHub/PortableGit_d76a6a98c9315931ec4927243517bc09e9b731a0/mingw32/libexec/git-core/git.exe"

# 3. 修改为第一步中 manifest 中 default.xml 保存的路径
dom = xml.dom.minidom.parse("E:/Android_Source/manifest/default.xml")
root = dom.documentElement

#prefix = git + " clone https://android.googlesource.com/"
# 4. 没有梯子使用清华源下载
prefix = git + " clone https://aosp.tuna.tsinghua.edu.cn/"
suffix = ".git"  
if not os.path.exists(rootdir):  
    os.mkdir(rootdir)  

for node in root.getElementsByTagName("project"):  
    os.chdir(rootdir)  
    d = node.getAttribute("path")  
    last = d.rfind("/")  
    if last != -1:  
        d = rootdir + "/" + d[:last]  
        if not os.path.exists(d):  
            os.makedirs(d)  
        os.chdir(d)  
    cmd = prefix + node.getAttribute("name") + suffix  
    call(cmd)

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容