Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Unified Diff: sitescripts/extensions/bin/createNightlies.py

Issue 6282207912001536: Issue 356 - Fixed URL for publishing an item on the Chrome Web Store (Closed)
Patch Set: Addressed comments Created May 6, 2014, 7:44 a.m.
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: sitescripts/extensions/bin/createNightlies.py
===================================================================
--- a/sitescripts/extensions/bin/createNightlies.py
+++ b/sitescripts/extensions/bin/createNightlies.py
@@ -376,10 +376,19 @@
shutil.rmtree(docsdir, ignore_errors=True)
def uploadToChromeWebStore(self):
+ # Google APIs use HTTP error codes with error message in body. So we add
+ # the response body to the HTTPError to get more meaningful error messages.
+
+ class HTTPErrorBodyHandler(urllib2.HTTPDefaultErrorHandler):
+ def http_error_default(self, req, fp, code, msg, hdrs):
+ raise urllib2.HTTPError(req.get_full_url(), code, '%s\n%s' % (msg, fp.read()), hdrs, fp)
+
+ opener = urllib2.build_opener(HTTPErrorHandler)
+
# use refresh token to obtain a valid access token
# https://developers.google.com/accounts/docs/OAuth2WebServer#refresh
- response = json.load(urllib2.urlopen(
+ response = json.load(opener.open(
'https://accounts.google.com/o/oauth2/token',
urlencode([
@@ -410,7 +419,7 @@
request.add_header('Content-Length', os.fstat(file.fileno()).st_size - file.tell())
request.add_data(file)
- response = json.load(urllib2.urlopen(request))
+ response = json.load(opener.open(request))
if response['uploadState'] == 'FAILURE':
raise Exception(response['itemError'])
@@ -418,15 +427,15 @@
# publish the new version on the Chrome Web Store
# https://developer.chrome.com/webstore/using_webstore_api#publishpublic
- request = urllib2.Request('https://www.googleapis.com/upload/chromewebstore/v1.1/items/%s/publish' % self.config.devbuildGalleryID)
+ request = urllib2.Request('https://www.googleapis.com/chromewebstore/v1.1/items/%s/publish' % self.config.devbuildGalleryID)
request.get_method = lambda: 'POST'
request.add_header('Authorization', auth_token)
request.add_header('x-goog-api-version', '2')
request.add_header('Content-Length', '0')
- response = json.load(urllib2.urlopen(request))
+ response = json.load(opener.open(request))
- if any(status != 'ITEM_PENDING_REVIEW' for status in response['status']):
+ if any(status not in ('OK', 'ITEM_PENDING_REVIEW') for status in response['status']):
raise Exception(response['statusDetail'])
Wladimir Palant 2014/05/06 08:05:48 I don't know where you got the status code OK from
Sebastian Noack 2014/05/06 08:18:50 Done.
def run(self):
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld