〖Android〗代理与正常网络分开同步CyangenMod源码

为了同步CyanogenMod源代码,你也学会了FQ,对吗?

通常 .repo/manifest.xml 文件有Google AOSP的Project,也有Github的Project;

访问Github不需要FQ,而同步Google源代码则避免不了了;

想分开同步,想智能一点吗?

#!/usr/bin/env python
# encoding: utf-8

import os,sys,subprocess
import xml.dom.minidom
from xml.dom.minidom import Node

# 代理环境
proxy_user=‘‘
proxy_pass=‘‘
proxy_host=123.123.123.123 # 请更换此IP地址
proxy_port=12345 #请更换此端口
if len(proxy_user) == 0:
    proxy_env="http_proxy=http://%s:%d" %(proxy_host, proxy_port)
else:
    proxy_env="http_proxy=http://%s:%s@%s:%d" %(proxy_user, proxy_pass, proxy_host, proxy_port)

# 解析.repo/manifest.xml文件,取出project节点
doc = xml.dom.minidom.parse(.repo/manifest.xml)
projects = doc.getElementsByTagName(project)

github_projects=[]
google_projects=[]

errorsync_projects=[]

# 执行同步
def sync_project(cmd):
    """
    执行同步命令
    cmd: 同步使用的命令,如: repo sync <project_name>
    return: 执行返回值
    """
    print >>>, sync_cmd
    process = subprocess.Popen(sync_cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
    out = process.stdout.readline()
    while out:
        print out,
        out = process.stdout.readline()
    err = process.stderr.readline()
    while err:
        print err,
        err = process.stderr.readline()
    process.poll()
    errcode = process.returncode
    return errcode

# 对project进行分类
# AOSP的Project保存在 google_projects 数组
# CyanogenMod的Project保存在 github_project 数组
for node in projects:
    remote=node.getAttribute(remote)
    project=node.getAttribute(name)
    if remote == aosp:
        google_projects.append(project)
    else:
        github_projects.append(project)

# 同步来自Google的Project
for project in google_projects:
    sync_cmd="env %s repo sync %s" %(proxy_env, project)
    ret = sync_project(sync_cmd)
    if ret != 0:
        errorsync_projects.append(project)
    sys.exit()

# 同步来自Github的Project
for project in github_projects:
    sync_cmd="repo sync %s" %project
    ret = sync_project(sync_cmd)
    if ret != 0:
        errorsync_projects.append(project)

# 输出同步出错的Project
if len(errorsync_projects) != 0:
    print >>> 同步出现了错误的Project: 
    for project in errorsync_projects:
        print project

    print >>> 请执行命令以重新同步Project: 
    for project in errorsync_projects:
        if project in google_projects:
            sync_cmd="env %s repo sync %s" %(proxy_env, project)
        else:
            sync_cmd="repo sync %s" %project
        print sync_cmd

保存脚本到 sync_split.py,同步的时候执行:

  cd /path/to/src

  python sync_split.py

Enjoy!

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。