Left: | ||
Right: |
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, |
(...skipping 10 matching lines...) Expand all Loading... | |
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, 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, getSafa riCertificateID |
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 |
37 def urlopen(url, attempts=3): | 37 def urlopen(url, attempts=3): |
38 """ | 38 """ |
39 Tries to open a particular URL, retries on failure. | 39 Tries to open a particular URL, retries on failure. |
40 """ | 40 """ |
41 for i in range(attempts): | 41 for i in range(attempts): |
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
99 | 99 |
100 def getLocalLink(repo): | 100 def getLocalLink(repo): |
101 """ | 101 """ |
102 gets the link for the newest download of an add-on in the local downloads | 102 gets the link for the newest download of an add-on in the local downloads |
103 repository | 103 repository |
104 """ | 104 """ |
105 url = repo.downloadsURL | 105 url = repo.downloadsURL |
106 | 106 |
107 highestURL = None | 107 highestURL = None |
108 highestVersion = None | 108 highestVersion = None |
109 prefix = os.path.basename(repo.repository) + '-' | 109 |
110 if repo.type == 'android': | |
111 prefix = os.path.basename(repo.repository) | |
112 else: | |
113 prefix = readRawMetadata(repo).get('general', 'basename') | |
114 prefix += '-' | |
110 suffix = repo.packageSuffix | 115 suffix = repo.packageSuffix |
111 | 116 |
112 # go through the downloads repository looking for downloads matching this exte nsion | 117 # go through the downloads repository looking for downloads matching this exte nsion |
113 command = ['hg', 'locate', '-R', repo.downloadsRepo, '-r', 'default'] | 118 command = ['hg', 'locate', '-R', repo.downloadsRepo, '-r', 'default'] |
114 result = subprocess.check_output(command) | 119 result = subprocess.check_output(command) |
115 for fileName in result.splitlines(): | 120 for fileName in result.splitlines(): |
116 if fileName.startswith(prefix) and fileName.endswith(suffix): | 121 if fileName.startswith(prefix) and fileName.endswith(suffix): |
117 version = fileName[len(prefix):len(fileName) - len(suffix)] | 122 version = fileName[len(prefix):len(fileName) - len(suffix)] |
118 if highestVersion == None or compareVersions(version, highestVersion) > 0: | 123 if highestVersion == None or compareVersions(version, highestVersion) > 0: |
119 highestURL = urlparse.urljoin(url, fileName) | 124 highestURL = urlparse.urljoin(url, fileName) |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
163 continue | 168 continue |
164 if not result.has_section(repo.repositoryName): | 169 if not result.has_section(repo.repositoryName): |
165 result.add_section(repo.repositoryName) | 170 result.add_section(repo.repositoryName) |
166 result.set(repo.repositoryName, "downloadURL", downloadURL) | 171 result.set(repo.repositoryName, "downloadURL", downloadURL) |
167 result.set(repo.repositoryName, "version", version) | 172 result.set(repo.repositoryName, "version", version) |
168 | 173 |
169 qrcode = getQRCode(downloadURL) | 174 qrcode = getQRCode(downloadURL) |
170 if qrcode != None: | 175 if qrcode != None: |
171 result.set(repo.repositoryName, "qrcode", qrcode) | 176 result.set(repo.repositoryName, "qrcode", qrcode) |
172 | 177 |
178 def readRawMetadata(repo, version='tip'): | |
179 files = subprocess.check_output(['hg', '-R', repo.repository, 'locate', '-r', version]).splitlines() | |
180 if 'metadata.%s' % repo.type in files: | |
181 command = ['hg', '-R', repo.repository, 'cat', '-r', version, os.path.join(r epo.repository, 'metadata.%s' % repo.type)] | |
182 result = subprocess.check_output(command) | |
183 else: | |
184 # Fall back to platform-independent metadata file for now | |
185 command = ['hg', '-R', repo.repository, 'cat', '-r', version, os.path.join(r epo.repository, 'metadata')] | |
186 result = subprocess.check_output(command) | |
Wladimir Palant
2014/04/30 11:50:57
Nit: You only copied that code but |result = subpr
Sebastian Noack
2014/04/30 12:21:45
Even better, just generating the manifest filename
| |
187 | |
188 parser = SafeConfigParser() | |
189 parser.readfp(StringIO(result)) | |
190 | |
191 return parser | |
192 | |
173 def readMetadata(repo, version): | 193 def readMetadata(repo, version): |
174 """ | 194 """ |
175 reads extension ID and compatibility information from metadata file in the | 195 reads extension ID and compatibility information from metadata file in the |
176 extension's repository | 196 extension's repository |
177 """ | 197 """ |
178 if repo.type == 'android': | 198 if repo.type == 'android': |
179 command = ['hg', '-R', repo.repository, 'id', '-r', version, '-n'] | 199 command = ['hg', '-R', repo.repository, 'id', '-r', version, '-n'] |
180 result = subprocess.check_output(command) | 200 result = subprocess.check_output(command) |
181 revision = re.sub(r'\D', '', result) | 201 revision = re.sub(r'\D', '', result) |
182 | 202 |
183 command = ['hg', '-R', repo.repository, 'cat', '-r', version, os.path.join(r epo.repository, 'AndroidManifest.xml')] | 203 command = ['hg', '-R', repo.repository, 'cat', '-r', version, os.path.join(r epo.repository, 'AndroidManifest.xml')] |
184 result = subprocess.check_output(command) | 204 result = subprocess.check_output(command) |
185 manifest = dom.parseString(result) | 205 manifest = dom.parseString(result) |
186 usesSdk = manifest.getElementsByTagName('uses-sdk')[0] | 206 usesSdk = manifest.getElementsByTagName('uses-sdk')[0] |
187 | 207 |
188 return { | 208 return { |
189 'revision': revision, | 209 'revision': revision, |
190 'minSdkVersion': usesSdk.attributes["android:minSdkVersion"].value, | 210 'minSdkVersion': usesSdk.attributes["android:minSdkVersion"].value, |
191 } | 211 } |
212 elif repo.type == 'safari': | |
213 metadata = readRawMetadata(repo, version) | |
214 return { | |
215 'certificateID': getSafariCertificateID(repo.keyFile), | |
216 'version': version, | |
217 'shortVersion': version, | |
218 'basename': metadata.get('general', 'basename'), | |
219 } | |
192 else: | 220 else: |
Wladimir Palant
2014/04/30 11:50:57
Nit: Please check |repo.type == 'gecko'| explicitl
Sebastian Noack
2014/04/30 12:21:45
Done.
| |
193 files = subprocess.check_output(['hg', '-R', repo.repository, 'locate', '-r' , version]).splitlines() | 221 metadata = readRawMetadata(repo, version) |
194 if 'metadata.%s' % repo.type in files: | |
195 command = ['hg', '-R', repo.repository, 'cat', '-r', version, os.path.join (repo.repository, 'metadata.%s' % repo.type)] | |
196 result = subprocess.check_output(command) | |
197 else: | |
198 # Fall back to platform-independent metadata file for now | |
199 command = ['hg', '-R', repo.repository, 'cat', '-r', version, os.path.join (repo.repository, 'metadata')] | |
200 result = subprocess.check_output(command) | |
201 | |
202 parser = SafeConfigParser() | |
203 parser.readfp(StringIO(result)) | |
204 | |
205 result = { | 222 result = { |
206 'extensionID': parser.get('general', 'id'), | 223 'extensionID': metadata.get('general', 'id'), |
207 'version': version, | 224 'version': version, |
208 'compat': [] | 225 'compat': [] |
209 } | 226 } |
210 for key, value in KNOWN_APPS.iteritems(): | 227 for key, value in KNOWN_APPS.iteritems(): |
211 if parser.has_option('compat', key): | 228 if metadata.has_option('compat', key): |
212 minVersion, maxVersion = parser.get('compat', key).split('/') | 229 minVersion, maxVersion = metadata.get('compat', key).split('/') |
213 result['compat'].append({'id': value, 'minVersion': minVersion, 'maxVers ion': maxVersion}) | 230 result['compat'].append({'id': value, 'minVersion': minVersion, 'maxVers ion': maxVersion}) |
214 return result | 231 return result |
215 | 232 |
216 def writeUpdateManifest(links): | 233 def writeUpdateManifest(links): |
217 """ | 234 """ |
218 writes an update manifest for all Gecko extensions and Android apps | 235 writes an update manifest for all Gecko extensions and Android apps |
219 """ | 236 """ |
220 | 237 |
221 extensions = {'gecko': [], 'android': []} | 238 extensions = {'gecko': [], 'android': [], 'safari': []} |
222 for repo in Configuration.getRepositoryConfigurations(): | 239 for repo in Configuration.getRepositoryConfigurations(): |
223 if repo.type not in extensions or not links.has_section(repo.repositoryName) : | 240 if repo.type not in extensions or not links.has_section(repo.repositoryName) : |
224 continue | 241 continue |
225 data = readMetadata(repo, links.get(repo.repositoryName, 'version')) | 242 data = readMetadata(repo, links.get(repo.repositoryName, 'version')) |
226 data['updateURL'] = links.get(repo.repositoryName, 'downloadURL') | 243 data['updateURL'] = links.get(repo.repositoryName, 'downloadURL') |
227 if data['updateURL'].startswith(repo.downloadsURL): | 244 if data['updateURL'].startswith(repo.downloadsURL): |
228 data['updateURL'] += "?update" | 245 data['updateURL'] += "?update" |
229 extensions[repo.type].append(data) | 246 extensions[repo.type].append(data) |
230 | 247 |
231 if len(extensions['android']) > 1: | 248 if len(extensions['android']) > 1: |
(...skipping 13 matching lines...) Expand all Loading... | |
245 result = SafeConfigParser() | 262 result = SafeConfigParser() |
246 getDownloadLinks(result) | 263 getDownloadLinks(result) |
247 file = open(get_config().get('extensions', 'downloadLinksFile'), 'wb') | 264 file = open(get_config().get('extensions', 'downloadLinksFile'), 'wb') |
248 result.write(file) | 265 result.write(file) |
249 file.close() | 266 file.close() |
250 | 267 |
251 writeUpdateManifest(result) | 268 writeUpdateManifest(result) |
252 | 269 |
253 if __name__ == "__main__": | 270 if __name__ == "__main__": |
254 updateLinks() | 271 updateLinks() |
OLD | NEW |