commit 22080b3f4b08f05c2c6e2fa841c259620ed66d72 Author: Damian Johnson atagar@torproject.org Date: Sun Feb 11 18:23:35 2018 -0800
Move curling to a helper
No reason to bundle retries and such in the main function. --- package_versions.py | 36 +++++++++++++++++++++--------------- 1 file changed, 21 insertions(+), 15 deletions(-)
diff --git a/package_versions.py b/package_versions.py index 9d56659..6c6e3f6 100755 --- a/package_versions.py +++ b/package_versions.py @@ -83,6 +83,17 @@ PACKAGES = [ log = util.get_logger('package_versions')
+def fetch_url(url): + for i in range(3): + try: + return urllib2.urlopen(url, timeout = 5).read() + except Exception as exc: + if i < 2: + time.sleep(2 ** i) + else: + raise IOError(str(exc)) + + def gentoo_version(request): # Unlike other platforms gentoo lists all package versions, so we # need to figure out what's the latest. @@ -113,19 +124,9 @@ def email_content(): lines.append(DIV)
for package in packages: - request, request_exc = None, None - - for i in range(3): - try: - request = urllib2.urlopen(package.url, timeout = 5).read() - break - except Exception as exc: - request_exc = exc # note exception and retry + try: + request = fetch_url(package.url)
- if i != 2: - time.sleep(2 ** i) - - if request: if package.platform == 'gentoo': current_version = gentoo_version(request) else: @@ -140,9 +141,14 @@ def email_content(): else: msg = 'current version is %s but wiki has %s' % (current_version, package.version) has_issue = True - else: - msg = 'unable to retrieve current version: %s' % request_exc - has_issue = True + except IOError as exc: + msg = 'unable to retrieve current version: %s' % exc + + # Gentoo's site fails pretty routinely. No need to generate notices for + # it. + + if package.platform == 'gentoo': + has_issue = True
lines.append(COLUMN % (project, package.platform, package.version, msg))
tor-commits@lists.torproject.org