 Issue 29370859:
  Issue 4767 - Improve error reporting in update_update_manifests  (Closed)
    
  
    Issue 29370859:
  Issue 4767 - Improve error reporting in update_update_manifests  (Closed) 
  | Left: | ||
| Right: | 
| LEFT | RIGHT | 
|---|---|
| 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 | |
| 27 from ConfigParser import SafeConfigParser, NoOptionError | 26 from ConfigParser import SafeConfigParser, NoOptionError | 
| 28 from StringIO import StringIO | 27 from StringIO import StringIO | 
| 29 from sitescripts.utils import get_config | 28 from sitescripts.utils import get_config | 
| 30 from xml.parsers.expat import ExpatError | 29 from xml.parsers.expat import ExpatError | 
| 31 | 30 | 
| 32 PACKAGE_SUFFIXES = { | 31 PACKAGE_SUFFIXES = { | 
| 33 'gecko': '.xpi', | 32 'gecko': '.xpi', | 
| 34 'gecko-webext': '.xpi', | 33 'gecko-webext': '.xpi', | 
| 35 'chrome': '.crx', | 34 'chrome': '.crx', | 
| 36 'safari': '.safariextz', | 35 'safari': '.safariextz', | 
| (...skipping 208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 245 | 244 | 
| 246 | 245 | 
| 247 def _urlopen(url, attempts=3): | 246 def _urlopen(url, attempts=3): | 
| 248 """ | 247 """ | 
| 249 Tries to open a particular URL, retries on failure. | 248 Tries to open a particular URL, retries on failure. | 
| 250 """ | 249 """ | 
| 251 for i in range(attempts): | 250 for i in range(attempts): | 
| 252 try: | 251 try: | 
| 253 return urllib.urlopen(url) | 252 return urllib.urlopen(url) | 
| 254 except IOError as e: | 253 except IOError as e: | 
| 255 error = e | 254 error = Exception('Error {0} while opening {1} url' | 
| 255 .format(e, url)) | |
| 256 time.sleep(5) | 256 time.sleep(5) | 
| 257 raise error | 257 raise error | 
| 258 | 258 | 
| 259 | 259 | 
| 260 def _parseXMLDocument(url, attempts=2): | |
| 261 for i in range(attempts): | |
| 262 page = _urlopen(url) | |
| 263 content = page.read() | |
| 264 page.close() | |
| 
Sebastian Noack
2017/01/17 09:33:32
The close() should have gone into a finally block,
 
Sebastian Noack
2017/01/17 10:16:56
Yes, in Python 2, the repsonse object returned by
 
Sebastian Noack
2017/01/17 10:20:15
Well, alternatively you could use try-finally. But
 
Vasily Kuznetsov
2017/01/17 10:30:34
Yeah, with is nicer, especially having Python 3 in
 | |
| 265 try: | |
| 266 return dom.parseString(content) | |
| 267 except ExpatError as err: | |
| 268 exception = Exception('Error {0} while parsing xml:\n{1}\nfrom {2}' | |
| 269 .format(err, content, url)) | |
| 270 raise exception | |
| 271 | |
| 272 | |
| 260 def _getMozillaDownloadLink(galleryID): | 273 def _getMozillaDownloadLink(galleryID): | 
| 261 """ | 274 """ | 
| 262 gets download link for a Gecko add-on from the Mozilla Addons site | 275 gets download link for a Gecko add-on from the Mozilla Addons site | 
| 263 """ | 276 """ | 
| 264 url = 'https://services.addons.mozilla.org/en-US/firefox/api/1/addon/%s' % _ urlencode(galleryID) | 277 url = 'https://services.addons.mozilla.org/en-US/firefox/api/1/addon/%s' % _ urlencode(galleryID) | 
| 265 document = dom.parse(_urlopen(url)) | 278 document = _parseXMLDocument(url) | 
| 266 linkTags = document.getElementsByTagName('install') | 279 linkTags = document.getElementsByTagName('install') | 
| 267 linkTag = linkTags[0] if len(linkTags) > 0 else None | 280 linkTag = linkTags[0] if len(linkTags) > 0 else None | 
| 268 versionTags = document.getElementsByTagName('version') | 281 versionTags = document.getElementsByTagName('version') | 
| 269 versionTag = versionTags[0] if len(versionTags) > 0 else None | 282 versionTag = versionTags[0] if len(versionTags) > 0 else None | 
| 270 if linkTag and versionTag and linkTag.firstChild and versionTag.firstChild: | 283 if linkTag and versionTag and linkTag.firstChild and versionTag.firstChild: | 
| 271 return (linkTag.firstChild.data, versionTag.firstChild.data) | 284 return (linkTag.firstChild.data, versionTag.firstChild.data) | 
| 272 else: | 285 else: | 
| 273 return (None, None) | 286 return (None, None) | 
| 274 | 287 | 
| 275 | 288 | 
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 315 """ | 328 """ | 
| 316 gets the download links for all extensions and puts them into the config | 329 gets the download links for all extensions and puts them into the config | 
| 317 object | 330 object | 
| 318 """ | 331 """ | 
| 319 for repo in Configuration.getRepositoryConfigurations(): | 332 for repo in Configuration.getRepositoryConfigurations(): | 
| 320 try: | 333 try: | 
| 321 (downloadURL, version) = _getDownloadLink(repo) | 334 (downloadURL, version) = _getDownloadLink(repo) | 
| 322 if downloadURL is None: | 335 if downloadURL is None: | 
| 323 raise Exception('No download link found for repo: ' + | 336 raise Exception('No download link found for repo: ' + | 
| 324 repo.repositoryName) | 337 repo.repositoryName) | 
| 325 except ExpatError: | |
| 326 traceback.print_exc() | |
| 327 print >> sys.stderr, ('Error found while parsing xml from {0} link' | |
| 328 .format(repo.repositoryName)) | |
| 329 continue | |
| 330 except: | 338 except: | 
| 331 traceback.print_exc() | 339 traceback.print_exc() | 
| 332 continue | 340 continue | 
| 333 if not result.has_section(repo.repositoryName): | 341 if not result.has_section(repo.repositoryName): | 
| 334 result.add_section(repo.repositoryName) | 342 result.add_section(repo.repositoryName) | 
| 335 result.set(repo.repositoryName, 'downloadURL', downloadURL) | 343 result.set(repo.repositoryName, 'downloadURL', downloadURL) | 
| 336 result.set(repo.repositoryName, 'version', version) | 344 result.set(repo.repositoryName, 'version', version) | 
| 337 | 345 | 
| 338 qrcode = _getQRCode(downloadURL) | 346 qrcode = _getQRCode(downloadURL) | 
| 339 if qrcode is not None: | 347 if qrcode is not None: | 
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 386 if not extensions: | 394 if not extensions: | 
| 387 return | 395 return | 
| 388 | 396 | 
| 389 updates = {} | 397 updates = {} | 
| 390 for extension in extensions: | 398 for extension in extensions: | 
| 391 updates[extension['basename']] = { | 399 updates[extension['basename']] = { | 
| 392 'url': extension['updateURL'], | 400 'url': extension['updateURL'], | 
| 393 'version': extension['version'] | 401 'version': extension['version'] | 
| 394 } | 402 } | 
| 395 writeLibabpUpdateManifest(path, updates) | 403 writeLibabpUpdateManifest(path, updates) | 
| LEFT | RIGHT |