[sources] Simplify source's init method 3.25
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Wed, 12 Apr 2017 15:49:05 +0200
branch3.25
changeset 12148 79160d54662e
parent 12147 232eefd6d3b3
child 12149 649100470733
[sources] Simplify source's init method Only call it when enabled instead of giving a boolean flag indicating whether it is or not (which were not correctly considered).
cubicweb/server/repository.py
cubicweb/server/sources/__init__.py
cubicweb/server/sources/datafeed.py
cubicweb/server/sources/ldapfeed.py
cubicweb/server/sources/native.py
--- a/cubicweb/server/repository.py	Wed Apr 12 14:54:10 2017 +0200
+++ b/cubicweb/server/repository.py	Wed Apr 12 15:49:05 2017 +0200
@@ -350,10 +350,7 @@
             # needed (for instance looking for persistent configuration using an
             # internal session, which is not possible until connections sets have been
             # initialized)
-            source.init(True, sourceent)
-        else:
-            source.init(False, sourceent)
-        source.set_schema(self.schema)
+            source.init(sourceent)
         return source
 
     # internals ###############################################################
@@ -368,7 +365,7 @@
                 ' S name "system", S type SA, S config SC'
             ).one()
             self.system_source.eid = sourceent.eid
-            self.system_source.init(True, sourceent)
+            self.system_source.init(sourceent)
 
     def get_source(self, type, uri, source_config, eid=None):
         # set uri and type in source config so it's available through
--- a/cubicweb/server/sources/__init__.py	Wed Apr 12 14:54:10 2017 +0200
+++ b/cubicweb/server/sources/__init__.py	Wed Apr 12 15:49:05 2017 +0200
@@ -186,12 +186,10 @@
         """method called by the repository once ready to create a new instance"""
         pass
 
-    def init(self, activated, source_entity):
+    def init(self, source_entity):
         """method called by the repository once ready to handle request.
         `activated` is a boolean flag telling if the source is activated or not.
         """
-        if not activated:
-            return
         source_entity.complete()
         if source_entity.url:
             self.urls = [url.strip() for url in source_entity.url.splitlines()
--- a/cubicweb/server/sources/datafeed.py	Wed Apr 12 14:54:10 2017 +0200
+++ b/cubicweb/server/sources/datafeed.py	Wed Apr 12 15:49:05 2017 +0200
@@ -107,8 +107,8 @@
             raise ValidationError(source_entity.eid, {'config': msg})
         return typed_config
 
-    def init(self, activated, source_entity):
-        super(DataFeedSource, self).init(activated, source_entity)
+    def init(self, source_entity):
+        super(DataFeedSource, self).init(source_entity)
         self.parser_id = source_entity.parser
         self.latest_retrieval = source_entity.latest_retrieval
         typed_config = self.config
--- a/cubicweb/server/sources/ldapfeed.py	Wed Apr 12 14:54:10 2017 +0200
+++ b/cubicweb/server/sources/ldapfeed.py	Wed Apr 12 15:49:05 2017 +0200
@@ -176,8 +176,8 @@
 
     _conn = None
 
-    def init(self, activated, source_entity):
-        super(LDAPFeedSource, self).init(activated, source_entity)
+    def init(self, source_entity):
+        super(LDAPFeedSource, self).init(source_entity)
         if self.urls:
             if len(self.urls) > 1:
                 raise ValidationError(source_entity.eid, {'url': _('can only have one url')})
--- a/cubicweb/server/sources/native.py	Wed Apr 12 14:54:10 2017 +0200
+++ b/cubicweb/server/sources/native.py	Wed Apr 12 15:49:05 2017 +0200
@@ -427,8 +427,8 @@
         else:
             raise ValueError('Unknown format %r' % format)
 
-    def init(self, activated, source_entity):
-        super(NativeSQLSource, self).init(activated, source_entity)
+    def init(self, source_entity):
+        super(NativeSQLSource, self).init(source_entity)
         self.init_creating(source_entity._cw.cnxset)
 
     def shutdown(self):