美文网首页
Android 源码拉取脚本

Android 源码拉取脚本

作者: 良人_Coder | 来源:发表于2019-10-12 18:04 被阅读0次
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)

相关文章

网友评论

      本文标题:Android 源码拉取脚本

      本文链接:https://www.haomeiwen.com/subject/xbhcmctx.html