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

Side by Side Diff: globals/get_browser_versions.py

Issue 5230369355857920: Issue 2432 - Ignore temporary issues when retrieving browser versions (Closed)
Patch Set: Don't round timestamp Created May 19, 2015, 2:18 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 import re 1 import re
2 import os 2 import os
3 import sys 3 import sys
4 import json 4 import json
5 import urllib2 5 import urllib2
6 import errno 6 import errno
7 import logging 7 import logging
8 import time
8 from xml.dom import minidom 9 from xml.dom import minidom
9 10
10 from jinja2 import contextfunction 11 from jinja2 import contextfunction
11 12
12 BROWSERS = {} 13 BROWSERS = {}
13 14
14 CHROME_UPDATE_XML = '''\ 15 CHROME_UPDATE_XML = '''\
15 <?xml version="1.0" encoding="UTF-8"?> 16 <?xml version="1.0" encoding="UTF-8"?>
16 <request protocol="3.0" ismachine="0"> 17 <request protocol="3.0" ismachine="0">
17 <os platform="win" version="99" arch="x64"/> 18 <os platform="win" version="99" arch="x64"/>
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 filename = os.path.join(context['source'].get_cache_dir(), 'browsers.json') 174 filename = os.path.join(context['source'].get_cache_dir(), 'browsers.json')
174 with open_cache_file(filename) as file: 175 with open_cache_file(filename) as file:
175 try: 176 try:
176 persistent_cache = json.load(file) 177 persistent_cache = json.load(file)
177 except ValueError: 178 except ValueError:
178 if file.tell() > 0: 179 if file.tell() > 0:
179 raise 180 raise
180 persistent_cache = {} 181 persistent_cache = {}
181 182
182 cached_versions = persistent_cache.get(browser) 183 cached_versions = persistent_cache.get(browser)
184 now = time.mktime(time.gmtime())
183 if exc_info: 185 if exc_info:
184 if not cached_versions: 186 if not cached_versions:
185 raise exc_info[0], exc_info[1], exc_info[2] 187 raise exc_info[0], exc_info[1], exc_info[2]
186 188
187 versions = cached_versions 189 versions = cached_versions
188 logging.warning('Failed to get %s versions, falling back to ' 190 if now - versions['timestamp'] > 60*60*2:
189 'cached versions', browser, exc_info=exc_info) 191 logging.warning('Failed to get %s versions, falling back to '
192 'cached versions', browser, exc_info=exc_info)
190 else: 193 else:
191 # Determine previous version: If we recorded the version before and it 194 # Determine previous version: If we recorded the version before and it
192 # changed since then, the old current version becomes the new previous 195 # changed since then, the old current version becomes the new previous
193 # version. If the version didn't change, use the cached previous version. 196 # version. If the version didn't change, use the cached previous version.
194 current = versions['current'] 197 current = versions['current']
195 previous = None 198 previous = None
196 if cached_versions: 199 if cached_versions:
197 cached_current = cached_versions['current'] 200 cached_current = cached_versions['current']
198 if cached_current != current: 201 if cached_current != current:
199 previous = cached_current 202 previous = cached_current
200 else: 203 else:
201 previous = cached_versions['previous'] 204 previous = cached_versions['previous']
202 versions['previous'] = previous 205 versions['previous'] = previous
203 206
204 # Remove duplicates from unreleased versions. Occasionally, 207 # Remove duplicates from unreleased versions. Occasionally,
205 # different channels are on the same version, but we want 208 # different channels are on the same version, but we want
206 # to list each version only once. 209 # to list each version only once.
207 versions['unreleased'] = sorted( 210 versions['unreleased'] = sorted(
208 set(versions['unreleased']) - {current, previous}, 211 set(versions['unreleased']) - {current, previous},
209 key=lambda ver: map(int, ver.split('.')) 212 key=lambda ver: map(int, ver.split('.'))
210 ) 213 )
211 214
215 versions['timestamp'] = now
212 persistent_cache[browser] = versions 216 persistent_cache[browser] = versions
213 file.seek(0) 217 file.seek(0)
214 json.dump(persistent_cache, file) 218 json.dump(persistent_cache, file)
215 file.truncate() 219 file.truncate()
216 220
217 if not versions['previous']: 221 if not versions['previous']:
218 logging.warning("Couldn't determine previous browser version, " 222 logging.warning("Couldn't determine previous browser version, "
219 'please set %s.previous in %s', browser, filename) 223 'please set %s.previous in %s', browser, filename)
220 224
221 cache[browser] = versions 225 cache[browser] = versions
222 return versions 226 return versions
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