android 4.0.3源码python3下载脚本

和许多人的思路一样。我也是通过解析platform/mainfest/default.xml,然后通过组合git命令,来实现安卓源码的。

我只是个python的初学者。花一个晚上,边查边写边测。终于是写了这一小段代码。

今天挂机下载测试,情况OK。可能是因为我是翻墙下载的缘故,下的很顺畅,基本没有发现链接挂起的问题。

脚本写的很简单,用beautiful soup来解析下载下来的xml,用着觉得挺方便。

'''
Created on Jul 30, 2013


@author: turbinyan
'''


import os
from bs4 import BeautifulSoup


git_cmd_prefix = "git clone https://android.googlesource.com/"
g_SrcPath  = './'+'android-4.0.4_r1.1/'
g_filePath = g_SrcPath+"mainfest.xml"


def downloadMainfest(version):
    path = "./"+version
    if not os.path.exists(path):
        os.mkdir(path)


    g_filePath = path+"/mainfest.xml"
    cmd = "curl https://android.googlesource.com/platform/manifest/+/"+version+"/default.xml >>"+g_filePath
    os.system(cmd)
    print("cmd:"+cmd+"excution well!")


def paseDownloadList(xml):
    downloadList = set()
    xmlSoup = BeautifulSoup(xml, 'xml')
    for link in xmlSoup.find_all('project'):
        downloadList.add(link.get('name'))
        
    return downloadList
    
    
def getContent():
        print("path "+g_filePath)
        with open(g_filePath,'rt') as fXmlData:
            xmlSoup = BeautifulSoup(fXmlData, 'xml')
            try: 
                return str(xmlSoup.pre.get_text())
            except:
                print("xml find all error")


def download(a_list):
    print('download list'+str(a_list))
    for path in a_list:
        try:
            cmd = git_cmd_prefix+path +' '+ g_SrcPath+path
            print('exec cmd: '+cmd)
            os.system(cmd)
        except:
            print("download "+path+" is error!")
    
if __name__ == '__main__':
    print("main looper run")
    downloadList = paseDownloadList(getContent())
    download(downloadList)
    print('well done! finished!')

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值