blob: 61f8555c9dcbeaf116345307ab5aaaae8cb83b41 [file] [log] [blame]
Koushik Dutta780fb5f2011-11-26 18:51:42 -08001#!/usr/bin/env python
2import os
3import sys
4import urllib2
5import json
6from xml.etree import ElementTree
7
8product = sys.argv[1];
9device = product[product.index("_") + 1:]
10print "Device %s not found. Attempting to retrieve device repository from CyanogenMod Github (http://github.com/CyanogenMod)." % device
11
12repositories = []
13
14page = 1
15while 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
22for 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
55print "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