[multi-sources] support for moving an entity from an external source (closes #343818)
Original need is to move a user from a ldap source to the system source so
we can delete it from ldap without loosing information into the cubicweb
instance.
We can't wait for the user to be deleted from the ldap since it will be too
late then to get back user attributes, so it has to be a manual operation to
operate before actual deletion. This makes sense for other sources as well.
So the idea is to make the "Any cw_source CWSource" relation editable by
managers, and to watch changes of it. We then check the move is possible
(ie from an external source to the system source) and do necessary stuff
(essentially changing source information and copying data into the system
source).
Remaining pb is that we don't want the moved entity to be reimported later.
To distinguish this state, the trick is to change the associated record in
the 'entities' system table with eid=-eid while leaving other fields
unchanged, and to add a new record with eid=eid, source='system'. External
source will then have consider case where `extid2eid` return a negative eid
as 'this entity was known but has been moved, ignore it'.
Notice no ui is provided yet, it has currently to be done in a c-c shell.
# copyright 2003-2010 LOGILAB S.A. (Paris, FRANCE), all rights reserved.# contact http://www.logilab.fr/ -- mailto:contact@logilab.fr## This file is part of CubicWeb.## CubicWeb is free software: you can redistribute it and/or modify it under the# terms of the GNU Lesser General Public License as published by the Free# Software Foundation, either version 2.1 of the License, or (at your option)# any later version.## CubicWeb is distributed in the hope that it will be useful, but WITHOUT# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS# FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more# details.## You should have received a copy of the GNU Lesser General Public License along# with CubicWeb. If not, see <http://www.gnu.org/licenses/>."""Pyro RQL server"""__docformat__="restructuredtext en"importosimportsysimportselectimportwarningsfromtimeimportlocaltime,mktimefromcubicweb.cwconfigimportCubicWebConfigurationfromcubicweb.server.repositoryimportRepositoryclassFinished(Exception):"""raise to remove an event from the event loop"""classTimeEvent:"""base event"""# timefunc = staticmethod(localtime)timefunc=localtimedef__init__(self,absolute=None,period=None):# local time tupleifabsoluteisNone:absolute=self.timefunc()self.absolute=absolute# optional period in secondsself.period=perioddefis_ready(self):"""return true if the event is ready to be fired"""now=self.timefunc()ifself.absolute<now:returnTruereturnFalsedeffire(self,server):"""fire the event must be overridden by concrete events """raiseNotImplementedError()defupdate(self):"""update the absolute date for the event or raise a finished exception """ifself.periodisNone:raiseFinishedself.absolute=localtime(mktime(self.absolute)+self.period)classQuitEvent(TimeEvent):"""stop the server"""deffire(self,server):server.repo.shutdown()server.quiting=TrueclassRepositoryServer(object):def__init__(self,config):"""make the repository available as a PyRO object"""self.config=configself.repo=Repository(config)self.ns=Noneself.quiting=None# event queueself.events=[]defadd_event(self,event):"""add an event to the loop"""self.info('adding event %s',event)self.events.append(event)deftrigger_events(self):"""trigger ready events"""foreventinself.events[:]:ifevent.is_ready():self.info('starting event %s',event)event.fire(self)try:event.update()exceptFinished:self.events.remove(event)defrun(self,req_timeout=5.0):"""enter the service loop"""# start repository looping tasksself.repo.start_looping_tasks()whileself.quitingisNone:try:self.daemon.handleRequests(req_timeout)exceptselect.error:continueself.trigger_events()defquit(self):"""stop the server"""self.add_event(QuitEvent())defconnect(self,host='',port=0):"""the connect method on the repository only register to pyro if necessary """self.daemon=self.repo.pyro_register(host)# server utilitities ######################################################definstall_sig_handlers(self):"""install signal handlers"""importsignalself.info('installing signal handlers')signal.signal(signal.SIGINT,lambdax,y,s=self:s.quit())signal.signal(signal.SIGTERM,lambdax,y,s=self:s.quit())fromloggingimportgetLoggerfromcubicwebimportset_log_methodsLOGGER=getLogger('cubicweb.reposerver')set_log_methods(RepositoryServer,LOGGER)