server/sources/__init__.py
changeset 6427 c8a5ac2d1eaa
parent 6162 76bd320c5ace
child 6582 8eb7883b4223
--- a/server/sources/__init__.py	Sat Oct 09 00:05:50 2010 +0200
+++ b/server/sources/__init__.py	Sat Oct 09 00:05:52 2010 +0200
@@ -99,13 +99,18 @@
     dont_cross_relations = ()
     cross_relations = ()
 
+    # force deactivation (configuration error for instance)
+    disabled = False
 
-    def __init__(self, repo, appschema, source_config, *args, **kwargs):
+    def __init__(self, repo, source_config, *args, **kwargs):
         self.repo = repo
         self.uri = source_config['uri']
         set_log_methods(self, getLogger('cubicweb.sources.'+self.uri))
-        self.set_schema(appschema)
+        self.set_schema(repo.schema)
         self.support_relations['identity'] = False
+        self.eid = None
+        self.cfg = source_config.copy()
+        self.remove_sensitive_information(self.cfg)
 
     def init_creating(self):
         """method called by the repository once ready to create a new instance"""
@@ -219,7 +224,7 @@
     def extid2eid(self, value, etype, session=None, **kwargs):
         return self.repo.extid2eid(self, value, etype, session, **kwargs)
 
-    PUBLIC_KEYS = ('adapter', 'uri')
+    PUBLIC_KEYS = ('type', 'uri')
     def remove_sensitive_information(self, sourcedef):
         """remove sensitive information such as login / password from source
         definition
@@ -508,17 +513,17 @@
     def cursor(self):
         return None # no actual cursor support
 
+
 from cubicweb.server import SOURCE_TYPES
 
-def source_adapter(source_config):
-    adapter_type = source_config['adapter'].lower()
+def source_adapter(source_type):
     try:
-        return SOURCE_TYPES[adapter_type]
+        return SOURCE_TYPES[source_type]
     except KeyError:
-        raise RuntimeError('Unknown adapter %r' % adapter_type)
+        raise RuntimeError('Unknown source type %r' % source_type)
 
-def get_source(source_config, global_schema, repo):
+def get_source(type, source_config, repo):
     """return a source adapter according to the adapter field in the
     source's configuration
     """
-    return source_adapter(source_config)(repo, global_schema, source_config)
+    return source_adapter(type)(repo, source_config)