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

Side by Side Diff: sitescripts/extensions/utils.py

Issue 29337977: Issue 3758 - Removed Opera Extensions related logic (Closed)
Patch Set: Created March 8, 2016, 5:15 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
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-2016 Eyeo GmbH 4 # Copyright (C) 2006-2016 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 codecs 18 import codecs
19 import os 19 import os
20 import json 20 import json
21 import re 21 import re
22 import subprocess 22 import subprocess
23 import time 23 import time
24 import urlparse 24 import urlparse
25 import urllib 25 import urllib
26 import urllib2
27 import xml.dom.minidom as dom 26 import xml.dom.minidom as dom
28 from ConfigParser import SafeConfigParser, NoOptionError 27 from ConfigParser import SafeConfigParser, NoOptionError
29 from StringIO import StringIO 28 from StringIO import StringIO
30 from sitescripts.utils import get_config 29 from sitescripts.utils import get_config
31 30
31 PACKAGE_SUFFIXES = {
32 'gecko': '.xpi',
33 'chrome': '.crx',
34 'safari': '.safariextz',
35 'ie': '.exe',
36 'android': '.apk'
37 }
38
32 def compareVersionParts(part1, part2): 39 def compareVersionParts(part1, part2):
33 def convertInt(value, default): 40 def convertInt(value, default):
34 try: 41 try:
35 return int(value) 42 return int(value)
36 except ValueError: 43 except ValueError:
37 return default 44 return default
38 45
39 def convertVersionPart(part): 46 def convertVersionPart(part):
40 if part == '*': 47 if part == '*':
41 # Special case - * is interpreted as Infinity 48 # Special case - * is interpreted as Infinity
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 163
157 self.repositoryName = repositoryName 164 self.repositoryName = repositoryName
158 self.repository = repository 165 self.repository = repository
159 self.config = config 166 self.config = config
160 self.nightlyConfig = nightlyConfig 167 self.nightlyConfig = nightlyConfig
161 168
162 if self.config.has_option('extensions', self.repositoryName + '_type'): 169 if self.config.has_option('extensions', self.repositoryName + '_type'):
163 self.type = self.config.get('extensions', self.repositoryName + '_type') 170 self.type = self.config.get('extensions', self.repositoryName + '_type')
164 else: 171 else:
165 self.type = 'gecko' 172 self.type = 'gecko'
166 173 self.packageSuffix = PACKAGE_SUFFIXES[self.type]
167 if self.type == 'gecko':
168 self.packageSuffix = '.xpi'
169 elif self.type == 'chrome' or self.type == 'opera':
170 self.packageSuffix = '.crx'
171 elif self.type == 'safari':
172 self.packageSuffix = '.safariextz'
173 elif self.type == 'ie':
174 self.packageSuffix = '.exe'
175 elif self.type == 'android':
176 self.packageSuffix = '.apk'
177 174
178 if self.nightlyConfig and not self.nightlyConfig.has_section(self.repository Name): 175 if self.nightlyConfig and not self.nightlyConfig.has_section(self.repository Name):
179 self.nightlyConfig.add_section(self.repositoryName) 176 self.nightlyConfig.add_section(self.repositoryName)
180 177
181 def __str__(self): 178 def __str__(self):
182 """ 179 """
183 Provides a string representation of this configuration 180 Provides a string representation of this configuration
184 """ 181 """
185 return self.repositoryName 182 return self.repositoryName
186 183
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after
260 document = dom.parse(_urlopen(url)) 257 document = dom.parse(_urlopen(url))
261 linkTags = document.getElementsByTagName('install') 258 linkTags = document.getElementsByTagName('install')
262 linkTag = linkTags[0] if len(linkTags) > 0 else None 259 linkTag = linkTags[0] if len(linkTags) > 0 else None
263 versionTags = document.getElementsByTagName('version') 260 versionTags = document.getElementsByTagName('version')
264 versionTag = versionTags[0] if len(versionTags) > 0 else None 261 versionTag = versionTags[0] if len(versionTags) > 0 else None
265 if linkTag and versionTag and linkTag.firstChild and versionTag.firstChild: 262 if linkTag and versionTag and linkTag.firstChild and versionTag.firstChild:
266 return (linkTag.firstChild.data, versionTag.firstChild.data) 263 return (linkTag.firstChild.data, versionTag.firstChild.data)
267 else: 264 else:
268 return (None, None) 265 return (None, None)
269 266
270 def _getGoogleDownloadLink(galleryID):
Sebastian Noack 2016/03/08 17:23:05 For reference, the web store URLs are hard-coded o
271 """
272 gets download link for a Chrome add-on from the Chrome Gallery site
273 """
274 galleryID = _urlencode(galleryID)
275
276 url = 'https://clients2.google.com/service/update2/crx?x=%s' % _urlencode('id= %s&uc' % galleryID)
277 document = dom.parse(_urlopen(url))
278 updateTags = document.getElementsByTagName('updatecheck')
279 version = updateTags and updateTags[0].getAttribute('version')
280
281 if not version:
282 return (None, None)
283
284 request = urllib2.Request('https://chrome.google.com/webstore/detail/_/' + gal leryID)
285 request.get_method = lambda : 'HEAD'
286 url = urllib2.urlopen(request).geturl()
287
288 return (url, version)
289
290 def _getOperaDownloadLink(galleryID):
291 """
292 gets download link for an Opera add-on from the Opera Addons site
293 """
294 galleryID = _urlencode(galleryID)
295
296 request = urllib2.Request('https://addons.opera.com/extensions/download/%s/' % galleryID)
297 request.get_method = lambda : 'HEAD'
298 response = urllib2.urlopen(request)
299
300 content_disposition = response.info().getheader('Content-Disposition')
301 if content_disposition:
302 match = re.search(r'filename=\S+-([\d.]+)-\d+\.crx$', content_disposition)
303 if match:
304 return ('https://addons.opera.com/extensions/details/%s/' % galleryID , ma tch.group(1))
305
306 return (None, None)
307
308 def _getLocalLink(repo): 267 def _getLocalLink(repo):
309 """ 268 """
310 gets the link for the newest download of an add-on in the local downloads 269 gets the link for the newest download of an add-on in the local downloads
311 repository 270 repository
312 """ 271 """
313 highestURL = None 272 highestURL = None
314 highestVersion = None 273 highestVersion = None
315 274
316 for filename, version in repo.getDownloads(): 275 for filename, version in repo.getDownloads():
317 if not highestVersion or compareVersions(version, highestVersion) > 0: 276 if not highestVersion or compareVersions(version, highestVersion) > 0:
318 highestURL = urlparse.urljoin(repo.downloadsURL, filename) 277 highestURL = urlparse.urljoin(repo.downloadsURL, filename)
319 highestVersion = version 278 highestVersion = version
320 279
321 return (highestURL, highestVersion) 280 return (highestURL, highestVersion)
322 281
323 def _getDownloadLink(repo): 282 def _getDownloadLink(repo):
324 """ 283 """
325 gets the download link to the most current version of an extension 284 gets the download link to the most current version of an extension
326 """ 285 """
327 if repo.galleryID: 286 if repo.galleryID and repo.type == "gecko":
328 if repo.type == "chrome": 287 return _getMozillaDownloadLink(repo.galleryID)
329 return _getGoogleDownloadLink(repo.galleryID)
330 elif repo.type == "opera":
331 return _getOperaDownloadLink(repo.galleryID)
332 elif repo.type == "gecko":
333 return _getMozillaDownloadLink(repo.galleryID)
334
335 return _getLocalLink(repo) 288 return _getLocalLink(repo)
336 289
337 def _getQRCode(text): 290 def _getQRCode(text):
338 try: 291 try:
339 import qrcode 292 import qrcode
340 import base64 293 import base64
341 import Image # required by qrcode but not formally a dependency 294 import Image # required by qrcode but not formally a dependency
342 except: 295 except:
343 return None 296 return None
344 297
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
408 if not extensions: 361 if not extensions:
409 return 362 return
410 363
411 updates = {} 364 updates = {}
412 for extension in extensions: 365 for extension in extensions:
413 updates[extension['basename']] = { 366 updates[extension['basename']] = {
414 "url": extension['updateURL'], 367 "url": extension['updateURL'],
415 "version": extension['version'] 368 "version": extension['version']
416 } 369 }
417 writeLibabpUpdateManifest(path, updates) 370 writeLibabpUpdateManifest(path, updates)
OLDNEW
« sitescripts/extensions/bin/createNightlies.py ('K') | « sitescripts/extensions/template/updates.xml ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld