Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code

Side by Side Diff: sitescripts/extensions/bin/updateDownloadLinks.py

Issue 6282067956465664: Issue 399 - Added support for Safari to updateDownloadLinks (Closed)
Patch Set: Addressed comments Created April 30, 2014, 12:21 p.m.
Left:
Right:
Use n/p to move between diff chunks; N/P to move between comments.
Jump to:
View unified diff | Download patch
« no previous file with comments | « sitescripts/extensions/bin/createNightlies.py ('k') | sitescripts/extensions/utils.py » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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
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
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 genericFilename = 'metadata'
181 filename = '%s.%s' % (genericFilename, repo.type)
182
183 # Fall back to platform-independent metadata file
184 if filename not in files:
185 filename = genericFilename
186
187 command = ['hg', '-R', repo.repository, 'cat', '-r', version, os.path.join(rep o.repository, filename)]
188 result = subprocess.check_output(command)
189
190 parser = SafeConfigParser()
191 parser.readfp(StringIO(result))
192
193 return parser
194
173 def readMetadata(repo, version): 195 def readMetadata(repo, version):
174 """ 196 """
175 reads extension ID and compatibility information from metadata file in the 197 reads extension ID and compatibility information from metadata file in the
176 extension's repository 198 extension's repository
177 """ 199 """
178 if repo.type == 'android': 200 if repo.type == 'android':
179 command = ['hg', '-R', repo.repository, 'id', '-r', version, '-n'] 201 command = ['hg', '-R', repo.repository, 'id', '-r', version, '-n']
180 result = subprocess.check_output(command) 202 result = subprocess.check_output(command)
181 revision = re.sub(r'\D', '', result) 203 revision = re.sub(r'\D', '', result)
182 204
183 command = ['hg', '-R', repo.repository, 'cat', '-r', version, os.path.join(r epo.repository, 'AndroidManifest.xml')] 205 command = ['hg', '-R', repo.repository, 'cat', '-r', version, os.path.join(r epo.repository, 'AndroidManifest.xml')]
184 result = subprocess.check_output(command) 206 result = subprocess.check_output(command)
185 manifest = dom.parseString(result) 207 manifest = dom.parseString(result)
186 usesSdk = manifest.getElementsByTagName('uses-sdk')[0] 208 usesSdk = manifest.getElementsByTagName('uses-sdk')[0]
187 209
188 return { 210 return {
189 'revision': revision, 211 'revision': revision,
190 'minSdkVersion': usesSdk.attributes["android:minSdkVersion"].value, 212 'minSdkVersion': usesSdk.attributes["android:minSdkVersion"].value,
191 } 213 }
192 else: 214 elif repo.type == 'safari':
193 files = subprocess.check_output(['hg', '-R', repo.repository, 'locate', '-r' , version]).splitlines() 215 metadata = readRawMetadata(repo, version)
194 if 'metadata.%s' % repo.type in files: 216 return {
195 command = ['hg', '-R', repo.repository, 'cat', '-r', version, os.path.join (repo.repository, 'metadata.%s' % repo.type)] 217 'certificateID': getSafariCertificateID(repo.keyFile),
196 result = subprocess.check_output(command) 218 'version': version,
197 else: 219 'shortVersion': version,
198 # Fall back to platform-independent metadata file for now 220 'basename': metadata.get('general', 'basename'),
199 command = ['hg', '-R', repo.repository, 'cat', '-r', version, os.path.join (repo.repository, 'metadata')] 221 }
200 result = subprocess.check_output(command) 222 elif repo.type == 'gecko':
201 223 metadata = readRawMetadata(repo, version)
202 parser = SafeConfigParser()
203 parser.readfp(StringIO(result))
204
205 result = { 224 result = {
206 'extensionID': parser.get('general', 'id'), 225 'extensionID': metadata.get('general', 'id'),
207 'version': version, 226 'version': version,
208 'compat': [] 227 'compat': []
209 } 228 }
210 for key, value in KNOWN_APPS.iteritems(): 229 for key, value in KNOWN_APPS.iteritems():
211 if parser.has_option('compat', key): 230 if metadata.has_option('compat', key):
212 minVersion, maxVersion = parser.get('compat', key).split('/') 231 minVersion, maxVersion = metadata.get('compat', key).split('/')
213 result['compat'].append({'id': value, 'minVersion': minVersion, 'maxVers ion': maxVersion}) 232 result['compat'].append({'id': value, 'minVersion': minVersion, 'maxVers ion': maxVersion})
214 return result 233 return result
234 else:
235 raise Exception('unknown repository type %r' % repo.type)
215 236
216 def writeUpdateManifest(links): 237 def writeUpdateManifest(links):
217 """ 238 """
218 writes an update manifest for all Gecko extensions and Android apps 239 writes an update manifest for all Gecko extensions and Android apps
219 """ 240 """
220 241
221 extensions = {'gecko': [], 'android': []} 242 extensions = {'gecko': [], 'android': [], 'safari': []}
222 for repo in Configuration.getRepositoryConfigurations(): 243 for repo in Configuration.getRepositoryConfigurations():
223 if repo.type not in extensions or not links.has_section(repo.repositoryName) : 244 if repo.type not in extensions or not links.has_section(repo.repositoryName) :
224 continue 245 continue
225 data = readMetadata(repo, links.get(repo.repositoryName, 'version')) 246 data = readMetadata(repo, links.get(repo.repositoryName, 'version'))
226 data['updateURL'] = links.get(repo.repositoryName, 'downloadURL') 247 data['updateURL'] = links.get(repo.repositoryName, 'downloadURL')
227 if data['updateURL'].startswith(repo.downloadsURL): 248 if data['updateURL'].startswith(repo.downloadsURL):
228 data['updateURL'] += "?update" 249 data['updateURL'] += "?update"
229 extensions[repo.type].append(data) 250 extensions[repo.type].append(data)
230 251
231 if len(extensions['android']) > 1: 252 if len(extensions['android']) > 1:
(...skipping 13 matching lines...) Expand all
245 result = SafeConfigParser() 266 result = SafeConfigParser()
246 getDownloadLinks(result) 267 getDownloadLinks(result)
247 file = open(get_config().get('extensions', 'downloadLinksFile'), 'wb') 268 file = open(get_config().get('extensions', 'downloadLinksFile'), 'wb')
248 result.write(file) 269 result.write(file)
249 file.close() 270 file.close()
250 271
251 writeUpdateManifest(result) 272 writeUpdateManifest(result)
252 273
253 if __name__ == "__main__": 274 if __name__ == "__main__":
254 updateLinks() 275 updateLinks()
OLDNEW
« no previous file with comments | « sitescripts/extensions/bin/createNightlies.py ('k') | sitescripts/extensions/utils.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld