diff -r 752b94ed9748 -r d540defa0591 cubicweb/server/repository.py --- a/cubicweb/server/repository.py Tue Apr 04 17:43:56 2017 +0200 +++ b/cubicweb/server/repository.py Wed Apr 05 14:59:09 2017 +0200 @@ -302,6 +302,20 @@ # 5. call instance level initialisation hooks self.hm.call_hooks('server_startup', repo=self) + def source_by_uri(self, uri): + with self.internal_cnx() as cnx: + rset = cnx.find('CWSource', name=uri) + if not rset: + raise ValueError('no source with uri %s found' % uri) + return self._source_from_cwsource(rset.one()) + + def source_by_eid(self, eid): + with self.internal_cnx() as cnx: + rset = cnx.find('CWSource', eid=eid) + if not rset: + raise ValueError('no source with eid %d found' % eid) + return self._source_from_cwsource(rset.one()) + @property def sources_by_uri(self): mapping = {'system': self.system_source} @@ -323,20 +337,24 @@ for sourceent in cnx.execute( 'Any S, SN, SA, SC WHERE S is_instance_of CWSource, ' 'S name SN, S type SA, S config SC, S name != "system"').entities(): - source = self.get_source(sourceent.type, sourceent.name, - sourceent.host_config, sourceent.eid) - if self.config.source_enabled(source): - # call source's init method to complete their initialisation if - # 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 = self._source_from_cwsource(sourceent) yield sourceent, source self._clear_source_defs_caches() + def _source_from_cwsource(self, sourceent): + source = self.get_source(sourceent.type, sourceent.name, + sourceent.host_config, sourceent.eid) + if self.config.source_enabled(source): + # call source's init method to complete their initialisation if + # 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) + return source + # internals ############################################################### def _init_system_source(self):