OLD | NEW |
1 # coding: utf-8 | 1 # coding: utf-8 |
2 | 2 |
3 # This file is part of the Adblock Plus web scripts, | 3 # This file is part of the Adblock Plus web scripts, |
4 # Copyright (C) 2006-2014 Eyeo GmbH | 4 # Copyright (C) 2006-2014 Eyeo GmbH |
5 # | 5 # |
6 # Adblock Plus is free software: you can redistribute it and/or modify | 6 # Adblock Plus is free software: you can redistribute it and/or modify |
7 # it under the terms of the GNU General Public License version 3 as | 7 # it under the terms of the GNU General Public License version 3 as |
8 # published by the Free Software Foundation. | 8 # published by the Free Software Foundation. |
9 # | 9 # |
10 # Adblock Plus is distributed in the hope that it will be useful, | 10 # Adblock Plus is distributed in the hope that it will be useful, |
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of | 11 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
13 # GNU General Public License for more details. | 13 # GNU General Public License for more details. |
14 # | 14 # |
15 # You should have received a copy of the GNU General Public License | 15 # You should have received a copy of the GNU General Public License |
16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 16 # along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
17 | 17 |
18 import re | 18 import re |
19 import os | 19 import os |
20 import subprocess | 20 import subprocess |
| 21 import urlparse |
21 from ConfigParser import SafeConfigParser, NoOptionError | 22 from ConfigParser import SafeConfigParser, NoOptionError |
22 from StringIO import StringIO | 23 from StringIO import StringIO |
23 from sitescripts.utils import get_config | 24 from sitescripts.utils import get_config |
| 25 from sitescripts.extensions.android import get_min_sdk_version |
| 26 from buildtools.packagerGecko import KNOWN_APPS |
24 | 27 |
25 def compareVersionParts(part1, part2): | 28 def compareVersionParts(part1, part2): |
26 def convertInt(value, default): | 29 def convertInt(value, default): |
27 try: | 30 try: |
28 return int(value) | 31 return int(value) |
29 except ValueError: | 32 except ValueError: |
30 return default | 33 return default |
31 | 34 |
32 def convertVersionPart(part): | 35 def convertVersionPart(part): |
33 if part == '*': | 36 if part == '*': |
(...skipping 215 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
249 except M2Crypto.X509.X509Error: | 252 except M2Crypto.X509.X509Error: |
250 raise Exception('No safari developer certificate found in chain') | 253 raise Exception('No safari developer certificate found in chain') |
251 | 254 |
252 subject = cert.get_subject() | 255 subject = cert.get_subject() |
253 for entry in subject.get_entries_by_nid(subject.nid['CN']): | 256 for entry in subject.get_entries_by_nid(subject.nid['CN']): |
254 m = re.match(r'Safari Developer: \((.*?)\)', entry.get_data().as_text()) | 257 m = re.match(r'Safari Developer: \((.*?)\)', entry.get_data().as_text()) |
255 if m: | 258 if m: |
256 return m.group(1) | 259 return m.group(1) |
257 finally: | 260 finally: |
258 bio.close() | 261 bio.close() |
| 262 |
| 263 def _getLocalLink(repo): |
| 264 """ |
| 265 gets the link for the newest download of an add-on in the local downloads |
| 266 repository |
| 267 """ |
| 268 highestURL = None |
| 269 highestVersion = None |
| 270 |
| 271 for filename, version in repo.getDownloads(): |
| 272 if not highestVersion or compareVersions(version, highestVersion) > 0: |
| 273 highestURL = urlparse.urljoin(repo.downloadsURL, filename) |
| 274 highestVersion = version |
| 275 |
| 276 return (highestURL, highestVersion) |
| 277 |
| 278 def _getDownloadLink(repo): |
| 279 """ |
| 280 gets the download link to the most current version of an extension |
| 281 """ |
| 282 # you can't easily install extensions from third-party sources on Chrome |
| 283 # and Opera. So always get the link for the version on the Web Store. |
| 284 if repo.galleryID: |
| 285 if repo.type == "chrome": |
| 286 return getGoogleDownloadLink(repo.galleryID) |
| 287 if repo.type == "opera": |
| 288 return getOperaDownloadLink(repo.galleryID) |
| 289 |
| 290 (localURL, localVersion) = _getLocalLink(repo) |
| 291 |
| 292 # get a link to Firefox Add-Ons, if the latest version has been published ther
e |
| 293 if repo.type == 'gecko' and repo.galleryID: |
| 294 (galleryURL, galleryVersion) = getMozillaDownloadLink(repo.galleryID) |
| 295 if not localVersion or (galleryVersion and |
| 296 compareVersions(galleryVersion, localVersion) >= 0): |
| 297 return (galleryURL, galleryVersion) |
| 298 |
| 299 return (localURL, localVersion) |
| 300 |
| 301 def _getQRCode(text): |
| 302 try: |
| 303 import qrcode |
| 304 import base64 |
| 305 import Image # required by qrcode but not formally a dependency |
| 306 except: |
| 307 return None |
| 308 |
| 309 data = StringIO() |
| 310 qrcode.make(text, box_size=5).save(data, 'png') |
| 311 return 'data:image/png;base64,' + base64.b64encode(data.getvalue()) |
| 312 |
| 313 def getDownloadLinks(result): |
| 314 """ |
| 315 gets the download links for all extensions and puts them into the config |
| 316 object |
| 317 """ |
| 318 for repo in Configuration.getRepositoryConfigurations(): |
| 319 (downloadURL, version) = _getDownloadLink(repo) |
| 320 if downloadURL == None: |
| 321 continue |
| 322 if not result.has_section(repo.repositoryName): |
| 323 result.add_section(repo.repositoryName) |
| 324 result.set(repo.repositoryName, "downloadURL", downloadURL) |
| 325 result.set(repo.repositoryName, "version", version) |
| 326 |
| 327 qrcode = _getQRCode(downloadURL) |
| 328 if qrcode != None: |
| 329 result.set(repo.repositoryName, "qrcode", qrcode) |
| 330 |
| 331 def readMetadata(repo, version): |
| 332 """ |
| 333 reads extension ID and compatibility information from metadata file in the |
| 334 extension's repository |
| 335 """ |
| 336 if repo.type == 'android': |
| 337 command = ['hg', '-R', repo.repository, 'id', '-r', version, '-n'] |
| 338 result = subprocess.check_output(command) |
| 339 revision = re.sub(r'\D', '', result) |
| 340 |
| 341 return { |
| 342 'revision': revision, |
| 343 'minSdkVersion': get_min_sdk_version(repo, version), |
| 344 } |
| 345 elif repo.type == 'safari': |
| 346 metadata = repo.readMetadata(version) |
| 347 return { |
| 348 'certificateID': getSafariCertificateID(repo.keyFile), |
| 349 'version': version, |
| 350 'shortVersion': version, |
| 351 'basename': metadata.get('general', 'basename'), |
| 352 } |
| 353 elif repo.type == 'gecko': |
| 354 metadata = repo.readMetadata(version) |
| 355 result = { |
| 356 'extensionID': metadata.get('general', 'id'), |
| 357 'version': version, |
| 358 'compat': [] |
| 359 } |
| 360 for key, value in KNOWN_APPS.iteritems(): |
| 361 if metadata.has_option('compat', key): |
| 362 minVersion, maxVersion = metadata.get('compat', key).split('/') |
| 363 result['compat'].append({'id': value, 'minVersion': minVersion, 'maxVers
ion': maxVersion}) |
| 364 return result |
| 365 else: |
| 366 raise Exception('unknown repository type %r' % repo.type) |
OLD | NEW |