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 urllib | 5 import urllib |
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 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
121 return { | 121 return { |
122 'current': get_opera_version('Stable'), | 122 'current': get_opera_version('Stable'), |
123 'unreleased': [ | 123 'unreleased': [ |
124 get_opera_version('Beta'), | 124 get_opera_version('Beta'), |
125 get_opera_version('Developer') | 125 get_opera_version('Developer') |
126 ] | 126 ] |
127 } | 127 } |
128 | 128 |
129 BROWSERS['opera'] = get_opera_versions | 129 BROWSERS['opera'] = get_opera_versions |
130 | 130 |
131 def get_yandex_version(suffix): | 131 def key_by_version(version): |
132 response = urllib.urlopen('https://api.browser.yandex.ru/update-info/browser/y
andex%s/win-yandex.xml' % suffix) | 132 return map(int, version.split('.')) |
| 133 |
| 134 def get_yandex_version_raw(suffix, params): |
| 135 response = urllib.urlopen('https://api.browser.yandex.ru/update-info/browser/y
andex%s/win-yandex.xml%s' % (suffix, params)) |
133 try: | 136 try: |
134 doc = minidom.parse(response) | 137 doc = minidom.parse(response) |
135 finally: | 138 finally: |
136 response.close() | 139 response.close() |
137 | 140 |
138 item = doc.getElementsByTagName('item')[0] | 141 item = doc.getElementsByTagName('item')[0] |
139 description = item.getElementsByTagName('description')[0] | 142 description = item.getElementsByTagName('description')[0] |
140 return re.search(r'\d+\.\d+', description.firstChild.nodeValue).group(0) | 143 return re.search(r'\d+\.\d+', description.firstChild.nodeValue).group(0) |
141 | 144 |
| 145 def get_yandex_version(suffix=''): |
| 146 return max( |
| 147 get_yandex_version_raw(suffix, ''), |
| 148 get_yandex_version_raw(suffix, '?manual=yes'), |
| 149 key=key_by_version |
| 150 ) |
| 151 |
142 def get_yandex_versions(): | 152 def get_yandex_versions(): |
143 return { | 153 return { |
144 'current': get_yandex_version(''), | 154 'current': get_yandex_version(), |
145 'unreleased': [get_yandex_version('-beta')] | 155 'unreleased': [get_yandex_version('-beta')] |
146 } | 156 } |
147 | 157 |
148 BROWSERS['yandex'] = get_yandex_versions | 158 BROWSERS['yandex'] = get_yandex_versions |
149 | 159 |
150 def open_cache_file(filename): | 160 def open_cache_file(filename): |
151 flags = os.O_RDWR | os.O_CREAT | 161 flags = os.O_RDWR | os.O_CREAT |
152 try: | 162 try: |
153 fd = os.open(filename, flags) | 163 fd = os.open(filename, flags) |
154 except OSError as e: | 164 except OSError as e: |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
202 previous = cached_current | 212 previous = cached_current |
203 else: | 213 else: |
204 previous = cached_versions['previous'] | 214 previous = cached_versions['previous'] |
205 versions['previous'] = previous | 215 versions['previous'] = previous |
206 | 216 |
207 # Remove duplicates from unreleased versions. Occasionally, | 217 # Remove duplicates from unreleased versions. Occasionally, |
208 # different channels are on the same version, but we want | 218 # different channels are on the same version, but we want |
209 # to list each version only once. | 219 # to list each version only once. |
210 versions['unreleased'] = sorted( | 220 versions['unreleased'] = sorted( |
211 set(versions['unreleased']) - {current, previous}, | 221 set(versions['unreleased']) - {current, previous}, |
212 key=lambda ver: map(int, ver.split('.')) | 222 key=key_by_version |
213 ) | 223 ) |
214 | 224 |
215 versions['timestamp'] = now | 225 versions['timestamp'] = now |
216 persistent_cache[browser] = versions | 226 persistent_cache[browser] = versions |
217 file.seek(0) | 227 file.seek(0) |
218 json.dump(persistent_cache, file) | 228 json.dump(persistent_cache, file) |
219 file.truncate() | 229 file.truncate() |
220 | 230 |
221 if not versions['previous']: | 231 if not versions['previous']: |
222 logging.warning("Couldn't determine previous browser version, " | 232 logging.warning("Couldn't determine previous browser version, " |
223 'please set %s.previous in %s', browser, filename) | 233 'please set %s.previous in %s', browser, filename) |
224 | 234 |
225 cache[browser] = versions | 235 cache[browser] = versions |
226 return versions | 236 return versions |
OLD | NEW |