Left: | ||
Right: |
OLD | NEW |
---|---|
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 Loading... | |
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()) | |
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
| |
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'] = int(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.
| |
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 |
OLD | NEW |