Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- # Github repo local_manifest builder
- # Creates a local_manifest.xml which points all available projects at the github
- # mirrors. The names are adjusted to match, and any projects not available on
- # github.com/android are marked as 'remove' so repo will skip them.
- import string;
- from xml.etree.ElementTree import ElementTree, Element
- import httplib
- from xml.dom import minidom
- def to_github_name(s):
- s = s.lower()
- s = string.replace(s, '/', '_')
- return s
- def verify_github_project(name):
- github = httplib.HTTPSConnection("github.com", timeout=5)
- github.request("HEAD", "/android/%s" % name, None, {'Connection': 'close'})
- res = github.getresponse()
- return res.status != httplib.NOT_FOUND
- def prettify(name):
- dom = minidom.parse(name)
- f = open(name, "w")
- f.write(dom.toprettyxml(indent=" "))
- f.close()
- local_manifest = Element('manifest')
- new_tree = ElementTree(local_manifest)
- tree = ElementTree()
- tree.parse(".repo/manifest.xml")
- manifest = tree.getroot()
- print "Generating .repo/local_manifest.xml for GitHub"
- # add a remote for github
- remote = Element('remote')
- remote.attrib["name"] = "github"
- remote.attrib["fetch"] = "git://github.com/android"
- local_manifest.append(remote)
- for project in tree.getroot().findall("project"):
- # mark the original with a project-remove entry
- korg_name = project.attrib["name"]
- remove = Element('remove-project')
- remove.attrib["name"] = korg_name
- local_manifest.append(remove)
- # only include if github has the project mirrored
- gh_name = to_github_name(korg_name)
- if verify_github_project(gh_name):
- print gh_name
- gh_project = Element('project')
- gh_project.attrib["name"] = gh_name
- gh_project.attrib["path"] = project.attrib["path"]
- gh_project.attrib["remote"] = "github"
- local_manifest.append(gh_project)
- new_tree.write(".repo/local_manifest.xml")
- prettify(".repo/local_manifest.xml")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement