Commit cb43e492 authored by Sylvain Thénault's avatar Sylvain Thénault
Browse files

[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).

--HG--
branch : 3.25
parent 232eefd6d3b3
...@@ -350,10 +350,7 @@ class Repository(object): ...@@ -350,10 +350,7 @@ class Repository(object):
# needed (for instance looking for persistent configuration using an # needed (for instance looking for persistent configuration using an
# internal session, which is not possible until connections sets have been # internal session, which is not possible until connections sets have been
# initialized) # initialized)
source.init(True, sourceent) source.init(sourceent)
else:
source.init(False, sourceent)
source.set_schema(self.schema)
return source return source
# internals ############################################################### # internals ###############################################################
...@@ -368,7 +365,7 @@ class Repository(object): ...@@ -368,7 +365,7 @@ class Repository(object):
' S name "system", S type SA, S config SC' ' S name "system", S type SA, S config SC'
).one() ).one()
self.system_source.eid = sourceent.eid 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): def get_source(self, type, uri, source_config, eid=None):
# set uri and type in source config so it's available through # set uri and type in source config so it's available through
......
...@@ -186,12 +186,10 @@ class AbstractSource(object): ...@@ -186,12 +186,10 @@ class AbstractSource(object):
"""method called by the repository once ready to create a new instance""" """method called by the repository once ready to create a new instance"""
pass pass
def init(self, activated, source_entity): def init(self, source_entity):
"""method called by the repository once ready to handle request. """method called by the repository once ready to handle request.
`activated` is a boolean flag telling if the source is activated or not. `activated` is a boolean flag telling if the source is activated or not.
""" """
if not activated:
return
source_entity.complete() source_entity.complete()
if source_entity.url: if source_entity.url:
self.urls = [url.strip() for url in source_entity.url.splitlines() self.urls = [url.strip() for url in source_entity.url.splitlines()
......
...@@ -107,8 +107,8 @@ class DataFeedSource(AbstractSource): ...@@ -107,8 +107,8 @@ class DataFeedSource(AbstractSource):
raise ValidationError(source_entity.eid, {'config': msg}) raise ValidationError(source_entity.eid, {'config': msg})
return typed_config return typed_config
def init(self, activated, source_entity): def init(self, source_entity):
super(DataFeedSource, self).init(activated, source_entity) super(DataFeedSource, self).init(source_entity)
self.parser_id = source_entity.parser self.parser_id = source_entity.parser
self.latest_retrieval = source_entity.latest_retrieval self.latest_retrieval = source_entity.latest_retrieval
typed_config = self.config typed_config = self.config
......
...@@ -176,8 +176,8 @@ You can set multiple groups by separating them by a comma.', ...@@ -176,8 +176,8 @@ You can set multiple groups by separating them by a comma.',
_conn = None _conn = None
def init(self, activated, source_entity): def init(self, source_entity):
super(LDAPFeedSource, self).init(activated, source_entity) super(LDAPFeedSource, self).init(source_entity)
if self.urls: if self.urls:
if len(self.urls) > 1: if len(self.urls) > 1:
raise ValidationError(source_entity.eid, {'url': _('can only have one url')}) raise ValidationError(source_entity.eid, {'url': _('can only have one url')})
......
...@@ -427,8 +427,8 @@ class NativeSQLSource(SQLAdapterMixIn, AbstractSource): ...@@ -427,8 +427,8 @@ class NativeSQLSource(SQLAdapterMixIn, AbstractSource):
else: else:
raise ValueError('Unknown format %r' % format) raise ValueError('Unknown format %r' % format)
def init(self, activated, source_entity): def init(self, source_entity):
super(NativeSQLSource, self).init(activated, source_entity) super(NativeSQLSource, self).init(source_entity)
self.init_creating(source_entity._cw.cnxset) self.init_creating(source_entity._cw.cnxset)
def shutdown(self): def shutdown(self):
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment