[repo sources] move handling of source's url into abstract source as this becomes shared by most sources
authorSylvain Thénault <sylvain.thenault@logilab.fr>
Fri, 04 Jan 2013 15:18:44 +0100
changeset 8674 001c1592060a
parent 8673 8ea63a2cc2cc
child 8675 b60329e40e26
[repo sources] move handling of source's url into abstract source as this becomes shared by most sources prepare #2539822
server/ldaputils.py
server/sources/__init__.py
server/sources/datafeed.py
server/sources/ldapfeed.py
server/sources/ldapuser.py
server/sources/remoterql.py
--- a/server/ldaputils.py	Thu Jan 10 22:52:47 2013 +0100
+++ b/server/ldaputils.py	Fri Jan 04 15:18:44 2013 +0100
@@ -1,4 +1,4 @@
-# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of CubicWeb.
@@ -135,6 +135,7 @@
     _conn = None
 
     def _entity_update(self, source_entity):
+        super(LDAPSourceMixIn, self)._entity_update(source_entity)
         if self.urls:
             if len(self.urls) > 1:
                 raise ValidationError(source_entity.eid, {'url': _('can only have one url')})
@@ -149,6 +150,7 @@
         """update configuration from source entity. `typedconfig` is config
         properly typed with defaults set
         """
+        super(LDAPSourceMixIn, self).update_config(source_entity, typedconfig)
         self.authmode = typedconfig['auth-mode']
         self._authenticate = getattr(self, '_auth_%s' % self.authmode)
         self.cnx_dn = typedconfig['data-cnx-dn']
--- a/server/sources/__init__.py	Thu Jan 10 22:52:47 2013 +0100
+++ b/server/sources/__init__.py	Fri Jan 04 15:18:44 2013 +0100
@@ -1,4 +1,4 @@
-# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of CubicWeb.
@@ -133,6 +133,8 @@
         self.uri = source_config.pop('uri')
         set_log_methods(self, getLogger('cubicweb.sources.'+self.uri))
         source_config.pop('type')
+        self.update_config(None, self.check_conf_dict(eid, source_config,
+                                                      fail_if_unknown=False))
 
     def __repr__(self):
         return '<%s %s source %s @%#x>' % (self.uri, self.__class__.__name__,
@@ -206,7 +208,17 @@
         """update configuration from source entity. `typedconfig` is config
         properly typed with defaults set
         """
-        pass
+        if source_entity is not None:
+            self._entity_update(source_entity)
+        self.config = typedconfig
+
+    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 #####################################
 
@@ -222,7 +234,8 @@
         """method called by the repository once ready to handle request.
         `activated` is a boolean flag telling if the source is activated or not.
         """
-        pass
+        if activated:
+            self._entity_update(source_entity)
 
     PUBLIC_KEYS = ('type', 'uri', 'use-cwuri-as-url')
     def remove_sensitive_information(self, sourcedef):
--- a/server/sources/datafeed.py	Thu Jan 10 22:52:47 2013 +0100
+++ b/server/sources/datafeed.py	Fri Jan 04 15:18:44 2013 +0100
@@ -1,4 +1,4 @@
-# copyright 2010-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2010-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of CubicWeb.
@@ -81,43 +81,30 @@
           }),
         )
 
-    def __init__(self, repo, source_config, eid=None):
-        AbstractSource.__init__(self, repo, source_config, eid)
-        self.update_config(None, self.check_conf_dict(eid, source_config,
-                                                      fail_if_unknown=False))
-
     def check_config(self, source_entity):
         """check configuration of source entity"""
-        typedconfig = super(DataFeedSource, self).check_config(source_entity)
-        if typedconfig['synchronization-interval'] < 60:
+        typed_config = super(DataFeedSource, self).check_config(source_entity)
+        if typed_config['synchronization-interval'] < 60:
             _ = source_entity._cw._
             msg = _('synchronization-interval must be greater than 1 minute')
             raise ValidationError(source_entity.eid, {'config': msg})
-        return typedconfig
+        return typed_config
 
     def _entity_update(self, source_entity):
-        source_entity.complete()
+        super(DataFeedSource, self)._entity_update(source_entity)
         self.parser_id = source_entity.parser
         self.latest_retrieval = source_entity.latest_retrieval
-        if source_entity.url:
-            self.urls = [url.strip() for url in source_entity.url.splitlines()
-                         if url.strip()]
-        else:
-            self.urls = []
 
-    def update_config(self, source_entity, typedconfig):
-        """update configuration from source entity. `typedconfig` is config
+    def update_config(self, source_entity, typed_config):
+        """update configuration from source entity. `typed_config` is config
         properly typed with defaults set
         """
-        self.synchro_interval = timedelta(seconds=typedconfig['synchronization-interval'])
-        self.max_lock_lifetime = timedelta(seconds=typedconfig['max-lock-lifetime'])
-        if source_entity is not None:
-            self._entity_update(source_entity)
-        self.config = typedconfig
+        super(DataFeedSource, self).update_config(source_entity, typed_config)
+        self.synchro_interval = timedelta(seconds=typed_config['synchronization-interval'])
+        self.max_lock_lifetime = timedelta(seconds=typed_config['max-lock-lifetime'])
 
     def init(self, activated, source_entity):
-        if activated:
-            self._entity_update(source_entity)
+        super(DataFeedSource, self).init(activated, source_entity)
         self.parser_id = source_entity.parser
         self.load_mapping(source_entity._cw)
 
--- a/server/sources/ldapfeed.py	Thu Jan 10 22:52:47 2013 +0100
+++ b/server/sources/ldapfeed.py	Fri Jan 04 15:18:44 2013 +0100
@@ -1,4 +1,4 @@
-# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of CubicWeb.
@@ -32,13 +32,3 @@
 
     options = datafeed.DataFeedSource.options + ldaputils.LDAPSourceMixIn.options
 
-    def update_config(self, source_entity, typedconfig):
-        """update configuration from source entity. `typedconfig` is config
-        properly typed with defaults set
-        """
-        datafeed.DataFeedSource.update_config(self, source_entity, typedconfig)
-        ldaputils.LDAPSourceMixIn.update_config(self, source_entity, typedconfig)
-
-    def _entity_update(self, source_entity):
-        datafeed.DataFeedSource._entity_update(self, source_entity)
-        ldaputils.LDAPSourceMixIn._entity_update(self, source_entity)
--- a/server/sources/ldapuser.py	Thu Jan 10 22:52:47 2013 +0100
+++ b/server/sources/ldapuser.py	Fri Jan 04 15:18:44 2013 +0100
@@ -1,4 +1,4 @@
-# copyright 2003-2012 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
+# copyright 2003-2013 LOGILAB S.A. (Paris, FRANCE), all rights reserved.
 # contact http://www.logilab.fr/ -- mailto:contact@logilab.fr
 #
 # This file is part of CubicWeb.
@@ -67,26 +67,11 @@
 
     )
 
-    def __init__(self, repo, source_config, eid=None):
-        AbstractSource.__init__(self, repo, source_config, eid)
-        self.update_config(None, self.check_conf_dict(eid, source_config,
-                                                      fail_if_unknown=False))
-
-    def _entity_update(self, source_entity):
-        # XXX copy from datafeed source
-        if source_entity.url:
-            self.urls = [url.strip() for url in source_entity.url.splitlines()
-                         if url.strip()]
-        else:
-            self.urls = []
-        # /end XXX
-        ldaputils.LDAPSourceMixIn._entity_update(self, source_entity)
-
     def update_config(self, source_entity, typedconfig):
         """update configuration from source entity. `typedconfig` is config
         properly typed with defaults set
         """
-        ldaputils.LDAPSourceMixIn.update_config(self, source_entity, typedconfig)
+        super(LDAPUserSource, self).update_config(source_entity, typedconfig)
         self._interval = typedconfig['synchronization-interval']
         self._cache_ttl = max(71, typedconfig['cache-life-time'])
         self.reset_caches()
--- a/server/sources/remoterql.py	Thu Jan 10 22:52:47 2013 +0100
+++ b/server/sources/remoterql.py	Fri Jan 04 15:18:44 2013 +0100
@@ -99,12 +99,11 @@
 
     def __init__(self, repo, source_config, eid=None):
         super(RemoteSource, self).__init__(repo, source_config, eid)
-        self.update_config(None, self.check_conf_dict(eid, source_config,
-                                                      fail_if_unknown=False))
         self._query_cache = TimedCache(1800)
 
     def update_config(self, source_entity, processed_config):
         """update configuration from source entity"""
+        super(RemoteSource, self).update_config(source_entity, processed_config)
         baseurl = processed_config.get('base-url')
         if baseurl and not baseurl.endswith('/'):
             processed_config['base-url'] += '/'