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