| 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 52 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
|   82       return result |   85       return result | 
|   83   return 0 |   86   return 0 | 
|   84  |   87  | 
|   85 class Configuration(object): |   88 class Configuration(object): | 
|   86   """ |   89   """ | 
|   87     This class represents the configuration settings for a single repository. |   90     This class represents the configuration settings for a single repository. | 
|   88     Some of these properties come from the nightly config file and can be |   91     Some of these properties come from the nightly config file and can be | 
|   89     changed (latestRevision), others come from the global config and are |   92     changed (latestRevision), others come from the global config and are | 
|   90     read-only (repository, repositoryName, nightliesDirectory). |   93     read-only (repository, repositoryName, nightliesDirectory). | 
|   91   """ |   94   """ | 
 |   95   def _defineProperty(name, local=False, type='', default=None): | 
 |   96     def getter(self): | 
 |   97       method = getattr(self.config, 'get' + type) | 
 |   98       key = '%s_%s' % (self.repositoryName, name) if local else name | 
|   92  |   99  | 
|   93   def _defineGlobalProperty(key): |  100       try: | 
|   94     """ |  101         return method('extensions', key) | 
|   95       Creates a property corresponding with a key in the config file |  102       except NoOptionError: | 
|   96     """ |  103         if default is None: | 
|   97     return property(lambda self: self.config.get('extensions', key)) |  104           raise | 
 |  105         return default | 
|   98  |  106  | 
|   99   def _defineLocalProperty(key, default = None): |  107     return property(getter) | 
|  100     """ |  | 
|  101       Creates a property corresponding with a repository-specific key in the con
     fig file |  | 
|  102     """ |  | 
|  103     def getLocalProperty(self): |  | 
|  104       try: |  | 
|  105         return self.config.get('extensions', self.repositoryName + '_' + key) |  | 
|  106       except NoOptionError, e: |  | 
|  107         if default != None: |  | 
|  108           return default |  | 
|  109         else: |  | 
|  110           raise e |  | 
|  111     return property(getLocalProperty) |  | 
|  112  |  108  | 
|  113   def _defineNightlyProperty(key): |  109   def _defineNightlyProperty(key): | 
|  114     """ |  110     """ | 
|  115       Creates a property corresponding with a key in the nightly config file |  111       Creates a property corresponding with a key in the nightly config file | 
|  116     """ |  112     """ | 
|  117     return property(lambda self: self.nightlyConfig.get(self.repositoryName, key
     ), |  113     return property(lambda self: self.nightlyConfig.get(self.repositoryName, key
     ), | 
|  118                     lambda self, value: self.nightlyConfig.set(self.repositoryNa
     me, key, value)) |  114                     lambda self, value: self.nightlyConfig.set(self.repositoryNa
     me, key, value)) | 
|  119  |  115  | 
|  120   config = None |  116   config = None | 
|  121   nightlyConfig = None |  117   nightlyConfig = None | 
|  122   repositoryName = None |  118   repositoryName = None | 
|  123   repository = None |  119   repository = None | 
|  124  |  120  | 
|  125   buildRepository = _defineGlobalProperty('buildRepository') |  121   buildRepository = _defineProperty('buildRepository') | 
|  126   nightliesDirectory = _defineGlobalProperty('nightliesDirectory') |  122   nightliesDirectory = _defineProperty('nightliesDirectory') | 
|  127   nightliesURL = _defineGlobalProperty('nightliesURL') |  123   nightliesURL = _defineProperty('nightliesURL') | 
|  128   downloadsRepo = _defineGlobalProperty('downloadsRepo') |  124   downloadsRepo = _defineProperty('downloadsRepo') | 
|  129   downloadsURL = _defineGlobalProperty('downloadsURL') |  125   downloadsURL = _defineProperty('downloadsURL') | 
|  130   docsDirectory = _defineGlobalProperty('docsDirectory') |  126   docsDirectory = _defineProperty('docsDirectory') | 
|  131   signtool = _defineGlobalProperty('signtool') |  127   signtool = _defineProperty('signtool') | 
|  132   certname = _defineGlobalProperty('signtool_certname') |  128   certname = _defineProperty('signtool_certname') | 
|  133   dbdir = _defineGlobalProperty('signtool_dbdir') |  129   dbdir = _defineProperty('signtool_dbdir') | 
|  134   dbpass = _defineGlobalProperty('signtool_dbpass') |  130   dbpass = _defineProperty('signtool_dbpass') | 
 |  131   padDirectory = _defineProperty('padDirectory') | 
 |  132   padURL = _defineProperty('padURL') | 
 |  133   padTemplate = _defineProperty('padTemplate') | 
