| 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-2012 Eyeo GmbH | 4 # Copyright (C) 2006-2012 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 os, re, urllib, urllib2, urlparse, subprocess, time | 26 import sys, os, re, urllib, urllib2, urlparse, subprocess, time |
| 27 import xml.dom.minidom as dom | 27 import xml.dom.minidom as dom |
| 28 from ConfigParser import SafeConfigParser | 28 from ConfigParser import SafeConfigParser |
| 29 from StringIO import StringIO | 29 from StringIO import StringIO |
| 30 from sitescripts.utils import get_config, get_template | 30 from sitescripts.utils import get_config, get_template |
| 31 from sitescripts.extensions.utils import compareVersions, Configuration | 31 from sitescripts.extensions.utils import compareVersions, Configuration |
| 32 from buildtools.packagerGecko import KNOWN_APPS | 32 from buildtools.packagerGecko import KNOWN_APPS |
| 33 | 33 |
| 34 def urlencode(value): | 34 def urlencode(value): |
| 35 return urllib.quote(value.encode('utf-8'), '') | 35 return urllib.quote(value.encode('utf-8'), '') |
| 36 | 36 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 151 if not result.has_section(repo.repositoryName): | 151 if not result.has_section(repo.repositoryName): |
| 152 result.add_section(repo.repositoryName) | 152 result.add_section(repo.repositoryName) |
| 153 result.set(repo.repositoryName, "downloadURL", downloadURL) | 153 result.set(repo.repositoryName, "downloadURL", downloadURL) |
| 154 result.set(repo.repositoryName, "version", version) | 154 result.set(repo.repositoryName, "version", version) |
| 155 | 155 |
| 156 def readMetadata(repo, version): | 156 def readMetadata(repo, version): |
| 157 """ | 157 """ |
| 158 reads extension ID and compatibility information from metadata file in the | 158 reads extension ID and compatibility information from metadata file in the |
| 159 extension's repository | 159 extension's repository |
| 160 """ | 160 """ |
| 161 command = ['hg', '-R', repo.repository, 'cat', '-r', version, os.path.join(rep
o.repository, 'metadata.%s' % repo.type)] | 161 if repo.type == 'android': |
| 162 (result, dummy) = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=sub
process.PIPE).communicate() | 162 command = ['hg', '-R', repo.repository, 'id', '-r', version, '-n'] |
| 163 (result, dummy) = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=s
ubprocess.PIPE).communicate() |
| 164 revision = re.sub(r'\D', '', result) |
| 163 | 165 |
| 164 # Fall back to platform-independent metadata file for now | 166 command = ['hg', '-R', repo.repository, 'cat', '-r', version, os.path.join(r
epo.repository, 'AndroidManifest.xml')] |
| 165 if not result: | 167 (result, dummy) = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=s
ubprocess.PIPE).communicate() |
| 166 command = ['hg', '-R', repo.repository, 'cat', '-r', version, os.path.join(r
epo.repository, 'metadata')] | 168 manifest = dom.parseString(result) |
| 167 (result, dummy) = subprocess.Popen(command, stdout=subprocess.PIPE).communic
ate() | 169 usesSdk = manifest.getElementsByTagName('uses-sdk')[0] |
| 168 | 170 |
| 169 parser = SafeConfigParser() | 171 return { |
| 170 parser.readfp(StringIO(result)) | 172 'revision': revision, |
| 173 'minSdkVersion': usesSdk.attributes["android:minSdkVersion"].value, |
| 174 } |
| 175 else: |
| 176 command = ['hg', '-R', repo.repository, 'cat', '-r', version, os.path.join(r
epo.repository, 'metadata.%s' % repo.type)] |
| 177 (result, dummy) = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=s
ubprocess.PIPE).communicate() |
| 171 | 178 |
| 172 result = { | 179 # Fall back to platform-independent metadata file for now |
| 173 'extensionID': parser.get('general', 'id'), | 180 if not result: |
| 174 'version': version, | 181 command = ['hg', '-R', repo.repository, 'cat', '-r', version, os.path.join
(repo.repository, 'metadata')] |
| 175 'compat': [] | 182 (result, dummy) = subprocess.Popen(command, stdout=subprocess.PIPE).commun
icate() |
| 176 } | 183 |
| 177 for key, value in KNOWN_APPS.iteritems(): | 184 parser = SafeConfigParser() |
| 178 if parser.has_option('compat', key): | 185 parser.readfp(StringIO(result)) |
| 179 minVersion, maxVersion = parser.get('compat', key).split('/') | 186 |
| 180 result['compat'].append({'id': value, 'minVersion': minVersion, 'maxVersio
n': maxVersion}) | 187 result = { |
| 181 return result | 188 'extensionID': parser.get('general', 'id'), |
| 189 'version': version, |
| 190 'compat': [] |
| 191 } |
| 192 for key, value in KNOWN_APPS.iteritems(): |
| 193 if parser.has_option('compat', key): |
| 194 minVersion, maxVersion = parser.get('compat', key).split('/') |
| 195 result['compat'].append({'id': value, 'minVersion': minVersion, 'maxVers
ion': maxVersion}) |
| 196 return result |
| 182 | 197 |
| 183 def writeUpdateManifest(links): | 198 def writeUpdateManifest(links): |
| 184 """ | 199 """ |
| 185 writes an update.rdf file for all Gecko extensions | 200 writes an update manifest for all Gecko extensions and Android apps |
| 186 """ | 201 """ |
| 187 | 202 |
| 188 extensions = [] | 203 extensions = {'gecko': [], 'android': []} |
| 189 for repo in Configuration.getRepositoryConfigurations(): | 204 for repo in Configuration.getRepositoryConfigurations(): |
| 190 if repo.type != 'gecko': | 205 if repo.type not in extensions or not links.has_section(repo.repositoryName)
: |
| 191 continue | |
| 192 if not links.has_section(repo.repositoryName): | |
| 193 continue | 206 continue |
| 194 data = readMetadata(repo, links.get(repo.repositoryName, 'version')) | 207 data = readMetadata(repo, links.get(repo.repositoryName, 'version')) |
| 195 data['updateURL'] = links.get(repo.repositoryName, 'downloadURL') | 208 data['updateURL'] = links.get(repo.repositoryName, 'downloadURL') |
| 196 extensions.append(data) | 209 extensions[repo.type].append(data) |
| 197 | 210 |
| 198 manifestPath = get_config().get('extensions', 'geckoUpdateManifestPath') | 211 if len(extensions['android']) > 1: |
| 199 template = get_template(get_config().get('extensions', 'geckoUpdateManifest')) | 212 print >>sys.stderr, 'Warning: more than one Android app defined, update mani
fest only works for one' |
| 200 template.stream({'extensions': extensions}).dump(manifestPath) | 213 |
| 214 for repoType in extensions.iterkeys(): |
| 215 manifestPath = get_config().get('extensions', '%sUpdateManifestPath' % repoT
ype) |
| 216 template = get_template(get_config().get('extensions', '%sUpdateManifest' %
repoType)) |
| 217 template.stream({'extensions': extensions[repoType]}).dump(manifestPath) |
| 201 | 218 |
| 202 def updateLinks(): | 219 def updateLinks(): |
| 203 """ | 220 """ |
| 204 writes the current extension download links to a file | 221 writes the current extension download links to a file |
| 205 """ | 222 """ |
| 206 | 223 |
| 207 # Update downloads directory first | 224 # Update downloads directory first |
| 208 downloadsRepository = get_config().get('extensions', 'downloadsDirectory') | 225 downloadsRepository = get_config().get('extensions', 'downloadsDirectory') |
| 209 subprocess.Popen(['hg', '-R', downloadsRepository, 'pull', '-u'], stdout=subp
rocess.PIPE).communicate() | 226 subprocess.Popen(['hg', '-R', downloadsRepository, 'pull', '-u'], stdout=subp
rocess.PIPE).communicate() |
| 210 | 227 |
| 211 # Now get download links and save them to file | 228 # Now get download links and save them to file |
| 212 result = SafeConfigParser() | 229 result = SafeConfigParser() |
| 213 getDownloadLinks(result) | 230 getDownloadLinks(result) |
| 214 file = open(get_config().get('extensions', 'downloadLinksFile'), 'wb') | 231 file = open(get_config().get('extensions', 'downloadLinksFile'), 'wb') |
| 215 result.write(file) | 232 result.write(file) |
| 216 file.close() | 233 file.close() |
| 217 | 234 |
| 218 writeUpdateManifest(result) | 235 writeUpdateManifest(result) |
| 219 | 236 |
| 220 if __name__ == "__main__": | 237 if __name__ == "__main__": |
| 221 updateLinks() | 238 updateLinks() |
| OLD | NEW |