server/sources/__init__.py
changeset 6427 c8a5ac2d1eaa
parent 6162 76bd320c5ace
child 6582 8eb7883b4223
equal deleted inserted replaced
6426:541659c39f6a 6427:c8a5ac2d1eaa
    97 
    97 
    98     # multi-sources planning control
    98     # multi-sources planning control
    99     dont_cross_relations = ()
    99     dont_cross_relations = ()
   100     cross_relations = ()
   100     cross_relations = ()
   101 
   101 
   102 
   102     # force deactivation (configuration error for instance)
   103     def __init__(self, repo, appschema, source_config, *args, **kwargs):
   103     disabled = False
       
   104 
       
   105     def __init__(self, repo, source_config, *args, **kwargs):
   104         self.repo = repo
   106         self.repo = repo
   105         self.uri = source_config['uri']
   107         self.uri = source_config['uri']
   106         set_log_methods(self, getLogger('cubicweb.sources.'+self.uri))
   108         set_log_methods(self, getLogger('cubicweb.sources.'+self.uri))
   107         self.set_schema(appschema)
   109         self.set_schema(repo.schema)
   108         self.support_relations['identity'] = False
   110         self.support_relations['identity'] = False
       
   111         self.eid = None
       
   112         self.cfg = source_config.copy()
       
   113         self.remove_sensitive_information(self.cfg)
   109 
   114 
   110     def init_creating(self):
   115     def init_creating(self):
   111         """method called by the repository once ready to create a new instance"""
   116         """method called by the repository once ready to create a new instance"""
   112         pass
   117         pass
   113 
   118 
   217         return self.repo.eid2extid(self, eid, session)
   222         return self.repo.eid2extid(self, eid, session)
   218 
   223 
   219     def extid2eid(self, value, etype, session=None, **kwargs):
   224     def extid2eid(self, value, etype, session=None, **kwargs):
   220         return self.repo.extid2eid(self, value, etype, session, **kwargs)
   225         return self.repo.extid2eid(self, value, etype, session, **kwargs)
   221 
   226 
   222     PUBLIC_KEYS = ('adapter', 'uri')
   227     PUBLIC_KEYS = ('type', 'uri')
   223     def remove_sensitive_information(self, sourcedef):
   228     def remove_sensitive_information(self, sourcedef):
   224         """remove sensitive information such as login / password from source
   229         """remove sensitive information such as login / password from source
   225         definition
   230         definition
   226         """
   231         """
   227         for key in sourcedef.keys():
   232         for key in sourcedef.keys():
   506     def rollback(self):
   511     def rollback(self):
   507         pass
   512         pass
   508     def cursor(self):
   513     def cursor(self):
   509         return None # no actual cursor support
   514         return None # no actual cursor support
   510 
   515 
       
   516 
   511 from cubicweb.server import SOURCE_TYPES
   517 from cubicweb.server import SOURCE_TYPES
   512 
   518 
   513 def source_adapter(source_config):
   519 def source_adapter(source_type):
   514     adapter_type = source_config['adapter'].lower()
       
   515     try:
   520     try:
   516         return SOURCE_TYPES[adapter_type]
   521         return SOURCE_TYPES[source_type]
   517     except KeyError:
   522     except KeyError:
   518         raise RuntimeError('Unknown adapter %r' % adapter_type)
   523         raise RuntimeError('Unknown source type %r' % source_type)
   519 
   524 
   520 def get_source(source_config, global_schema, repo):
   525 def get_source(type, source_config, repo):
   521     """return a source adapter according to the adapter field in the
   526     """return a source adapter according to the adapter field in the
   522     source's configuration
   527     source's configuration
   523     """
   528     """
   524     return source_adapter(source_config)(repo, global_schema, source_config)
   529     return source_adapter(type)(repo, source_config)