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. 設(shè)置 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)

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容