Koushik Dutta | 780fb5f | 2011-11-26 18:51:42 -0800 | [diff] [blame^] | 1 | #!/usr/bin/env python |
| 2 | import os |
| 3 | import sys |
| 4 | import urllib2 |
| 5 | import json |
| 6 | from xml.etree import ElementTree |
| 7 | |
| 8 | product = sys.argv[1]; |
| 9 | device = product[product.index("_") + 1:] |
| 10 | print "Device %s not found. Attempting to retrieve device repository from CyanogenMod Github (http://github.com/CyanogenMod)." % device |
| 11 | |
| 12 | repositories = [] |
| 13 | |
| 14 | page = 1 |
| 15 | while True: |
| 16 | result = json.loads(urllib2.urlopen("http://github.com/api/v2/json/repos/show/CyanogenMod?page=%d" % page).read()) |
| 17 | if len(result['repositories']) == 0: |
| 18 | break |
| 19 | repositories = repositories + result['repositories'] |
| 20 | page = page + 1 |
| 21 | |
| 22 | for repository in repositories: |
| 23 | repo_name = repository['name'] |
| 24 | if repo_name.startswith("android_device_") and repo_name.endswith("_" + device): |
| 25 | print "Found repository: %s" % repository['name'] |
| 26 | manufacturer = repo_name.replace("android_device_", "").replace("_" + device, "") |
| 27 | |
| 28 | try: |
| 29 | lm = ElementTree.parse(".repo/local_manifest.xml") |
| 30 | lm = lm.getroot() |
| 31 | except: |
| 32 | lm = ElementTree.Element("manifest") |
| 33 | |
| 34 | for child in lm.getchildren(): |
| 35 | if child.attrib['name'].endswith("_" + device): |
| 36 | print "Duplicate device '%s' found in local_manifest.xml." % child.attrib['name'] |
| 37 | sys.exit() |
| 38 | |
| 39 | repo_path = "device/%s/%s" % (manufacturer, device) |
| 40 | project = ElementTree.Element("project", attrib = { "path": repo_path, "remote": "github", "name": "CyanogenMod/%s" % repository['name'] }) |
| 41 | lm.append(project) |
| 42 | |
| 43 | raw_xml = ElementTree.tostring(lm) |
| 44 | raw_xml = '<?xml version="1.0" encoding="UTF-8"?>\n' + raw_xml |
| 45 | |
| 46 | f = open('.repo/local_manifest.xml', 'w') |
| 47 | f.write(raw_xml) |
| 48 | f.close() |
| 49 | |
| 50 | print "Syncing repository to retrieve project." |
| 51 | os.system('repo sync %s' % repo_path) |
| 52 | print "Done!" |
| 53 | sys.exit() |
| 54 | |
| 55 | print "Repository for %s not found in the CyanogenMod Github repository list. If this is in error, you may need to manually add it to your local_manifest.xml." % device |