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

Delta Between Two Patch Sets: globals/get_browser_versions.py

Issue 5230369355857920: Issue 2432 - Ignore temporary issues when retrieving browser versions (Closed)
Left Patch Set: Created May 19, 2015, 1:49 p.m.
Right 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:
Left: Side by side diff | Download
Right: Side by side diff | Download
« no previous file with change/comment | « no previous file | no next file » | no next file with change/comment »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
LEFTRIGHT
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 import time
9 from xml.dom import minidom 9 from xml.dom import minidom
10 10
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 filename = os.path.join(context['source'].get_cache_dir(), 'browsers.json') 174 filename = os.path.join(context['source'].get_cache_dir(), 'browsers.json')
175 with open_cache_file(filename) as file: 175 with open_cache_file(filename) as file:
176 try: 176 try:
177 persistent_cache = json.load(file) 177 persistent_cache = json.load(file)
178 except ValueError: 178 except ValueError:
179 if file.tell() > 0: 179 if file.tell() > 0:
180 raise 180 raise
181 persistent_cache = {} 181 persistent_cache = {}
182 182
183 cached_versions = persistent_cache.get(browser) 183 cached_versions = persistent_cache.get(browser)
184 now = time.mktime(time.gmtime()) 184 now = time.mktime(time.gmtime())
Wladimir Palant 2015/05/19 14:15:47 now = time.time()?
Sebastian Noack 2015/05/19 14:18:22 This would return local time.
Wladimir Palant 2015/05/19 14:20:39 I don't really see a problem with that. Wouldn't e
185 if exc_info: 185 if exc_info:
186 if not cached_versions: 186 if not cached_versions:
187 raise exc_info[0], exc_info[1], exc_info[2] 187 raise exc_info[0], exc_info[1], exc_info[2]
188 188
189 versions = cached_versions 189 versions = cached_versions
190 if now - versions['timestamp'] > 60*60*2: 190 if now - versions['timestamp'] > 60*60*2:
191 logging.warning('Failed to get %s versions, falling back to ' 191 logging.warning('Failed to get %s versions, falling back to '
192 'cached versions', browser, exc_info=exc_info) 192 'cached versions', browser, exc_info=exc_info)
193 else: 193 else:
194 # Determine previous version: If we recorded the version before and it 194 # Determine previous version: If we recorded the version before and it
(...skipping 10 matching lines...) Expand all
205 versions['previous'] = previous 205 versions['previous'] = previous
206 206
207 # Remove duplicates from unreleased versions. Occasionally, 207 # Remove duplicates from unreleased versions. Occasionally,
208 # different channels are on the same version, but we want 208 # different channels are on the same version, but we want
209 # to list each version only once. 209 # to list each version only once.
210 versions['unreleased'] = sorted( 210 versions['unreleased'] = sorted(
211 set(versions['unreleased']) - {current, previous}, 211 set(versions['unreleased']) - {current, previous},
212 key=lambda ver: map(int, ver.split('.')) 212 key=lambda ver: map(int, ver.split('.'))
213 ) 213 )
214 214
215 versions['timestamp'] = int(now) 215 versions['timestamp'] = now
Wladimir Palant 2015/05/19 14:15:47 Nit: I don't see much point rounding the timestamp
Sebastian Noack 2015/05/19 14:18:22 Done.
216 persistent_cache[browser] = versions 216 persistent_cache[browser] = versions
217 file.seek(0) 217 file.seek(0)
218 json.dump(persistent_cache, file) 218 json.dump(persistent_cache, file)
219 file.truncate() 219 file.truncate()
220 220
221 if not versions['previous']: 221 if not versions['previous']:
222 logging.warning("Couldn't determine previous browser version, " 222 logging.warning("Couldn't determine previous browser version, "
223 'please set %s.previous in %s', browser, filename) 223 'please set %s.previous in %s', browser, filename)
224 224
225 cache[browser] = versions 225 cache[browser] = versions
226 return versions 226 return versions
LEFTRIGHT
« no previous file | no next file » | Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Toggle Comments ('s')

Powered by Google App Engine
This is Rietveld