| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 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 """ | 18 """ |
| 19 Update the list of extenstions | 19 Update the list of extenstions |
| 20 ============================== | 20 ============================== |
| 21 | 21 |
| 22 This script generates a list of extensions and saves these with download links | 22 This script generates a list of extensions and saves these with download links |
| 23 and version information | 23 and version information |
| 24 """ | 24 """ |
| 25 | 25 |
| 26 import sys, os, re, urllib, urllib2, subprocess, time | |
|
Wladimir Palant
2014/07/22 11:24:26
sys, os, subprocess are no longer being used here.
Felix Dahlke
2014/07/22 12:01:11
Done.
| |
| 27 import xml.dom.minidom as dom | |
|
Wladimir Palant
2014/07/22 11:24:26
dom should no longer be required here.
Felix Dahlke
2014/07/22 12:01:11
Done.
| |
| 28 from ConfigParser import SafeConfigParser | 26 from ConfigParser import SafeConfigParser |
| 29 from StringIO import StringIO | 27 from sitescripts.utils import get_config |
|
Wladimir Palant
2014/07/22 11:24:26
StringIO is no longer being used here.
Felix Dahlke
2014/07/22 12:01:11
Done.
| |
| 30 from sitescripts.utils import get_config, get_template | 28 from sitescripts.extensions.utils import Configuration, getDownloadLinks |
|
Wladimir Palant
2014/07/22 11:24:26
get_template is no longer being used here.
Felix Dahlke
2014/07/22 12:01:11
Done.
| |
| 31 from sitescripts.extensions.utils import (compareVersions, Configuration, | |
| 32 getSafariCertificateID, getDownloadLinks, readMetadata) | |
|
Wladimir Palant
2014/07/22 11:24:26
compareVersions, getSafariCertificateID, readMetad
Felix Dahlke
2014/07/22 12:01:11
Done.
| |
| 33 from sitescripts.extensions.pad import PadFile | 29 from sitescripts.extensions.pad import PadFile |
| 34 | |
| 35 def urlencode(value): | |
| 36 return urllib.quote(value.encode('utf-8'), '') | |
| 37 | |
| 38 def urlopen(url, attempts=3): | |
| 39 """ | |
| 40 Tries to open a particular URL, retries on failure. | |
| 41 """ | |
| 42 for i in range(attempts): | |
| 43 try: | |
| 44 return urllib.urlopen(url) | |
| 45 except IOError, e: | |
| 46 error = e | |
| 47 time.sleep(5) | |
| 48 raise error | |
| 49 | |
| 50 def getMozillaDownloadLink(galleryID): | |
| 51 """ | |
| 52 gets download link for a Gecko add-on from the Mozilla Addons site | |
| 53 """ | |
| 54 url = 'https://services.addons.mozilla.org/en-US/firefox/api/1/addon/%s' % url encode(galleryID) | |
| 55 contents = urlopen(url).read() | |
| 56 document = dom.parseString(contents) | |
| 57 linkTags = document.getElementsByTagName('install') | |
| 58 linkTag = linkTags[0] if len(linkTags) > 0 else None | |
| 59 versionTags = document.getElementsByTagName('version') | |
| 60 versionTag = versionTags[0] if len(versionTags) > 0 else None | |
| 61 if linkTag and versionTag and linkTag.firstChild and versionTag.firstChild: | |
| 62 return (linkTag.firstChild.data, versionTag.firstChild.data) | |
| 63 else: | |
| 64 return (None, None) | |
| 65 | |
| 66 def getGoogleDownloadLink(galleryID): | |
| 67 """ | |
| 68 gets download link for a Chrome add-on from the Chrome Gallery site | |
| 69 """ | |
| 70 galleryID = urlencode(galleryID) | |
| 71 | |
| 72 url = 'https://clients2.google.com/service/update2/crx?x=%s' % urlencode('id=% s&uc' % galleryID) | |
| 73 document = dom.parse(urlopen(url)) | |
| 74 updateTags = document.getElementsByTagName('updatecheck') | |
| 75 version = updateTags and updateTags[0].getAttribute('version') | |
| 76 | |
| 77 if not version: | |
| 78 return (None, None) | |
| 79 | |
| 80 request = urllib2.Request('https://chrome.google.com/webstore/detail/_/' + gal leryID) | |
| 81 request.get_method = lambda : 'HEAD' | |
| 82 url = urllib2.urlopen(request).geturl() | |
| 83 | |
| 84 return (url, version) | |
| 85 | |
| 86 def getOperaDownloadLink(galleryID): | |
|
Wladimir Palant
2014/07/22 11:24:26
From the look of it, this function and the ones ab
Felix Dahlke
2014/07/22 12:01:11
Done.
| |
| 87 """ | |
| 88 gets download link for an Opera add-on from the Opera Addons site | |
| 89 """ | |
| 90 galleryID = urlencode(galleryID) | |
| 91 | |
| 92 request = urllib2.Request('https://addons.opera.com/extensions/download/%s/' % galleryID) | |
| 93 request.get_method = lambda : 'HEAD' | |
| 94 response = urllib2.urlopen(request) | |
| 95 | |
| 96 content_disposition = response.info().getheader('Content-Disposition') | |
| 97 if content_disposition: | |
| 98 match = re.search(r'filename=\S+-([\d.]+)-\d+\.crx$', content_disposition) | |
| 99 if match: | |
| 100 return ('https://addons.opera.com/extensions/details/%s/' % galleryID , ma tch.group(1)) | |
| 101 | |
| 102 return (None, None) | |
| 103 | 30 |
| 104 def writePadFile(links): | 31 def writePadFile(links): |
| 105 for repo in Configuration.getRepositoryConfigurations(): | 32 for repo in Configuration.getRepositoryConfigurations(): |
| 106 if repo.pad and links.has_section(repo.repositoryName): | 33 if repo.pad and links.has_section(repo.repositoryName): |
| 107 PadFile.forRepository(repo, links.get(repo.repositoryName, 'version'), | 34 PadFile.forRepository(repo, links.get(repo.repositoryName, 'version'), |
| 108 links.get(repo.repositoryName, 'downloadURL')) .write() | 35 links.get(repo.repositoryName, 'downloadURL')) .write() |
| 109 | 36 |
| 110 def updateLinks(): | 37 def updateLinks(): |
| 111 """ | 38 """ |
| 112 writes the current extension download links to a file | 39 writes the current extension download links to a file |
| 113 """ | 40 """ |
| 114 | 41 |
| 115 # Now get download links and save them to file | 42 # Now get download links and save them to file |
| 116 result = SafeConfigParser() | 43 result = SafeConfigParser() |
| 117 getDownloadLinks(result) | 44 getDownloadLinks(result) |
| 118 file = open(get_config().get('extensions', 'downloadLinksFile'), 'wb') | 45 file = open(get_config().get('extensions', 'downloadLinksFile'), 'wb') |
| 119 result.write(file) | 46 result.write(file) |
| 120 file.close() | 47 file.close() |
| 121 | 48 |
| 122 writePadFile(result) | 49 writePadFile(result) |
| 123 | 50 |
| 124 if __name__ == "__main__": | 51 if __name__ == "__main__": |
| 125 updateLinks() | 52 updateLinks() |
| LEFT | RIGHT |