summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatt Mower <mowerm@gmail.com>2014-10-31 21:02:37 -0500
committerAdnan Begovic <adnan@cyngn.com>2015-10-06 17:57:46 -0700
commitee84e3f2dd7487137428bafdb1c2519e364aca5f (patch)
treeef20b1520ccdafb30bf42f8133371723f62a0315
parent84be297191b44d4bf411284da1e1804626849435 (diff)
downloadbuild-ee84e3f2dd7487137428bafdb1c2519e364aca5f.zip
build-ee84e3f2dd7487137428bafdb1c2519e364aca5f.tar.gz
build-ee84e3f2dd7487137428bafdb1c2519e364aca5f.tar.bz2
roomservice: Improve new device retrieval
Without credentials, GitHub's search API limits requests to 60/hr. The existing method to add a new device is to fetch JSON-formatted info for ALL CM repositories and then search for the device. In doing so, more than 10 pages of results are returned (i.e. more than 10 requests per device). This is clumsy, slow, and limits use of roomservice to only ~5 devices per hour. Instead, only return search results for repositories that have the device name in the repository name. Then, one device = one request. It's faster and allows closer to 60 device setups / hr. Additional bailouts are included to stop the script earlier than later if a device is not found. Change-Id: I7f914d7ede82da0f100d9fd6cf8b603177962e48
-rwxr-xr-xtools/roomservice.py20
1 files changed, 12 insertions, 8 deletions
diff --git a/tools/roomservice.py b/tools/roomservice.py
index f5aac06..86f75c3 100755
--- a/tools/roomservice.py
+++ b/tools/roomservice.py
@@ -52,16 +52,20 @@ def add_auth(githubreq):
if githubauth:
githubreq.add_header("Authorization","Basic %s" % githubauth)
-page = 1
-while not depsonly:
- githubreq = urllib2.Request("https://api.github.com/users/CyanogenMod/repos?per_page=200&page=%d" % page)
+if not depsonly:
+ githubreq = urllib.request.Request("https://api.github.com/search/repositories?q=%s+user:CyanogenMod+in:name" % device)
add_auth(githubreq)
- result = json.loads(urllib2.urlopen(githubreq).read())
- if len(result) == 0:
- break
- for res in result:
+ result = json.loads(urllib.request.urlopen(githubreq).read().decode())
+ try:
+ numresults = int(result['total_count'])
+ except:
+ print("Failed to search GitHub (offline?)")
+ sys.exit()
+ if (numresults == 0):
+ print("Could not find device %s on github.com/CyanogenMod" % device)
+ sys.exit()
+ for res in result['items']:
repositories.append(res)
- page = page + 1
local_manifests = r'.repo/local_manifests'
if not os.path.exists(local_manifests): os.makedirs(local_manifests)