cubicweb/server/sources/__init__.py
branch3.25
changeset 12155 4ba8fd2cd41a
parent 12153 0ff0aff4413d
child 12156 0d1d22a3a48b
equal deleted inserted replaced
12154:0cf35ffde0e4 12155:4ba8fd2cd41a
   130 
   130 
   131     def restore(self, backupfile, confirm, drop, format='native'):
   131     def restore(self, backupfile, confirm, drop, format='native'):
   132         """method called to restore a backup of source's data"""
   132         """method called to restore a backup of source's data"""
   133         pass
   133         pass
   134 
   134 
   135     @classmethod
   135     def _check_config_dict(self, eid, confdict, raise_on_error=True):
   136     def _check_config_dict(cls, eid, confdict, raise_on_error=True):
       
   137         """Check configuration of source entity and return config dict properly
   136         """Check configuration of source entity and return config dict properly
   138         typed with defaults set.
   137         typed with defaults set.
   139 
   138 
   140         If `raise_on_error` is True (the default), a ValidationError will be
   139         If `raise_on_error` is True (the default), a ValidationError will be
   141         raised if some error is encountered, else the problem will be ignored.
   140         raised if some error is encountered, else the problem will be ignored.
   142         """
   141         """
   143         processed = {}
   142         processed = {}
   144         for optname, optdict in cls.options:
   143         for optname, optdict in self.options:
   145             value = confdict.pop(optname, optdict.get('default'))
   144             value = confdict.pop(optname, optdict.get('default'))
   146             if value is configuration.REQUIRED:
   145             if value is configuration.REQUIRED:
   147                 if not raise_on_error:
   146                 if not raise_on_error:
   148                     continue
   147                     continue
   149                 msg = _('specifying %s is mandatory')
   148                 msg = _('specifying %s is mandatory')
   169             if raise_on_error:
   168             if raise_on_error:
   170                 msg = _('unknown options %s')
   169                 msg = _('unknown options %s')
   171                 msgargs = ', '.join(confdict)
   170                 msgargs = ', '.join(confdict)
   172                 raise ValidationError(eid, {role_name('config', 'subject'): msg}, msgargs)
   171                 raise ValidationError(eid, {role_name('config', 'subject'): msg}, msgargs)
   173             else:
   172             else:
   174                 logger = getLogger('cubicweb.sources')
   173                 self.warning('unknown options %s', ', '.join(confdict))
   175                 logger.warning('unknown options %s', ', '.join(confdict))
       
   176                 # add options to processed, they may be necessary during migration
   174                 # add options to processed, they may be necessary during migration
   177                 processed.update(confdict)
   175                 processed.update(confdict)
   178         return processed
   176         return processed
   179 
   177 
   180     @classmethod
   178     def check_config(self, source_entity):
   181     def check_config(cls, source_entity):
       
   182         """Check configuration of source entity, raise ValidationError if some
   179         """Check configuration of source entity, raise ValidationError if some
   183         errors are detected.
   180         errors are detected.
   184         """
   181         """
   185         return cls._check_config_dict(source_entity.eid, source_entity.dictconfig)
   182         return self._check_config_dict(source_entity.eid, source_entity.dictconfig)
   186 
   183 
   187     def check_urls(self, source_entity):
   184     def check_urls(self, source_entity):
   188         """Check URL of source entity: `urls` is a string that may contain one
   185         """Check URL of source entity: `urls` is a string that may contain one
   189         URL per line), and return a list of at least one validated URL.
   186         URL per line), and return a list of at least one validated URL.
   190         """
   187         """