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

Side by Side Diff: sitescripts/extensions/utils.py

Issue 29370859: Issue 4767 - Improve error reporting in update_update_manifests (Closed)
Patch Set: For comments 9 and 10 Created Jan. 11, 2017, 11:31 p.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 # 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 os 17 import os
18 import json 18 import json
19 import re 19 import re
20 import subprocess 20 import subprocess
21 import traceback 21 import traceback
22 import time 22 import time
23 import urlparse 23 import urlparse
24 import urllib 24 import urllib
25 import xml.dom.minidom as dom 25 import xml.dom.minidom as dom
26 import sys
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 } 39 }
38 40
(...skipping 213 matching lines...) Expand 10 before | Expand all | Expand 10 after
252 except IOError as e: 254 except IOError as e:
253 error = e 255 error = e
254 time.sleep(5) 256 time.sleep(5)
255 raise error 257 raise error
256 258
257 259
258 def _getMozillaDownloadLink(galleryID): 260 def _getMozillaDownloadLink(galleryID):
259 """ 261 """
260 gets download link for a Gecko add-on from the Mozilla Addons site 262 gets download link for a Gecko add-on from the Mozilla Addons site
261 """ 263 """
262 url = 'https://services.addons.mozilla.org/en-US/firefox/api/1/addon/%s' % _ urlencode(galleryID) 264 try:
263 document = dom.parse(_urlopen(url)) 265 url = 'https://services.addons.mozilla.org/en-US/firefox/api/1/addon/%s' % _urlencode(galleryID)
264 linkTags = document.getElementsByTagName('install') 266 document = dom.parse(_urlopen(url))
Vasily Kuznetsov 2017/01/12 11:12:32 Actually we don't need to put the whole block into
265 linkTag = linkTags[0] if len(linkTags) > 0 else None 267 linkTags = document.getElementsByTagName('install')
266 versionTags = document.getElementsByTagName('version') 268 linkTag = linkTags[0] if len(linkTags) > 0 else None
267 versionTag = versionTags[0] if len(versionTags) > 0 else None 269 versionTags = document.getElementsByTagName('version')
268 if linkTag and versionTag and linkTag.firstChild and versionTag.firstChild: 270 versionTag = versionTags[0] if len(versionTags) > 0 else None
269 return (linkTag.firstChild.data, versionTag.firstChild.data) 271 if linkTag and versionTag and linkTag.firstChild and versionTag.firstChi ld:
270 else: 272 return (linkTag.firstChild.data, versionTag.firstChild.data)
271 return (None, None) 273 else:
274 return (None, None)
275 except ExpatError:
276 page = _urlopen(url)
Vasily Kuznetsov 2017/01/12 11:12:32 This is not a good idea. You're downloading the pa
277 content = document.open()
278 page.close()
279 raise Exception('Error found while parsing xml:\n{0}\nfrom {1} link'
280 .format(content, galleryID))
281
272 282
273 283
274 def _getLocalLink(repo): 284 def _getLocalLink(repo):
275 """ 285 """
276 gets the link for the newest download of an add-on in the local downloads 286 gets the link for the newest download of an add-on in the local downloads
277 repository 287 repository
278 """ 288 """
279 highestURL = None 289 highestURL = None
280 highestVersion = None 290 highestVersion = None
281 291
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after
379 if not extensions: 389 if not extensions:
380 return 390 return
381 391
382 updates = {} 392 updates = {}
383 for extension in extensions: 393 for extension in extensions:
384 updates[extension['basename']] = { 394 updates[extension['basename']] = {
385 'url': extension['updateURL'], 395 'url': extension['updateURL'],
386 'version': extension['version'] 396 'version': extension['version']
387 } 397 }
388 writeLibabpUpdateManifest(path, updates) 398 writeLibabpUpdateManifest(path, updates)
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