Advertisement
Guest User

Untitled

a guest
Jan 22nd, 2018
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.88 KB | None | 0 0
  1. #!/usr/bin/env python
  2.  
  3. # Github repo local_manifest builder
  4.  
  5. # Creates a local_manifest.xml which points all available projects at the github
  6. # mirrors. The names are adjusted to match, and any projects not available on
  7. # github.com/android are marked as 'remove' so repo will skip them.
  8.  
  9. import string;
  10. from xml.etree.ElementTree import ElementTree, Element
  11. import httplib
  12. from xml.dom import minidom
  13.  
  14. def to_github_name(s):
  15. s = s.lower()
  16. s = string.replace(s, '/', '_')
  17. return s
  18.  
  19. def verify_github_project(name):
  20. github = httplib.HTTPSConnection("github.com", timeout=5)
  21. github.request("HEAD", "/android/%s" % name, None, {'Connection': 'close'})
  22. res = github.getresponse()
  23. return res.status != httplib.NOT_FOUND
  24.  
  25. def prettify(name):
  26. dom = minidom.parse(name)
  27. f = open(name, "w")
  28. f.write(dom.toprettyxml(indent=" "))
  29. f.close()
  30.  
  31. local_manifest = Element('manifest')
  32. new_tree = ElementTree(local_manifest)
  33.  
  34. tree = ElementTree()
  35. tree.parse(".repo/manifest.xml")
  36. manifest = tree.getroot()
  37.  
  38. print "Generating .repo/local_manifest.xml for GitHub"
  39.  
  40. # add a remote for github
  41. remote = Element('remote')
  42. remote.attrib["name"] = "github"
  43. remote.attrib["fetch"] = "git://github.com/android"
  44. local_manifest.append(remote)
  45.  
  46. for project in tree.getroot().findall("project"):
  47. # mark the original with a project-remove entry
  48. korg_name = project.attrib["name"]
  49. remove = Element('remove-project')
  50. remove.attrib["name"] = korg_name
  51. local_manifest.append(remove)
  52.  
  53. # only include if github has the project mirrored
  54. gh_name = to_github_name(korg_name)
  55. if verify_github_project(gh_name):
  56. print gh_name
  57. gh_project = Element('project')
  58. gh_project.attrib["name"] = gh_name
  59. gh_project.attrib["path"] = project.attrib["path"]
  60. gh_project.attrib["remote"] = "github"
  61. local_manifest.append(gh_project)
  62.  
  63. new_tree.write(".repo/local_manifest.xml")
  64. prettify(".repo/local_manifest.xml")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement