| Left: | ||
| Right: |
| LEFT | RIGHT |
|---|---|
| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 63 return (linkTag.firstChild.data, versionTag.firstChild.data) | 63 return (linkTag.firstChild.data, versionTag.firstChild.data) |
| 64 else: | 64 else: |
| 65 return (None, None) | 65 return (None, None) |
| 66 | 66 |
| 67 def getGoogleDownloadLink(galleryID): | 67 def getGoogleDownloadLink(galleryID): |
| 68 """ | 68 """ |
| 69 gets download link for a Chrome add-on from the Chrome Gallery site | 69 gets download link for a Chrome add-on from the Chrome Gallery site |
| 70 """ | 70 """ |
| 71 galleryID = urlencode(galleryID) | 71 galleryID = urlencode(galleryID) |
| 72 | 72 |
| 73 response = urlopen('https://clients2.google.com/service/update2/crx?x=' + urle ncode('id=%s&uc' % galleryID)) | 73 url = 'https://clients2.google.com/service/update2/crx?x=%s' % urlencode('id=% s&uc' % galleryID) |
|
Wladimir Palant
2014/05/26 10:54:57
a) Why use an overly long line instead of a tempor
Sebastian Noack
2014/05/26 12:04:53
Agreed.
Wladimir Palant
2014/05/26 13:26:53
What we have here is a URL template, substitution
Sebastian Noack
2014/05/27 12:01:23
Done.
| |
| 74 document = dom.parse(response) | 74 document = dom.parse(urlopen(url)) |
| 75 updateTags = document.getElementsByTagName('updatecheck') | 75 updateTags = document.getElementsByTagName('updatecheck') |
| 76 version = updateTags and updateTags[0].getAttribute('version') | 76 version = updateTags and updateTags[0].getAttribute('version') |
| 77 | 77 |
| 78 if not version: | 78 if not version: |
| 79 return (None, None) | 79 return (None, None) |
| 80 | 80 |
| 81 request = urllib2.Request('https://chrome.google.com/webstore/detail/_/' + gal leryID) | 81 request = urllib2.Request('https://chrome.google.com/webstore/detail/_/' + gal leryID) |
| 82 request.get_method = lambda : 'HEAD' | 82 request.get_method = lambda : 'HEAD' |
| 83 url = urllib2.urlopen(request).geturl() | 83 url = urllib2.urlopen(request).geturl() |
| 84 | 84 |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 116 highestVersion = version | 116 highestVersion = version |
| 117 | 117 |
| 118 return (highestURL, highestVersion) | 118 return (highestURL, highestVersion) |
| 119 | 119 |
| 120 def getDownloadLink(repo): | 120 def getDownloadLink(repo): |
| 121 """ | 121 """ |
| 122 gets the download link to the most current version of an extension | 122 gets the download link to the most current version of an extension |
| 123 """ | 123 """ |
| 124 # you can't easily install extensions from third-party sources on Chrome | 124 # you can't easily install extensions from third-party sources on Chrome |
| 125 # and Opera. So always get the link for the version on the Web Store. | 125 # and Opera. So always get the link for the version on the Web Store. |
| 126 if repo.type in ("chrome", "opera") and repo.galleryID: | 126 if repo.galleryID: |
|
Wladimir Palant
2014/05/26 10:54:57
Isn't the repo.type check redundant here? You chec
Sebastian Noack
2014/05/26 12:04:53
You are right.
| |
| 127 if repo.type == "chrome": | 127 if repo.type == "chrome": |
| 128 return getGoogleDownloadLink(repo.galleryID) | 128 return getGoogleDownloadLink(repo.galleryID) |
| 129 | |
| 130 if repo.type == "opera": | 129 if repo.type == "opera": |
| 131 return getOperaDownloadLink(repo.galleryID) | 130 return getOperaDownloadLink(repo.galleryID) |
| 132 | 131 |
| 133 (localURL, localVersion) = getLocalLink(repo) | 132 (localURL, localVersion) = getLocalLink(repo) |
| 134 | 133 |
| 135 # get a link to Firefox Add-Ons, if the latest version has been published ther e | 134 # get a link to Firefox Add-Ons, if the latest version has been published ther e |
| 136 if repo.type == 'gecko' and repo.galleryID: | 135 if repo.type == 'gecko' and repo.galleryID: |
| 137 (galleryURL, galleryVersion) = getMozillaDownloadLink(repo.galleryID) | 136 (galleryURL, galleryVersion) = getMozillaDownloadLink(repo.galleryID) |
| 138 if not localVersion or (galleryVersion and | 137 if not localVersion or (galleryVersion and |
| 139 compareVersions(galleryVersion, localVersion) >= 0): | 138 compareVersions(galleryVersion, localVersion) >= 0): |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 226 if len(extensions['android']) > 1: | 225 if len(extensions['android']) > 1: |
| 227 print >>sys.stderr, 'Warning: more than one Android app defined, update mani fest only works for one' | 226 print >>sys.stderr, 'Warning: more than one Android app defined, update mani fest only works for one' |
| 228 | 227 |
| 229 for repoType in extensions.iterkeys(): | 228 for repoType in extensions.iterkeys(): |
| 230 manifestPath = get_config().get('extensions', '%sUpdateManifestPath' % repoT ype) | 229 manifestPath = get_config().get('extensions', '%sUpdateManifestPath' % repoT ype) |
| 231 template = get_template(get_config().get('extensions', '%sUpdateManifest' % repoType)) | 230 template = get_template(get_config().get('extensions', '%sUpdateManifest' % repoType)) |
| 232 template.stream({'extensions': extensions[repoType]}).dump(manifestPath) | 231 template.stream({'extensions': extensions[repoType]}).dump(manifestPath) |
| 233 | 232 |
| 234 def writePadFile(links): | 233 def writePadFile(links): |
| 235 for repo in Configuration.getRepositoryConfigurations(): | 234 for repo in Configuration.getRepositoryConfigurations(): |
| 236 if repo.padTemplate and links.has_section(repo.repositoryName): | 235 if repo.pad and links.has_section(repo.repositoryName): |
| 237 PadFile.forRepository(repo, links.get(repo.repositoryName, 'version'), | 236 PadFile.forRepository(repo, links.get(repo.repositoryName, 'version'), |
| 238 links.get(repo.repositoryName, 'downloadURL')) .write() | 237 links.get(repo.repositoryName, 'downloadURL')) .write() |
| 239 | 238 |
| 240 def updateLinks(): | 239 def updateLinks(): |
| 241 """ | 240 """ |
| 242 writes the current extension download links to a file | 241 writes the current extension download links to a file |
| 243 """ | 242 """ |
| 244 | 243 |
| 245 # Now get download links and save them to file | 244 # Now get download links and save them to file |
| 246 result = SafeConfigParser() | 245 result = SafeConfigParser() |
| 247 getDownloadLinks(result) | 246 getDownloadLinks(result) |
| 248 file = open(get_config().get('extensions', 'downloadLinksFile'), 'wb') | 247 file = open(get_config().get('extensions', 'downloadLinksFile'), 'wb') |
| 249 result.write(file) | 248 result.write(file) |
| 250 file.close() | 249 file.close() |
| 251 | 250 |
| 252 writeUpdateManifest(result) | 251 writeUpdateManifest(result) |
| 253 writePadFile(result) | 252 writePadFile(result) |
| 254 | 253 |
| 255 if __name__ == "__main__": | 254 if __name__ == "__main__": |
| 256 updateLinks() | 255 updateLinks() |
| LEFT | RIGHT |