cubicweb/dataimport/stores.py
changeset 11307 74f5814ecdf0
parent 11304 1dad60d54dfb
child 11308 df75fe529ba8
equal deleted inserted replaced
11306:e759631889be 11307:74f5814ecdf0
   149         self.prepare_insert_relation(eid_from, rtype, eid_to, **kwargs)
   149         self.prepare_insert_relation(eid_from, rtype, eid_to, **kwargs)
   150 
   150 
   151 
   151 
   152 class NoHookRQLObjectStore(RQLObjectStore):
   152 class NoHookRQLObjectStore(RQLObjectStore):
   153     """Store that works by accessing low-level CubicWeb's source API, with all hooks deactivated. It
   153     """Store that works by accessing low-level CubicWeb's source API, with all hooks deactivated. It
   154     must be given a metadata generator object to handle metadata which are usually handled by hooks
   154     may be given a metadata generator object to handle metadata which are usually handled by hooks.
   155     (see :class:`MetaGenerator`).
   155 
       
   156     Arguments:
       
   157     - `cnx`, a connection to the repository
       
   158     - `metagen`, optional :class:`MetaGenerator` instance
   156     """
   159     """
   157 
   160 
   158     def __init__(self, cnx, metagen=None):
   161     def __init__(self, cnx, metagen=None):
   159         super(NoHookRQLObjectStore, self).__init__(cnx)
   162         super(NoHookRQLObjectStore, self).__init__(cnx)
   160         self.source = cnx.repo.system_source
   163         self._system_source = cnx.repo.system_source
   161         self._rschema = cnx.repo.schema.rschema
   164         self._rschema = cnx.repo.schema.rschema
   162         self._create_eid = cnx.repo.system_source.create_eid
   165         self._create_eid = cnx.repo.system_source.create_eid
   163         self._add_relation = self.source.add_relation
   166         self._add_relation = self.source.add_relation
   164         if metagen is None:
   167         if metagen is None:
   165             metagen = MetaGenerator(cnx)
   168             metagen = MetaGenerator(cnx)
   184         entity.cw_clear_relation_cache()
   187         entity.cw_clear_relation_cache()
   185         entity.cw_edited.update(kwargs, skipsec=False)
   188         entity.cw_edited.update(kwargs, skipsec=False)
   186         cnx = self._cnx
   189         cnx = self._cnx
   187         entity.eid = self._create_eid(cnx)
   190         entity.eid = self._create_eid(cnx)
   188         entity_source, extid = self.metagen.init_entity(entity)
   191         entity_source, extid = self.metagen.init_entity(entity)
   189         self.source.add_info(cnx, entity, entity_source, extid)
   192         self._system_source.add_info(cnx, entity, entity_source, extid)
   190         self.source.add_entity(cnx, entity)
   193         self._system_source.add_entity(cnx, entity)
   191         kwargs = dict()
   194         kwargs = dict()
   192         if inspect.getargspec(self._add_relation).keywords:
   195         if inspect.getargspec(self._add_relation).keywords:
   193             kwargs['subjtype'] = entity.cw_etype
   196             kwargs['subjtype'] = entity.cw_etype
   194         for rtype, targeteids in rels.items():
   197         for rtype, targeteids in rels.items():
   195             # targeteids may be a single eid or a list of eids
   198             # targeteids may be a single eid or a list of eids