|  135  |  134  | 
|  136   keyFile = _defineLocalProperty('key', '') |  135   keyFile = _defineProperty('key', local=True, default='') | 
|  137   name = _defineLocalProperty('name') |  136   name = _defineProperty('name', local=True) | 
|  138   galleryID = _defineLocalProperty('galleryID', '') |  137   galleryID = _defineProperty('galleryID', local=True, default='') | 
|  139   devbuildGalleryID = _defineLocalProperty('devbuildGalleryID', '') |  138   devbuildGalleryID = _defineProperty('devbuildGalleryID', local=True, default='
     ') | 
|  140   downloadPage = _defineLocalProperty('downloadPage', '') |  139   downloadPage = _defineProperty('downloadPage', local=True, default='') | 
|  141   experimental = _defineLocalProperty('experimental', '') |  140   experimental = _defineProperty('experimental', local=True, default='') | 
|  142   clientID = _defineLocalProperty('clientID', '') |  141   clientID = _defineProperty('clientID', local=True, default='') | 
|  143   clientSecret = _defineLocalProperty('clientSecret', '') |  142   clientSecret = _defineProperty('clientSecret', local=True, default='') | 
|  144   refreshToken = _defineLocalProperty('refreshToken', '') |  143   refreshToken = _defineProperty('refreshToken', local=True, default='') | 
 |  144   pad = _defineProperty('pad', local=True, type='boolean', default=False) | 
|  145  |  145  | 
|  146   latestRevision = _defineNightlyProperty('latestRevision') |  146   latestRevision = _defineNightlyProperty('latestRevision') | 
|  147  |  147  | 
|  148   def __init__(self, config, nightlyConfig, repositoryName, repository): |  148   def __init__(self, config, nightlyConfig, repositoryName, repository): | 
|  149     """ |  149     """ | 
|  150       Creates a new Configuration instance that is bound to a particular |  150       Creates a new Configuration instance that is bound to a particular | 
|  151       repository. |  151       repository. | 
|  152     """ |  152     """ | 
|  153  |  153  | 
|  154     self.repositoryName = repositoryName |  154     self.repositoryName = repositoryName | 
| (...skipping 19 matching lines...) Expand all  Loading... | 
|  174  |  174  | 
|  175     if self.nightlyConfig and not self.nightlyConfig.has_section(self.repository
     Name): |  175     if self.nightlyConfig and not self.nightlyConfig.has_section(self.repository
     Name): | 
|  176       self.nightlyConfig.add_section(self.repositoryName) |  176       self.nightlyConfig.add_section(self.repositoryName) | 
|  177  |  177  | 
|  178   def __str__(self): |  178   def __str__(self): | 
|  179     """ |  179     """ | 
|  180       Provides a string representation of this configuration |  180       Provides a string representation of this configuration | 
|  181     """ |  181     """ | 
|  182     return self.repositoryName |  182     return self.repositoryName | 
|  183  |  183  | 
 |  184   def listContents(self, version='tip'): | 
 |  185     return subprocess.check_output(['hg', '-R', self.repository, 'locate', '-r',
      version]).splitlines() | 
 |  186  | 
 |  187   def readMetadata(self, version='tip'): | 
 |  188     genericFilename = 'metadata' | 
 |  189     filename = '%s.%s' % (genericFilename, self.type) | 
 |  190     files = self.listContents(version) | 
 |  191  | 
 |  192     if filename not in files: | 
 |  193       # some repositories like those for Android and | 
 |  194       # Internet Explorer don't have metadata files | 
 |  195       if genericFilename not in files: | 
 |  196         return None | 
 |  197  | 
 |  198       # Fall back to platform-independent metadata file | 
 |  199       filename = genericFilename | 
 |  200  | 
 |  201     command = ['hg', '-R', self.repository, 'cat', '-r', version, os.path.join(s
     elf.repository, filename)] | 
 |  202     result = subprocess.check_output(command) | 
 |  203  | 
 |  204     parser = SafeConfigParser() | 
 |  205     parser.readfp(StringIO(result)) | 
 |  206  | 
 |  207     return parser | 
 |  208  | 
 |  209   @property | 
 |  210   def basename(self): | 
 |  211     metadata = self.readMetadata() | 
 |  212     if metadata: | 
 |  213       return metadata.get('general', 'basename') | 
 |  214     return os.path.basename(self.repository) | 
 |  215  | 
 |  216   def getDownloads(self): | 
 |  217     prefix = self.basename + '-' | 
 |  218     command = ['hg', 'locate', '-R', self.downloadsRepo, '-r', 'default'] | 
 |  219  | 
 |  220     for filename in subprocess.check_output(command).splitlines(): | 
 |  221       if filename.startswith(prefix) and filename.endswith(self.packageSuffix): | 
 |  222         yield (filename, filename[len(prefix):len(filename) - len(self.packageSu
     ffix)]) | 
 |  223  | 
|  184   @staticmethod |  224   @staticmethod | 
|  185   def getRepositoryConfigurations(nightlyConfig = None): |  225   def getRepositoryConfigurations(nightlyConfig = None): | 
|  186     """ |  226     """ | 
|  187       Retrieves configuration settings for all repositories |  227       Retrieves configuration settings for all repositories | 
|  188       from the configuration file, where existing repositories |  228       from the configuration file, where existing repositories | 
|  189       are identified by an <id>_repository entry appearing |  229       are identified by an <id>_repository entry appearing | 
|  190       in the configuration file. |  230       in the configuration file. | 
|  191       This static method will enumerate Configuration |  231       This static method will enumerate Configuration | 
|  192       objects representing the settings for each repository. |  232       objects representing the settings for each repository. | 
|  193     """ |  233     """ | 
| (...skipping 15 matching lines...) Expand all  Loading... | 
|  209       except M2Crypto.X509.X509Error: |  249       except M2Crypto.X509.X509Error: | 
|  210         raise Exception('No safari developer certificate found in chain') |  250         raise Exception('No safari developer certificate found in chain') | 
|  211  |  251  | 
|  212       subject = cert.get_subject() |  252       subject = cert.get_subject() | 
|  213       for entry in subject.get_entries_by_nid(subject.nid['CN']): |  253       for entry in subject.get_entries_by_nid(subject.nid['CN']): | 
|  214         m = re.match(r'Safari Developer: \((.*?)\)', entry.get_data().as_text()) |  254         m = re.match(r'Safari Developer: \((.*?)\)', entry.get_data().as_text()) | 
|  215         if m: |  255         if m: | 
|  216           return m.group(1) |  256           return m.group(1) | 
|  217   finally: |  257   finally: | 
|  218     bio.close() |  258     bio.close() | 
| OLD | NEW |