server/sources/datafeed.py
branchstable
changeset 7697 ef50074a0314
parent 7642 64eee2a83bfa
child 7698 1c7411535c2d
equal deleted inserted replaced
7695:2f6e37661cf6 7697:ef50074a0314
   265 
   265 
   266     def extid2entity(self, uri, etype, **sourceparams):
   266     def extid2entity(self, uri, etype, **sourceparams):
   267         """return an entity for the given uri. May return None if it should be
   267         """return an entity for the given uri. May return None if it should be
   268         skipped
   268         skipped
   269         """
   269         """
       
   270         session = self._cw
   270         # if cwsource is specified and repository has a source with the same
   271         # if cwsource is specified and repository has a source with the same
   271         # name, call extid2eid on that source so entity will be properly seen as
   272         # name, call extid2eid on that source so entity will be properly seen as
   272         # coming from this source
   273         # coming from this source
   273         source = self._cw.repo.sources_by_uri.get(
   274         source = session.repo.sources_by_uri.get(
   274             sourceparams.pop('cwsource', None), self.source)
   275             sourceparams.pop('cwsource', None), self.source)
   275         sourceparams['parser'] = self
   276         sourceparams['parser'] = self
   276         try:
   277         try:
   277             eid = source.extid2eid(str(uri), etype, self._cw,
   278             eid = session.repo.extid2eid(source, str(uri), etype, session,
   278                                    sourceparams=sourceparams)
   279                                    sourceparams=sourceparams)
   279         except ValidationError, ex:
   280         except ValidationError, ex:
   280             self.source.error('error while creating %s: %s', etype, ex)
   281             self.source.error('error while creating %s: %s', etype, ex)
   281             return None
   282             return None
   282         if eid < 0:
   283         if eid < 0:
   283             # entity has been moved away from its original source
   284             # entity has been moved away from its original source
   284             #
   285             #
   285             # Don't give etype to entity_from_eid so we get UnknownEid if the
   286             # Don't give etype to entity_from_eid so we get UnknownEid if the
   286             # entity has been removed
   287             # entity has been removed
   287             try:
   288             try:
   288                 entity = self._cw.entity_from_eid(-eid)
   289                 entity = session.entity_from_eid(-eid)
   289             except UnknownEid:
   290             except UnknownEid:
   290                 return None
   291                 return None
   291             self.notify_updated(entity) # avoid later update from the source's data
   292             self.notify_updated(entity) # avoid later update from the source's data
   292             return entity
   293             return entity
   293         if self.sourceuris is not None:
   294         if self.sourceuris is not None:
   294             self.sourceuris.pop(str(uri), None)
   295             self.sourceuris.pop(str(uri), None)
   295         return self._cw.entity_from_eid(eid, etype)
   296         return session.entity_from_eid(eid, etype)
   296 
   297 
   297     def process(self, url, partialcommit=True):
   298     def process(self, url, partialcommit=True):
   298         """main callback: process the url"""
   299         """main callback: process the url"""
   299         raise NotImplementedError
   300         raise NotImplementedError
   300 
   301