Created
July 17, 2012 01:18
-
-
Save suapapa/3126307 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import os, sys | |
import subprocess | |
import StringIO | |
import xml.dom.minidom | |
def getTop(): | |
for v in ('TOP', 'ANDROID_BUILD_TOP'): | |
if v in os.environ: | |
return os.getenv(v) | |
if os.access('.repo/manifest.xml', os.R_OK): | |
return os.getcwd() | |
def getOutput(command): | |
output = subprocess.Popen(command, stdout=subprocess.PIPE).communicate()[0] | |
return StringIO.StringIO(output) | |
def gitSync(path): | |
os.chdir(path) | |
if os.system('git pull'): | |
sys.exit(-1) | |
def getPaths(manifest): | |
root = xml.dom.minidom.parse(manifest) | |
path = set() | |
for node in root.childNodes[0].childNodes: | |
if node.nodeName != 'project': | |
continue | |
name = node.getAttribute('name') | |
path.add(name) | |
return path | |
def buildLocalManifest(manifestDir, repoDir): | |
os.chdir(manifestDir) | |
path = set() | |
for line in getOutput(('git', 'branch', '-a')): | |
branch = line.strip() | |
if not branch.startswith('remotes/origin'): | |
continue | |
if branch == 'remotes/origin/master': | |
continue | |
manifest = getOutput(('git', 'show', '%s:default.xml'%branch)) | |
path.update(getPaths(manifest)) | |
manifest = getOutput(('git', 'show', 'default:default.xml')) | |
defaultPath = getPaths(manifest) | |
doc = xml.dom.minidom.Document() | |
root = doc.createElement('manifest') | |
doc.appendChild(root) | |
for path in path - defaultPath: | |
e = doc.createElement('project') | |
root.appendChild(e) | |
e.setAttribute('name', path) | |
e.setAttribute('path', path) | |
doc.writexml(open(os.path.join(repoDir, 'local_manifest.xml'), 'w'), "", " ", "\n") | |
if __name__ == '__main__': | |
if len(sys.argv) == 1: | |
top = getTop() | |
elif sys.argv[1]: | |
top = sys.argv[1] | |
repoDir = os.path.join(top, '.repo') | |
manifestDir = os.path.join(repoDir, 'manifests') | |
gitSync(manifestDir) | |
buildLocalManifest(manifestDir, repoDir) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment