Skip to content

Commit

Permalink
roomservice: Improve new device retrieval
Browse files Browse the repository at this point in the history
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
  • Loading branch information
mdmower authored and Flinny committed Sep 8, 2016
1 parent 8cf5140 commit eb2694a
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions tools/roomservice.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,20 @@ def add_auth(githubreq):
if githubauth:
githubreq.add_header("Authorization","Basic %s" % githubauth)

page = 1
while not depsonly:
githubreq = urllib.request.Request("https://api.github.com/users/SlimRoms/repos?per_page=200&page=%d" % page)
if not depsonly:
githubreq = urllib.request.Request("https://api.github.com/search/repositories?q=%s+user:SlimRoms+in:name" % device)
add_auth(githubreq)
result = json.loads(urllib.request.urlopen(githubreq).read().decode())
if len(result) == 0:
break
for res in result:
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)
Expand Down

0 comments on commit eb2694a

Please sign in to comment.