server/sources/__init__.py
changeset 8674 001c1592060a
parent 8544 3d049071957e
child 8695 358d8bed9626
equal deleted inserted replaced
8673:8ea63a2cc2cc 8674:001c1592060a
     1 # copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     1 # copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     2 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
     3 #
     3 #
     4 # This file is part of CubicWeb.
     4 # This file is part of CubicWeb.
     5 #
     5 #
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
     6 # CubicWeb is free software: you can redistribute it and/or modify it under the
   131         self.public_config.setdefault('use-cwuri-as-url', self.use_cwuri_as_url)
   131         self.public_config.setdefault('use-cwuri-as-url', self.use_cwuri_as_url)
   132         self.remove_sensitive_information(self.public_config)
   132         self.remove_sensitive_information(self.public_config)
   133         self.uri = source_config.pop('uri')
   133         self.uri = source_config.pop('uri')
   134         set_log_methods(self, getLogger('cubicweb.sources.'+self.uri))
   134         set_log_methods(self, getLogger('cubicweb.sources.'+self.uri))
   135         source_config.pop('type')
   135         source_config.pop('type')
       
   136         self.update_config(None, self.check_conf_dict(eid, source_config,
       
   137                                                       fail_if_unknown=False))
   136 
   138 
   137     def __repr__(self):
   139     def __repr__(self):
   138         return '<%s %s source %s @%#x>' % (self.uri, self.__class__.__name__,
   140         return '<%s %s source %s @%#x>' % (self.uri, self.__class__.__name__,
   139                                            self.eid, id(self))
   141                                            self.eid, id(self))
   140 
   142 
   204 
   206 
   205     def update_config(self, source_entity, typedconfig):
   207     def update_config(self, source_entity, typedconfig):
   206         """update configuration from source entity. `typedconfig` is config
   208         """update configuration from source entity. `typedconfig` is config
   207         properly typed with defaults set
   209         properly typed with defaults set
   208         """
   210         """
   209         pass
   211         if source_entity is not None:
       
   212             self._entity_update(source_entity)
       
   213         self.config = typedconfig
       
   214 
       
   215     def _entity_update(self, source_entity):
       
   216         source_entity.complete()
       
   217         if source_entity.url:
       
   218             self.urls = [url.strip() for url in source_entity.url.splitlines()
       
   219                          if url.strip()]
       
   220         else:
       
   221             self.urls = []
   210 
   222 
   211     # source initialization / finalization #####################################
   223     # source initialization / finalization #####################################
   212 
   224 
   213     def set_schema(self, schema):
   225     def set_schema(self, schema):
   214         """set the instance'schema"""
   226         """set the instance'schema"""
   220 
   232 
   221     def init(self, activated, source_entity):
   233     def init(self, activated, source_entity):
   222         """method called by the repository once ready to handle request.
   234         """method called by the repository once ready to handle request.
   223         `activated` is a boolean flag telling if the source is activated or not.
   235         `activated` is a boolean flag telling if the source is activated or not.
   224         """
   236         """
   225         pass
   237         if activated:
       
   238             self._entity_update(source_entity)
   226 
   239 
   227     PUBLIC_KEYS = ('type', 'uri', 'use-cwuri-as-url')
   240     PUBLIC_KEYS = ('type', 'uri', 'use-cwuri-as-url')
   228     def remove_sensitive_information(self, sourcedef):
   241     def remove_sensitive_information(self, sourcedef):
   229         """remove sensitive information such as login / password from source
   242         """remove sensitive information such as login / password from source
   230         definition
   243         definition