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

Delta Between Two Patch Sets: sitescripts/extensions/utils.py

Issue 29374637: Issue 4549 - Implement the Windows Store API to upload development builds (Closed)
Left Patch Set: Update buildtools. Remove submission update logic. Always close requests. Created Feb. 16, 2017, 7:06 a.m.
Right Patch Set: Rebase Created Feb. 16, 2017, 1:14 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « sitescripts/extensions/test/sitescripts.ini.template ('k') | tox.ini » ('j') | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
1 # This file is part of the Adblock Plus web scripts, 1 # This file is part of the Adblock Plus web scripts,
2 # Copyright (C) 2006-2016 Eyeo GmbH 2 # Copyright (C) 2006-2016 Eyeo GmbH
3 # 3 #
4 # Adblock Plus is free software: you can redistribute it and/or modify 4 # Adblock Plus is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License version 3 as 5 # it under the terms of the GNU General Public License version 3 as
6 # published by the Free Software Foundation. 6 # published by the Free Software Foundation.
7 # 7 #
8 # Adblock Plus is distributed in the hope that it will be useful, 8 # Adblock Plus is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details. 11 # GNU General Public License for more details.
12 # 12 #
13 # You should have received a copy of the GNU General Public License 13 # You should have received a copy of the GNU General Public License
14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. 14 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>.
15 15
16 import codecs 16 import codecs
17 import contextlib
17 import os 18 import os
18 import json 19 import json
19 import re 20 import re
20 import subprocess 21 import subprocess
21 import traceback 22 import traceback
22 import time 23 import time
23 import urlparse 24 import urlparse
24 import urllib 25 import urllib
25 import xml.dom.minidom as dom 26 import xml.dom.minidom as dom
26 from ConfigParser import SafeConfigParser, NoOptionError 27 from ConfigParser import SafeConfigParser, NoOptionError
27 from StringIO import StringIO 28 from StringIO import StringIO
28 from sitescripts.utils import get_config 29 from sitescripts.utils import get_config
30 from xml.parsers.expat import ExpatError
29 31
30 PACKAGE_SUFFIXES = { 32 PACKAGE_SUFFIXES = {
31 'gecko': '.xpi', 33 'gecko': '.xpi',
32 'gecko-webext': '.xpi', 34 'gecko-webext': '.xpi',
33 'chrome': '.crx', 35 'chrome': '.crx',
34 'safari': '.safariextz', 36 'safari': '.safariextz',
35 'ie': '.exe', 37 'ie': '.exe',
36 'android': '.apk', 38 'android': '.apk',
37 'edge': '.appx' 39 'edge': '.appx'
38 } 40 }
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
243 def _urlencode(value): 245 def _urlencode(value):
244 return urllib.quote(value.encode('utf-8'), '') 246 return urllib.quote(value.encode('utf-8'), '')
245 247
246 248
247 def _urlopen(url, attempts=3): 249 def _urlopen(url, attempts=3):
248 """ 250 """
249 Tries to open a particular URL, retries on failure. 251 Tries to open a particular URL, retries on failure.
250 """ 252 """
251 for i in range(attempts): 253 for i in range(attempts):
252 try: 254 try:
253 return urllib.urlopen(url) 255 return contextlib.closing(urllib.urlopen(url))
254 except IOError as e: 256 except IOError as e:
255 error = e 257 error = Exception('Error {0} while opening {1} url'
258 .format(e, url))
256 time.sleep(5) 259 time.sleep(5)
257 raise error 260 raise error
258 261
259 262
263 def _parseXMLDocument(url, attempts=2):
264 for i in range(attempts):
265 with _urlopen(url) as page:
266 content = page.read()
267 try:
268 return dom.parseString(content)
269 except ExpatError as err:
270 exception = Exception('Error {0} while parsing xml:\n{1}\nfrom {2}'
271 .format(err, content, url))
272 raise exception
273
274
260 def _getMozillaDownloadLink(galleryID): 275 def _getMozillaDownloadLink(galleryID):
261 """ 276 """
262 gets download link for a Gecko add-on from the Mozilla Addons site 277 gets download link for a Gecko add-on from the Mozilla Addons site
263 """ 278 """
264 url = 'https://services.addons.mozilla.org/en-US/firefox/api/1/addon/%s' % _ urlencode(galleryID) 279 url = 'https://services.addons.mozilla.org/en-US/firefox/api/1/addon/%s' % _ urlencode(galleryID)
265 document = dom.parse(_urlopen(url)) 280 document = _parseXMLDocument(url)
266 linkTags = document.getElementsByTagName('install') 281 linkTags = document.getElementsByTagName('install')
267 linkTag = linkTags[0] if len(linkTags) > 0 else None 282 linkTag = linkTags[0] if len(linkTags) > 0 else None
268 versionTags = document.getElementsByTagName('version') 283 versionTags = document.getElementsByTagName('version')
269 versionTag = versionTags[0] if len(versionTags) > 0 else None 284 versionTag = versionTags[0] if len(versionTags) > 0 else None
270 if linkTag and versionTag and linkTag.firstChild and versionTag.firstChild: 285 if linkTag and versionTag and linkTag.firstChild and versionTag.firstChild:
271 return (linkTag.firstChild.data, versionTag.firstChild.data) 286 return (linkTag.firstChild.data, versionTag.firstChild.data)
272 else: 287 else:
273 return (None, None) 288 return (None, None)
274 289
275 290
(...skipping 105 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 if not extensions: 396 if not extensions:
382 return 397 return
383 398
384 updates = {} 399 updates = {}
385 for extension in extensions: 400 for extension in extensions:
386 updates[extension['basename']] = { 401 updates[extension['basename']] = {
387 'url': extension['updateURL'], 402 'url': extension['updateURL'],
388 'version': extension['version'] 403 'version': extension['version']
389 } 404 }
390 writeLibabpUpdateManifest(path, updates) 405 writeLibabpUpdateManifest(path, updates)
LEFTRIGHT

Powered by Google App Engine
This is Rietveld