cubicweb/dataimport/importer.py
changeset 12173 d13fc09301bd
parent 12167 1ca864397424
child 12625 ba5231e1aa45
equal deleted inserted replaced
12172:8bb323eb6859 12173:d13fc09301bd
   250         for rtype in entity_dict:
   250         for rtype in entity_dict:
   251             rschema = schema.rschema(rtype)
   251             rschema = schema.rschema(rtype)
   252             if rschema.inlined:
   252             if rschema.inlined:
   253                 entity_dict[rtype] = extid2eid[entity_dict[rtype]]
   253                 entity_dict[rtype] = extid2eid[entity_dict[rtype]]
   254         return True
   254         return True
       
   255 
       
   256     def why_not_ready(self, extid2eid):
       
   257         """Return some text explaining why this ext entity is not ready.
       
   258         """
       
   259         assert self._schema, 'prepare() method should be called first on %s' % self
       
   260         # as .prepare has been called, we know that .values only contains subject relation *type* as
       
   261         # key (no more (rtype, role) tuple)
       
   262         schema = self._schema
       
   263         entity_dict = self.values
       
   264         for rtype in entity_dict:
       
   265             rschema = schema.rschema(rtype)
       
   266             if not rschema.final:
       
   267                 if entity_dict[rtype] not in extid2eid:
       
   268                     return u'inlined relation %s is not present (%s)' % (rtype, entity_dict[rtype])
       
   269         raise AssertionError('this external entity seems actually ready for insertion')
   255 
   270 
   256 
   271 
   257 class ExtEntitiesImporter(object):
   272 class ExtEntitiesImporter(object):
   258     """This class is responsible for importing externals entities, that is instances of
   273     """This class is responsible for importing externals entities, that is instances of
   259     :class:`ExtEntity`, into CubicWeb entities.
   274     :class:`ExtEntity`, into CubicWeb entities.
   411         if queue:
   426         if queue:
   412             msgs = ["can't create some entities, is there some cycle or "
   427             msgs = ["can't create some entities, is there some cycle or "
   413                     "missing data?"]
   428                     "missing data?"]
   414             for ext_entities in queue.values():
   429             for ext_entities in queue.values():
   415                 for ext_entity in ext_entities:
   430                 for ext_entity in ext_entities:
   416                     msgs.append(str(ext_entity))
   431                     msg = '{}: {}'.format(ext_entity, ext_entity.why_not_ready(self.extid2eid))
       
   432                     msgs.append(msg)
   417             map(error, msgs)
   433             map(error, msgs)
   418             if self.raise_on_error:
   434             if self.raise_on_error:
   419                 raise Exception('\n'.join(msgs))
   435                 raise Exception('\n'.join(msgs))
   420         if missing_relations:
   436         if missing_relations:
   421             msgs = ["can't create some relations, is there missing data?"]
   437             msgs = ["can't create some relations, is there missing data?"]