[server] Inline _entity_update method into init method of AbstractSource 3.25
authorDenis Laxalde <denis.laxalde@logilab.fr>
Wed, 05 Apr 2017 14:31:44 +0200
branch3.25
changeset 12144 f54286c1cef5
parent 12143 a446124bcf3c
child 12145 752b94ed9748
[server] Inline _entity_update method into init method of AbstractSource This _entity_update method does not make sense now that we do not update source from database information but always build them afresh.
cubicweb/server/sources/__init__.py
cubicweb/server/sources/datafeed.py
cubicweb/server/sources/ldapfeed.py
--- a/cubicweb/server/sources/__init__.py	Wed Apr 05 14:02:58 2017 +0200
+++ b/cubicweb/server/sources/__init__.py	Wed Apr 05 14:31:44 2017 +0200
@@ -176,14 +176,6 @@
         return cls.check_conf_dict(source_entity.eid, source_entity.host_config,
                                     _=source_entity._cw._)
 
-    def _entity_update(self, source_entity):
-        source_entity.complete()
-        if source_entity.url:
-            self.urls = [url.strip() for url in source_entity.url.splitlines()
-                         if url.strip()]
-        else:
-            self.urls = []
-
     # source initialization / finalization #####################################
 
     def set_schema(self, schema):
@@ -198,8 +190,14 @@
         """method called by the repository once ready to handle request.
         `activated` is a boolean flag telling if the source is activated or not.
         """
-        if activated:
-            self._entity_update(source_entity)
+        if not activated:
+            return
+        source_entity.complete()
+        if source_entity.url:
+            self.urls = [url.strip() for url in source_entity.url.splitlines()
+                         if url.strip()]
+        else:
+            self.urls = []
 
     PUBLIC_KEYS = ('type', 'uri', 'use-cwuri-as-url')
     def remove_sensitive_information(self, sourcedef):
--- a/cubicweb/server/sources/datafeed.py	Wed Apr 05 14:02:58 2017 +0200
+++ b/cubicweb/server/sources/datafeed.py	Wed Apr 05 14:31:44 2017 +0200
@@ -107,14 +107,10 @@
             raise ValidationError(source_entity.eid, {'config': msg})
         return typed_config
 
-    def _entity_update(self, source_entity):
-        super(DataFeedSource, self)._entity_update(source_entity)
-        self.parser_id = source_entity.parser
-        self.latest_retrieval = source_entity.latest_retrieval
-
     def init(self, activated, source_entity):
         super(DataFeedSource, self).init(activated, source_entity)
         self.parser_id = source_entity.parser
+        self.latest_retrieval = source_entity.latest_retrieval
         typed_config = self.config
         self.synchro_interval = timedelta(seconds=typed_config['synchronization-interval'])
         self.max_lock_lifetime = timedelta(seconds=typed_config['max-lock-lifetime'])
--- a/cubicweb/server/sources/ldapfeed.py	Wed Apr 05 14:02:58 2017 +0200
+++ b/cubicweb/server/sources/ldapfeed.py	Wed Apr 05 14:31:44 2017 +0200
@@ -178,6 +178,16 @@
 
     def init(self, activated, source_entity):
         super(LDAPFeedSource, self).init(activated, source_entity)
+        if self.urls:
+            if len(self.urls) > 1:
+                raise ValidationError(source_entity.eid, {'url': _('can only have one url')})
+            try:
+                protocol, hostport = self.urls[0].split('://')
+            except ValueError:
+                raise ValidationError(source_entity.eid, {'url': _('badly formatted url')})
+            if protocol not in PROTO_PORT:
+                raise ValidationError(source_entity.eid, {'url': _('unsupported protocol')})
+
         typedconfig = self.config
         self.authmode = typedconfig['auth-mode']
         self._authenticate = getattr(self, '_auth_%s' % self.authmode)
@@ -206,18 +216,6 @@
             self.group_base_filters.append(typedconfig['group-filter'])
         self._conn = None
 
-    def _entity_update(self, source_entity):
-        super(LDAPFeedSource, self)._entity_update(source_entity)
-        if self.urls:
-            if len(self.urls) > 1:
-                raise ValidationError(source_entity.eid, {'url': _('can only have one url')})
-            try:
-                protocol, hostport = self.urls[0].split('://')
-            except ValueError:
-                raise ValidationError(source_entity.eid, {'url': _('badly formatted url')})
-            if protocol not in PROTO_PORT:
-                raise ValidationError(source_entity.eid, {'url': _('unsupported protocol')})
-
     def connection_info(self):
         assert len(self.urls) == 1, self.urls
         protocol, hostport = self.urls[0].split('://')