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

Side by Side 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.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 # coding: utf-8 1 # coding: utf-8
2 2
3 # This file is part of the Adblock Plus web scripts, 3 # This file is part of the Adblock Plus web scripts,
4 # Copyright (C) 2006-2014 Eyeo GmbH 4 # Copyright (C) 2006-2014 Eyeo GmbH
5 # 5 #
6 # Adblock Plus is free software: you can redistribute it and/or modify 6 # Adblock Plus is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License version 3 as 7 # it under the terms of the GNU General Public License version 3 as
8 # published by the Free Software Foundation. 8 # published by the Free Software Foundation.
9 # 9 #
10 # Adblock Plus is distributed in the hope that it will be useful, 10 # Adblock Plus is distributed in the hope that it will be useful,
(...skipping 358 matching lines...) Expand 10 before | Expand all | Expand 10 after
369 subprocess.check_call(command) 369 subprocess.check_call(command)
370 370
371 try: 371 try:
372 import buildtools.build as build 372 import buildtools.build as build
373 outputPath = os.path.join(self.config.docsDirectory, self.basename) 373 outputPath = os.path.join(self.config.docsDirectory, self.basename)
374 build.generateDocs(self.tempdir, None, [("-t", docsdir), ("-q", "")], [out putPath], self.config.type) 374 build.generateDocs(self.tempdir, None, [("-t", docsdir), ("-q", "")], [out putPath], self.config.type)
375 finally: 375 finally:
376 shutil.rmtree(docsdir, ignore_errors=True) 376 shutil.rmtree(docsdir, ignore_errors=True)
377 377
378 def uploadToChromeWebStore(self): 378 def uploadToChromeWebStore(self):
379 # Google APIs use HTTP error codes with error message in body. So we add
380 # the response body to the HTTPError to get more meaningful error messages.
381
382 class HTTPErrorBodyHandler(urllib2.HTTPDefaultErrorHandler):
383 def http_error_default(self, req, fp, code, msg, hdrs):
384 raise urllib2.HTTPError(req.get_full_url(), code, '%s\n%s' % (msg, fp.re ad()), hdrs, fp)
385
386 opener = urllib2.build_opener(HTTPErrorHandler)
387
379 # use refresh token to obtain a valid access token 388 # use refresh token to obtain a valid access token
380 # https://developers.google.com/accounts/docs/OAuth2WebServer#refresh 389 # https://developers.google.com/accounts/docs/OAuth2WebServer#refresh
381 390
382 response = json.load(urllib2.urlopen( 391 response = json.load(opener.open(
383 'https://accounts.google.com/o/oauth2/token', 392 'https://accounts.google.com/o/oauth2/token',
384 393
385 urlencode([ 394 urlencode([
386 ('refresh_token', self.config.refreshToken), 395 ('refresh_token', self.config.refreshToken),
387 ('client_id', self.config.clientID), 396 ('client_id', self.config.clientID),
388 ('client_secret', self.config.clientSecret), 397 ('client_secret', self.config.clientSecret),
389 ('grant_type', 'refresh_token'), 398 ('grant_type', 'refresh_token'),
390 ]) 399 ])
391 )) 400 ))
392 401
(...skipping 10 matching lines...) Expand all
403 with open(self.path, 'rb') as file: 412 with open(self.path, 'rb') as file:
404 if file.read(8) != 'Cr24\x02\x00\x00\x00': 413 if file.read(8) != 'Cr24\x02\x00\x00\x00':
405 raise Exception('not a chrome extension or unknown CRX version') 414 raise Exception('not a chrome extension or unknown CRX version')
406 415
407 # skip public key and signature 416 # skip public key and signature
408 file.seek(sum(struct.unpack('<II', file.read(8))), os.SEEK_CUR) 417 file.seek(sum(struct.unpack('<II', file.read(8))), os.SEEK_CUR)
409 418
410 request.add_header('Content-Length', os.fstat(file.fileno()).st_size - fil e.tell()) 419 request.add_header('Content-Length', os.fstat(file.fileno()).st_size - fil e.tell())
411 request.add_data(file) 420 request.add_data(file)
412 421
413 response = json.load(urllib2.urlopen(request)) 422 response = json.load(opener.open(request))
414 423
415 if response['uploadState'] == 'FAILURE': 424 if response['uploadState'] == 'FAILURE':
416 raise Exception(response['itemError']) 425 raise Exception(response['itemError'])
417 426
418 # publish the new version on the Chrome Web Store 427 # publish the new version on the Chrome Web Store
419 # https://developer.chrome.com/webstore/using_webstore_api#publishpublic 428 # https://developer.chrome.com/webstore/using_webstore_api#publishpublic
420 429
421 request = urllib2.Request('https://www.googleapis.com/upload/chromewebstore/ v1.1/items/%s/publish' % self.config.devbuildGalleryID) 430 request = urllib2.Request('https://www.googleapis.com/chromewebstore/v1.1/it ems/%s/publish' % self.config.devbuildGalleryID)
422 request.get_method = lambda: 'POST' 431 request.get_method = lambda: 'POST'
423 request.add_header('Authorization', auth_token) 432 request.add_header('Authorization', auth_token)
424 request.add_header('x-goog-api-version', '2') 433 request.add_header('x-goog-api-version', '2')
425 request.add_header('Content-Length', '0') 434 request.add_header('Content-Length', '0')
426 435
427 response = json.load(urllib2.urlopen(request)) 436 response = json.load(opener.open(request))
428 437
429 if any(status != 'ITEM_PENDING_REVIEW' for status in response['status']): 438 if any(status not in ('OK', 'ITEM_PENDING_REVIEW') for status in response['s tatus']):
430 raise Exception(response['statusDetail']) 439 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.
431 440
432 def run(self): 441 def run(self):
433 """ 442 """
434 Run the nightly build process for one extension 443 Run the nightly build process for one extension
435 """ 444 """
436 try: 445 try:
437 if self.config.type == 'ie': 446 if self.config.type == 'ie':
438 # We cannot build IE builds, simply list the builds already in 447 # We cannot build IE builds, simply list the builds already in
439 # the directory. Basename has to be deduced from the repository name. 448 # the directory. Basename has to be deduced from the repository name.
440 self.basename = os.path.basename(self.config.repository) 449 self.basename = os.path.basename(self.config.repository)
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
507 except Exception, ex: 516 except Exception, ex:
508 print >>sys.stderr, "The build for %s failed:" % repo 517 print >>sys.stderr, "The build for %s failed:" % repo
509 traceback.print_exc() 518 traceback.print_exc()
510 519
511 file = open(nightlyConfigFile, 'wb') 520 file = open(nightlyConfigFile, 'wb')
512 nightlyConfig.write(file) 521 nightlyConfig.write(file)
513 522
514 523
515 if __name__ == '__main__': 524 if __name__ == '__main__':
516 main() 525 main()
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld