OLD | NEW |
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, |
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 re | 18 import re |
19 from ConfigParser import NoOptionError | 19 import os |
| 20 import subprocess |
| 21 from ConfigParser import SafeConfigParser, NoOptionError |
| 22 from StringIO import StringIO |
20 from sitescripts.utils import get_config | 23 from sitescripts.utils import get_config |
21 | 24 |
22 def compareVersionParts(part1, part2): | 25 def compareVersionParts(part1, part2): |
23 def convertInt(value, default): | 26 def convertInt(value, default): |
24 try: | 27 try: |
25 return int(value) | 28 return int(value) |
26 except ValueError: | 29 except ValueError: |
27 return default | 30 return default |
28 | 31 |
29 def convertVersionPart(part): | 32 def convertVersionPart(part): |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 buildRepository = _defineGlobalProperty('buildRepository') | 128 buildRepository = _defineGlobalProperty('buildRepository') |
126 nightliesDirectory = _defineGlobalProperty('nightliesDirectory') | 129 nightliesDirectory = _defineGlobalProperty('nightliesDirectory') |
127 nightliesURL = _defineGlobalProperty('nightliesURL') | 130 nightliesURL = _defineGlobalProperty('nightliesURL') |
128 downloadsRepo = _defineGlobalProperty('downloadsRepo') | 131 downloadsRepo = _defineGlobalProperty('downloadsRepo') |
129 downloadsURL = _defineGlobalProperty('downloadsURL') | 132 downloadsURL = _defineGlobalProperty('downloadsURL') |
130 docsDirectory = _defineGlobalProperty('docsDirectory') | 133 docsDirectory = _defineGlobalProperty('docsDirectory') |
131 signtool = _defineGlobalProperty('signtool') | 134 signtool = _defineGlobalProperty('signtool') |
132 certname = _defineGlobalProperty('signtool_certname') | 135 certname = _defineGlobalProperty('signtool_certname') |
133 dbdir = _defineGlobalProperty('signtool_dbdir') | 136 dbdir = _defineGlobalProperty('signtool_dbdir') |
134 dbpass = _defineGlobalProperty('signtool_dbpass') | 137 dbpass = _defineGlobalProperty('signtool_dbpass') |
| 138 padDirectory = _defineGlobalProperty('padDirectory') |
| 139 padURL = _defineGlobalProperty('padURL') |
135 | 140 |
136 keyFile = _defineLocalProperty('key', '') | 141 keyFile = _defineLocalProperty('key', '') |
137 name = _defineLocalProperty('name') | 142 name = _defineLocalProperty('name') |
138 galleryID = _defineLocalProperty('galleryID', '') | 143 galleryID = _defineLocalProperty('galleryID', '') |
139 devbuildGalleryID = _defineLocalProperty('devbuildGalleryID', '') | 144 devbuildGalleryID = _defineLocalProperty('devbuildGalleryID', '') |
140 downloadPage = _defineLocalProperty('downloadPage', '') | 145 downloadPage = _defineLocalProperty('downloadPage', '') |
141 experimental = _defineLocalProperty('experimental', '') | 146 experimental = _defineLocalProperty('experimental', '') |
142 clientID = _defineLocalProperty('clientID', '') | 147 clientID = _defineLocalProperty('clientID', '') |
143 clientSecret = _defineLocalProperty('clientSecret', '') | 148 clientSecret = _defineLocalProperty('clientSecret', '') |
144 refreshToken = _defineLocalProperty('refreshToken', '') | 149 refreshToken = _defineLocalProperty('refreshToken', '') |
| 150 padTemplate = _defineLocalProperty('padTemplate') |
145 | 151 |
146 latestRevision = _defineNightlyProperty('latestRevision') | 152 latestRevision = _defineNightlyProperty('latestRevision') |
147 | 153 |
148 def __init__(self, config, nightlyConfig, repositoryName, repository): | 154 def __init__(self, config, nightlyConfig, repositoryName, repository): |
149 """ | 155 """ |
150 Creates a new Configuration instance that is bound to a particular | 156 Creates a new Configuration instance that is bound to a particular |
151 repository. | 157 repository. |
152 """ | 158 """ |
153 | 159 |
154 self.repositoryName = repositoryName | 160 self.repositoryName = repositoryName |
(...skipping 19 matching lines...) Expand all Loading... |
174 | 180 |
175 if self.nightlyConfig and not self.nightlyConfig.has_section(self.repository
Name): | 181 if self.nightlyConfig and not self.nightlyConfig.has_section(self.repository
Name): |
176 self.nightlyConfig.add_section(self.repositoryName) | 182 self.nightlyConfig.add_section(self.repositoryName) |
177 | 183 |
178 def __str__(self): | 184 def __str__(self): |
179 """ | 185 """ |
180 Provides a string representation of this configuration | 186 Provides a string representation of this configuration |
181 """ | 187 """ |
182 return self.repositoryName | 188 return self.repositoryName |
183 | 189 |
| 190 def listContents(self, version='tip'): |
| 191 return subprocess.check_output(['hg', '-R', self.repository, 'locate', '-r',
version]).splitlines() |
| 192 |
| 193 def readMetadata(self, version='tip'): |
| 194 genericFilename = 'metadata' |
| 195 filename = '%s.%s' % (genericFilename, self.type) |
| 196 files = self.listContents(version) |
| 197 |
| 198 if filename not in files: |
| 199 # some repositories like those for Android and |
| 200 # Internet Explorer don't have metadata files |
| 201 if genericFilename not in files: |
| 202 return None |
| 203 |
| 204 # Fall back to platform-independent metadata file |
| 205 filename = genericFilename |
| 206 |
| 207 command = ['hg', '-R', self.repository, 'cat', '-r', version, os.path.join(s
elf.repository, filename)] |
| 208 result = subprocess.check_output(command) |
| 209 |
| 210 parser = SafeConfigParser() |
| 211 parser.readfp(StringIO(result)) |
| 212 |
| 213 return parser |
| 214 |
| 215 @property |
| 216 def basename(self): |
| 217 metadata = self.readMetadata() |
| 218 if metadata: |
| 219 return metadata.get('general', 'basename') |
| 220 return os.path.basename(self.repository) |
| 221 |
| 222 def getDownloads(self): |
| 223 prefix = self.basename + '-' |
| 224 command = ['hg', 'locate', '-R', self.downloadsRepo, '-r', 'default'] |
| 225 |
| 226 for filename in subprocess.check_output(command).splitlines(): |
| 227 if filename.startswith(prefix) and filename.endswith(self.packageSuffix): |
| 228 yield (filename, filename[len(prefix):len(filename) - len(self.packageSu
ffix)]) |
| 229 |
184 @staticmethod | 230 @staticmethod |
185 def getRepositoryConfigurations(nightlyConfig = None): | 231 def getRepositoryConfigurations(nightlyConfig = None): |
186 """ | 232 """ |
187 Retrieves configuration settings for all repositories | 233 Retrieves configuration settings for all repositories |
188 from the configuration file, where existing repositories | 234 from the configuration file, where existing repositories |
189 are identified by an <id>_repository entry appearing | 235 are identified by an <id>_repository entry appearing |
190 in the configuration file. | 236 in the configuration file. |
191 This static method will enumerate Configuration | 237 This static method will enumerate Configuration |
192 objects representing the settings for each repository. | 238 objects representing the settings for each repository. |
193 """ | 239 """ |
(...skipping 15 matching lines...) Expand all Loading... |
209 except M2Crypto.X509.X509Error: | 255 except M2Crypto.X509.X509Error: |
210 raise Exception('No safari developer certificate found in chain') | 256 raise Exception('No safari developer certificate found in chain') |
211 | 257 |
212 subject = cert.get_subject() | 258 subject = cert.get_subject() |
213 for entry in subject.get_entries_by_nid(subject.nid['CN']): | 259 for entry in subject.get_entries_by_nid(subject.nid['CN']): |
214 m = re.match(r'Safari Developer: \((.*?)\)', entry.get_data().as_text()) | 260 m = re.match(r'Safari Developer: \((.*?)\)', entry.get_data().as_text()) |
215 if m: | 261 if m: |
216 return m.group(1) | 262 return m.group(1) |
217 finally: | 263 finally: |
218 bio.close() | 264 bio.close() |
OLD | NEW |