Skip to content

Commit

Permalink
Issue 4767 - Improve error reporting in update_update_manifests
Browse files Browse the repository at this point in the history
===================================================================
  • Loading branch information
poz2k4444 committed Jan 16, 2017
1 parent c5304b6 commit 95d360d
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions sitescripts/extensions/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
from ConfigParser import SafeConfigParser, NoOptionError
from StringIO import StringIO
from sitescripts.utils import get_config
from xml.parsers.expat import ExpatError

PACKAGE_SUFFIXES = {
'gecko': '.xpi',
Expand Down Expand Up @@ -250,17 +251,31 @@ def _urlopen(url, attempts=3):
try:
return urllib.urlopen(url)
except IOError as e:
error = e
error = Exception('Error {0} while opening {1} url'
.format(e, url))
time.sleep(5)
raise error


def _parseXMLDocument(url, attempts=2):
for i in range(attempts):
page = _urlopen(url)
content = page.read()
page.close()
try:
return dom.parseString(content)
except ExpatError as err:
exception = Exception('Error {0} while parsing xml:\n{1}\nfrom {2}'
.format(err, content, url))
raise exception


def _getMozillaDownloadLink(galleryID):
"""
gets download link for a Gecko add-on from the Mozilla Addons site
"""
url = 'https://services.addons.mozilla.org/en-US/firefox/api/1/addon/%s' % _urlencode(galleryID)
document = dom.parse(_urlopen(url))
document = _parseXMLDocument(url)
linkTags = document.getElementsByTagName('install')
linkTag = linkTags[0] if len(linkTags) > 0 else None
versionTags = document.getElementsByTagName('version')
Expand Down

0 comments on commit 95d360d

Please sign in to comment.