| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 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 233 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 244 | 244 |
| 245 | 245 |
| 246 def _urlopen(url, attempts=3): | 246 def _urlopen(url, attempts=3): |
| 247 """ | 247 """ |
| 248 Tries to open a particular URL, retries on failure. | 248 Tries to open a particular URL, retries on failure. |
| 249 """ | 249 """ |
| 250 for i in range(attempts): | 250 for i in range(attempts): |
| 251 try: | 251 try: |
| 252 return urllib.urlopen(url) | 252 return urllib.urlopen(url) |
| 253 except IOError as e: | 253 except IOError as e: |
| 254 error = e | 254 error = Exception('Error {0} while opening {1} url' |
| 255 .format(e, url)) | |
| 255 time.sleep(5) | 256 time.sleep(5) |
| 256 raise error | 257 raise error |
| 257 | 258 |
| 258 | 259 |
| 260 def _parseXMLDocument(url, attempts=2): | |
| 261 for i in range(attempts): | |
| 262 page = _urlopen(url) | |
| 263 content = page.read() | |
| 264 page.close() | |
|
Sebastian Noack
2017/01/17 09:33:32
The close() should have gone into a finally block,
Sebastian Noack
2017/01/17 10:16:56
Yes, in Python 2, the repsonse object returned by
Sebastian Noack
2017/01/17 10:20:15
Well, alternatively you could use try-finally. But
Vasily Kuznetsov
2017/01/17 10:30:34
Yeah, with is nicer, especially having Python 3 in
| |
| 265 try: | |
| 266 return dom.parseString(content) | |
| 267 except ExpatError as err: | |
| 268 exception = Exception('Error {0} while parsing xml:\n{1}\nfrom {2}' | |
| 269 .format(err, content, url)) | |
| 270 raise exception | |
| 271 | |
| 272 | |
| 259 def _getMozillaDownloadLink(galleryID): | 273 def _getMozillaDownloadLink(galleryID): |
| 260 """ | 274 """ |
| 261 gets download link for a Gecko add-on from the Mozilla Addons site | 275 gets download link for a Gecko add-on from the Mozilla Addons site |
| 262 """ | 276 """ |
| 263 url = 'https://services.addons.mozilla.org/en-US/firefox/api/1/addon/%s' % _ urlencode(galleryID) | 277 url = 'https://services.addons.mozilla.org/en-US/firefox/api/1/addon/%s' % _ urlencode(galleryID) |
| 264 document = dom.parse(_urlopen(url)) | 278 document = _parseXMLDocument(url) |
| 265 linkTags = document.getElementsByTagName('install') | 279 linkTags = document.getElementsByTagName('install') |
| 266 linkTag = linkTags[0] if len(linkTags) > 0 else None | 280 linkTag = linkTags[0] if len(linkTags) > 0 else None |
| 267 versionTags = document.getElementsByTagName('version') | 281 versionTags = document.getElementsByTagName('version') |
| 268 versionTag = versionTags[0] if len(versionTags) > 0 else None | 282 versionTag = versionTags[0] if len(versionTags) > 0 else None |
| 269 if linkTag and versionTag and linkTag.firstChild and versionTag.firstChild: | 283 if linkTag and versionTag and linkTag.firstChild and versionTag.firstChild: |
| 270 return (linkTag.firstChild.data, versionTag.firstChild.data) | 284 return (linkTag.firstChild.data, versionTag.firstChild.data) |
| 271 else: | 285 else: |
| 272 return (None, None) | 286 return (None, None) |
| 273 | 287 |
| 274 | 288 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 314 """ | 328 """ |
| 315 gets the download links for all extensions and puts them into the config | 329 gets the download links for all extensions and puts them into the config |
| 316 object | 330 object |
| 317 """ | 331 """ |
| 318 for repo in Configuration.getRepositoryConfigurations(): | 332 for repo in Configuration.getRepositoryConfigurations(): |
| 319 try: | 333 try: |
| 320 (downloadURL, version) = _getDownloadLink(repo) | 334 (downloadURL, version) = _getDownloadLink(repo) |
| 321 if downloadURL is None: | 335 if downloadURL is None: |
| 322 raise Exception('No download link found for repo: ' + | 336 raise Exception('No download link found for repo: ' + |
| 323 repo.repositoryName) | 337 repo.repositoryName) |
| 324 except ExpatError: | |
| 325 traceback.print_exc() | |
| 326 print "Error found while parsing xml from %s link" % repo.repository Name | |
|
Jon Sonesen
2017/01/09 07:48:22
Here you should be using the .format() method for
Jon Sonesen
2017/01/09 08:44:10
Oops, I also just noticed that you are using doubl
f.nicolaisen
2017/01/10 08:58:04
This adds some context (i.e. which repo) to the er
| |
| 327 continue | |
| 328 except: | 338 except: |
| 329 traceback.print_exc() | 339 traceback.print_exc() |
| 330 continue | 340 continue |
| 331 if not result.has_section(repo.repositoryName): | 341 if not result.has_section(repo.repositoryName): |
| 332 result.add_section(repo.repositoryName) | 342 result.add_section(repo.repositoryName) |
| 333 result.set(repo.repositoryName, 'downloadURL', downloadURL) | 343 result.set(repo.repositoryName, 'downloadURL', downloadURL) |
| 334 result.set(repo.repositoryName, 'version', version) | 344 result.set(repo.repositoryName, 'version', version) |
| 335 | 345 |
| 336 qrcode = _getQRCode(downloadURL) | 346 qrcode = _getQRCode(downloadURL) |
| 337 if qrcode is not None: | 347 if qrcode is not None: |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 384 if not extensions: | 394 if not extensions: |
| 385 return | 395 return |
| 386 | 396 |
| 387 updates = {} | 397 updates = {} |
| 388 for extension in extensions: | 398 for extension in extensions: |
| 389 updates[extension['basename']] = { | 399 updates[extension['basename']] = { |
| 390 'url': extension['updateURL'], | 400 'url': extension['updateURL'], |
| 391 'version': extension['version'] | 401 'version': extension['version'] |
| 392 } | 402 } |
| 393 writeLibabpUpdateManifest(path, updates) | 403 writeLibabpUpdateManifest(path, updates) |
| LEFT | RIGHT |