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

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

Issue 29345242: Noissue - Adapt quotes for compliance with our coding style in sitescripts (Closed)
Patch Set: Fixed raw string Created May 30, 2016, 8:47 a.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 # This file is part of the Adblock Plus web scripts, 1 # This file is part of the Adblock Plus web scripts,
2 # Copyright (C) 2006-2016 Eyeo GmbH 2 # Copyright (C) 2006-2016 Eyeo GmbH
3 # 3 #
4 # Adblock Plus is free software: you can redistribute it and/or modify 4 # Adblock Plus is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License version 3 as 5 # it under the terms of the GNU General Public License version 3 as
6 # published by the Free Software Foundation. 6 # published by the Free Software Foundation.
7 # 7 #
8 # Adblock Plus is distributed in the hope that it will be useful, 8 # Adblock Plus is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of 9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
(...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after
221 def getRepositoryConfigurations(nightlyConfig=None): 221 def getRepositoryConfigurations(nightlyConfig=None):
222 """ 222 """
223 Retrieves configuration settings for all repositories 223 Retrieves configuration settings for all repositories
224 from the configuration file, where existing repositories 224 from the configuration file, where existing repositories
225 are identified by an <id>_repository entry appearing 225 are identified by an <id>_repository entry appearing
226 in the configuration file. 226 in the configuration file.
227 This static method will enumerate Configuration 227 This static method will enumerate Configuration
228 objects representing the settings for each repository. 228 objects representing the settings for each repository.
229 """ 229 """
230 config = get_config() 230 config = get_config()
231 for key, value in config.items("extensions"): 231 for key, value in config.items('extensions'):
232 if key.endswith("_repository"): 232 if key.endswith('_repository'):
233 repositoryName = re.sub(r'_repository$', '', key) 233 repositoryName = re.sub(r'_repository$', '', key)
234 if repositoryName: 234 if repositoryName:
235 yield Configuration(config, nightlyConfig, repositoryName, v alue) 235 yield Configuration(config, nightlyConfig, repositoryName, v alue)
236 236
237 237
238 def _urlencode(value): 238 def _urlencode(value):
239 return urllib.quote(value.encode('utf-8'), '') 239 return urllib.quote(value.encode('utf-8'), '')
240 240
241 241
242 def _urlopen(url, attempts=3): 242 def _urlopen(url, attempts=3):
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
281 highestURL = urlparse.urljoin(repo.downloadsURL, filename) 281 highestURL = urlparse.urljoin(repo.downloadsURL, filename)
282 highestVersion = version 282 highestVersion = version
283 283
284 return (highestURL, highestVersion) 284 return (highestURL, highestVersion)
285 285
286 286
287 def _getDownloadLink(repo): 287 def _getDownloadLink(repo):
288 """ 288 """
289 gets the download link to the most current version of an extension 289 gets the download link to the most current version of an extension
290 """ 290 """
291 if repo.galleryID and repo.type == "gecko": 291 if repo.galleryID and repo.type == 'gecko':
292 return _getMozillaDownloadLink(repo.galleryID) 292 return _getMozillaDownloadLink(repo.galleryID)
293 return _getLocalLink(repo) 293 return _getLocalLink(repo)
294 294
295 295
296 def _getQRCode(text): 296 def _getQRCode(text):
297 try: 297 try:
298 import qrcode 298 import qrcode
299 import base64 299 import base64
300 import Image # required by qrcode but not formally a dependency 300 import Image # required by qrcode but not formally a dependency
301 except: 301 except:
302 return None 302 return None
303 303
304 data = StringIO() 304 data = StringIO()
305 qrcode.make(text, box_size=5).save(data, 'png') 305 qrcode.make(text, box_size=5).save(data, 'png')
306 return 'data:image/png;base64,' + base64.b64encode(data.getvalue()) 306 return 'data:image/png;base64,' + base64.b64encode(data.getvalue())
307 307
308 308
309 def getDownloadLinks(result): 309 def getDownloadLinks(result):
310 """ 310 """
311 gets the download links for all extensions and puts them into the config 311 gets the download links for all extensions and puts them into the config
312 object 312 object
313 """ 313 """
314 for repo in Configuration.getRepositoryConfigurations(): 314 for repo in Configuration.getRepositoryConfigurations():
315 (downloadURL, version) = _getDownloadLink(repo) 315 (downloadURL, version) = _getDownloadLink(repo)
316 if downloadURL == None: 316 if downloadURL == None:
317 continue 317 continue
318 if not result.has_section(repo.repositoryName): 318 if not result.has_section(repo.repositoryName):
319 result.add_section(repo.repositoryName) 319 result.add_section(repo.repositoryName)
320 result.set(repo.repositoryName, "downloadURL", downloadURL) 320 result.set(repo.repositoryName, 'downloadURL', downloadURL)
321 result.set(repo.repositoryName, "version", version) 321 result.set(repo.repositoryName, 'version', version)
322 322
323 qrcode = _getQRCode(downloadURL) 323 qrcode = _getQRCode(downloadURL)
324 if qrcode != None: 324 if qrcode != None:
325 result.set(repo.repositoryName, "qrcode", qrcode) 325 result.set(repo.repositoryName, 'qrcode', qrcode)
326 326
327 327
328 def writeLibabpUpdateManifest(path, updates): 328 def writeLibabpUpdateManifest(path, updates):
329 """ 329 """
330 Writes update.json file for libadblockplus 330 Writes update.json file for libadblockplus
331 """ 331 """
332 332
333 baseDir = os.path.dirname(path) 333 baseDir = os.path.dirname(path)
334 if not os.path.exists(baseDir): 334 if not os.path.exists(baseDir):
335 os.makedirs(baseDir) 335 os.makedirs(baseDir)
336 336
337 handle = codecs.open(path, "wb", encoding="UTF-8") 337 handle = codecs.open(path, 'wb', encoding='UTF-8')
338 json.dump(updates, handle, ensure_ascii=False, indent=2, separators=(",", ": ")) 338 json.dump(updates, handle, ensure_ascii=False, indent=2, separators=(',', ': '))
339 handle.close() 339 handle.close()
340 340
341 341
342 def writeIEUpdateManifest(path, extensions): 342 def writeIEUpdateManifest(path, extensions):
343 """ 343 """
344 Writes update.json for IE 344 Writes update.json for IE
345 """ 345 """
346 346
347 if not extensions: 347 if not extensions:
348 return 348 return
349 349
350 updates = {} 350 updates = {}
351 for extension in extensions: 351 for extension in extensions:
352 basename = extension['basename'] 352 basename = extension['basename']
353 updateURL = extension['updateURL'] 353 updateURL = extension['updateURL']
354 version = extension['version'] 354 version = extension['version']
355 updates["%s/%s" % (basename, "msie64")] = { 355 updates['%s/%s' % (basename, 'msie64')] = {
356 "url": updateURL.replace(".exe", "-x64.msi"), 356 'url': updateURL.replace('.exe', '-x64.msi'),
357 "version": version 357 'version': version
358 } 358 }
359 updates["%s/%s" % (basename, "msie32")] = { 359 updates['%s/%s' % (basename, 'msie32')] = {
360 "url": updateURL.replace(".exe", "-x86.msi"), 360 'url': updateURL.replace('.exe', '-x86.msi'),
361 "version": version 361 'version': version
362 } 362 }
363 writeLibabpUpdateManifest(path, updates) 363 writeLibabpUpdateManifest(path, updates)
364 364
365 365
366 def writeAndroidUpdateManifest(path, extensions): 366 def writeAndroidUpdateManifest(path, extensions):
367 """ 367 """
368 Writes update.json for Android 368 Writes update.json for Android
369 """ 369 """
370 370
371 if not extensions: 371 if not extensions:
372 return 372 return
373 373
374 updates = {} 374 updates = {}
375 for extension in extensions: 375 for extension in extensions:
376 updates[extension['basename']] = { 376 updates[extension['basename']] = {
377 "url": extension['updateURL'], 377 'url': extension['updateURL'],
378 "version": extension['version'] 378 'version': extension['version']
379 } 379 }
380 writeLibabpUpdateManifest(path, updates) 380 writeLibabpUpdateManifest(path, updates)
OLDNEW

Powered by Google App Engine
This is Rietveld