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

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

Issue 8851004: Added Opera extension type (Closed)
Patch Set: Created Nov. 13, 2012, 9:46 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
« 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-2012 Eyeo GmbH 4 # Copyright (C) 2006-2012 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 """ 18 """
19 Update the list of extenstions 19 Update the list of extenstions
20 ============================== 20 ==============================
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 os, urllib, urlparse, subprocess, time 26 import 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
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
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 url = 'https://clients2.google.com/service/update2/crx?x=%s' % urlencode(param ) 70 url = 'https://clients2.google.com/service/update2/crx?x=%s' % urlencode(param )
71 contents = urlopen(url).read() 71 contents = urlopen(url).read()
72 document = dom.parseString(contents) 72 document = dom.parseString(contents)
73 updateTags = document.getElementsByTagName('updatecheck') 73 updateTags = document.getElementsByTagName('updatecheck')
74 updateTag = updateTags[0] if len(updateTags) > 0 else None 74 updateTag = updateTags[0] if len(updateTags) > 0 else None
75 if updateTag and updateTag.hasAttribute('codebase') and updateTag.hasAttribute ('version'): 75 if updateTag and updateTag.hasAttribute('codebase') and updateTag.hasAttribute ('version'):
76 return (updateTag.getAttribute('codebase'), updateTag.getAttribute('version' )) 76 return (updateTag.getAttribute('codebase'), updateTag.getAttribute('version' ))
77 else: 77 else:
78 return (None, None) 78 return (None, None)
79 79
80 def getOperaDownloadLink(galleryID):
81 """
82 gets download link for an Opera add-on from the Opera Addons site
83 """
84 class HeadRequest(urllib2.Request):
85 def get_method(self):
86 return "HEAD"
87
88 url = 'https://addons.opera.com/extensions/download/%s/' % urlencode(galleryID )
89 response = urllib2.urlopen(HeadRequest(url))
90 content_disposition = response.info().dict.get('content-disposition', None)
91 if content_disposition != None:
92 match = re.search(r'filename=\S+-([\d.]+)-\d+\.oex$', content_disposition)
93 else:
94 match = None;
95 if match:
96 return (url, match.group(1))
97 else:
98 return (None, None)
99
80 def getLocalLink(repo): 100 def getLocalLink(repo):
81 """ 101 """
82 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
83 repository 103 repository
84 """ 104 """
85 dir = repo.downloadsDirectory 105 dir = repo.downloadsDirectory
86 url = repo.downloadsURL 106 url = repo.downloadsURL
87 107
88 highestURL = None 108 highestURL = None
89 highestVersion = None 109 highestVersion = None
(...skipping 12 matching lines...) Expand all
102 def getDownloadLink(repo): 122 def getDownloadLink(repo):
103 """ 123 """
104 gets the download link to the most current version of an extension 124 gets the download link to the most current version of an extension
105 """ 125 """
106 galleryURL = None 126 galleryURL = None
107 galleryVersion = None 127 galleryVersion = None
108 if repo.type == "gecko" and repo.galleryID: 128 if repo.type == "gecko" and repo.galleryID:
109 (galleryURL, galleryVersion) = getMozillaDownloadLink(repo.galleryID) 129 (galleryURL, galleryVersion) = getMozillaDownloadLink(repo.galleryID)
110 elif repo.type == "chrome" and repo.galleryID: 130 elif repo.type == "chrome" and repo.galleryID:
111 (galleryURL, galleryVersion) = getGoogleDownloadLink(repo.galleryID) 131 (galleryURL, galleryVersion) = getGoogleDownloadLink(repo.galleryID)
132 elif repo.type == "opera" and repo.galleryID:
133 (galleryURL, galleryVersion) = getOperaDownloadLink(repo.galleryID)
112 134
113 (downloadsURL, downloadsVersion) = getLocalLink(repo) 135 (downloadsURL, downloadsVersion) = getLocalLink(repo)
114 if galleryVersion == None or (downloadsVersion != None and 136 if galleryVersion == None or (downloadsVersion != None and
115 compareVersions(galleryVersion, downloadsVersion ) < 0): 137 compareVersions(galleryVersion, downloadsVersion ) < 0):
116 return (downloadsURL, downloadsVersion) 138 return (downloadsURL, downloadsVersion)
117 else: 139 else:
118 return (galleryURL, galleryVersion) 140 return (galleryURL, galleryVersion)
119 141
120 def getDownloadLinks(result): 142 def getDownloadLinks(result):
121 """ 143 """
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
185 result = SafeConfigParser() 207 result = SafeConfigParser()
186 getDownloadLinks(result) 208 getDownloadLinks(result)
187 file = open(get_config().get('extensions', 'downloadLinksFile'), 'wb') 209 file = open(get_config().get('extensions', 'downloadLinksFile'), 'wb')
188 result.write(file) 210 result.write(file)
189 file.close() 211 file.close()
190 212
191 writeUpdateManifest(result) 213 writeUpdateManifest(result)
192 214
193 if __name__ == "__main__": 215 if __name__ == "__main__":
194 updateLinks() 216 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