server/sources/datafeed.py
changeset 10089 6346f53c85f1
parent 9990 c84ad981fc4a
child 10143 2eb06486273a
equal deleted inserted replaced
10088:ac63f7ec5af0 10089:6346f53c85f1
   340         """deleted CWSourceSchemaConfig, modify mapping accordingly"""
   340         """deleted CWSourceSchemaConfig, modify mapping accordingly"""
   341         msg = schemacfg._cw._("this parser doesn't use a mapping")
   341         msg = schemacfg._cw._("this parser doesn't use a mapping")
   342         raise ValidationError(schemacfg.eid, {None: msg})
   342         raise ValidationError(schemacfg.eid, {None: msg})
   343 
   343 
   344     def extid2entity(self, uri, etype, **sourceparams):
   344     def extid2entity(self, uri, etype, **sourceparams):
   345         """return an entity for the given uri. May return None if it should be
   345         """Return an entity for the given uri. May return None if it should be
   346         skipped
   346         skipped.
   347         """
   347 
       
   348         If a `raise_on_error` keyword parameter is passed, a ValidationError
       
   349         exception may be raised.
       
   350         """
       
   351         raise_on_error = sourceparams.pop('raise_on_error', False)
   348         cnx = self._cw
   352         cnx = self._cw
   349         # if cwsource is specified and repository has a source with the same
   353         # if cwsource is specified and repository has a source with the same
   350         # name, call extid2eid on that source so entity will be properly seen as
   354         # name, call extid2eid on that source so entity will be properly seen as
   351         # coming from this source
   355         # coming from this source
   352         source_uri = sourceparams.pop('cwsource', None)
   356         source_uri = sourceparams.pop('cwsource', None)
   359             uri = uri.encode('utf-8')
   363             uri = uri.encode('utf-8')
   360         try:
   364         try:
   361             eid = cnx.repo.extid2eid(source, str(uri), etype, cnx,
   365             eid = cnx.repo.extid2eid(source, str(uri), etype, cnx,
   362                                          sourceparams=sourceparams)
   366                                          sourceparams=sourceparams)
   363         except ValidationError as ex:
   367         except ValidationError as ex:
   364             # XXX use critical so they are seen during tests. Should consider
   368             if raise_on_error:
   365             # raise_on_error instead?
   369                 raise
   366             self.source.critical('error while creating %s: %s', etype, ex)
   370             self.source.critical('error while creating %s: %s', etype, ex)
   367             self.import_log.record_error('error while creating %s: %s'
   371             self.import_log.record_error('error while creating %s: %s'
   368                                          % (etype, ex))
   372                                          % (etype, ex))
   369             return None
   373             return None
   370         if eid < 0:
   374         if eid < 0:
   451         error = False
   455         error = False
   452         commit = self._cw.commit
   456         commit = self._cw.commit
   453         rollback = self._cw.rollback
   457         rollback = self._cw.rollback
   454         for args in parsed:
   458         for args in parsed:
   455             try:
   459             try:
   456                 self.process_item(*args)
   460                 self.process_item(*args, raise_on_error=raise_on_error)
   457                 # commit+set_cnxset instead of commit(free_cnxset=False) to let
   461                 # commit+set_cnxset instead of commit(free_cnxset=False) to let
   458                 # other a chance to get our connections set
   462                 # other a chance to get our connections set
   459                 commit()
   463                 commit()
   460             except ValidationError as exc:
   464             except ValidationError as exc:
   461                 if raise_on_error:
   465                 if raise_on_error:
   471         return self.parse_etree(etree.parse(stream).getroot())
   475         return self.parse_etree(etree.parse(stream).getroot())
   472 
   476 
   473     def parse_etree(self, document):
   477     def parse_etree(self, document):
   474         return [(document,)]
   478         return [(document,)]
   475 
   479 
   476     def process_item(self, *args):
   480     def process_item(self, *args, **kwargs):
   477         raise NotImplementedError
   481         raise NotImplementedError
   478 
   482 
   479     def is_deleted(self, extid, etype, eid):
   483     def is_deleted(self, extid, etype, eid):
   480         if extid.startswith('http'):
   484         if extid.startswith('http'):
   481             try:
   485             try: