Python下载Android源码

2018-05-09  本文已影响0人  Spirituality韬

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 仓库命令。

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

# 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)
上一篇 下一篇

猜你喜欢

热点阅读