Commit 2279bf76 authored by Nicolas Delaby's avatar Nicolas Delaby

Code typo improvements, bug fix on reset, hide logs for better performance

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@15796 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 3190340c
...@@ -177,7 +177,7 @@ class ERP5Conduit(XMLSyncUtilsMixin): ...@@ -177,7 +177,7 @@ class ERP5Conduit(XMLSyncUtilsMixin):
if previous_xml is not None and sub_object_id is not None: if previous_xml is not None and sub_object_id is not None:
# Find the previous xml corresponding to this subobject # Find the previous xml corresponding to this subobject
sub_previous_xml = self.getSubObjectXml(sub_object_id, previous_xml) sub_previous_xml = self.getSubObjectXml(sub_object_id, previous_xml)
LOG('addNode', DEBUG,'isSubObjectModification sub_previous_xml: %s' % str(sub_previous_xml)) #LOG('addNode', DEBUG,'isSubObjectModification sub_previous_xml: %s' % str(sub_previous_xml))
if sub_previous_xml is not None: if sub_previous_xml is not None:
sub_object = None sub_object = None
try: try:
...@@ -185,11 +185,11 @@ class ERP5Conduit(XMLSyncUtilsMixin): ...@@ -185,11 +185,11 @@ class ERP5Conduit(XMLSyncUtilsMixin):
except (AttributeError, KeyError, TypeError): except (AttributeError, KeyError, TypeError):
pass pass
if sub_object is not None: if sub_object is not None:
LOG('addNode', DEBUG, 'subobject.id: %s' % sub_object.id) #LOG('addNode', DEBUG, 'subobject.id: %s' % sub_object.id)
# Change the xml in order to directly apply # Change the xml in order to directly apply
# modifications to the subobject # modifications to the subobject
sub_xml = self.getSubObjectXupdate(xml) sub_xml = self.getSubObjectXupdate(xml)
LOG('addNode', DEBUG, 'sub_xml: %s' % str(sub_xml)) #LOG('addNode', DEBUG, 'sub_xml: %s' % str(sub_xml))
# Then do the udpate # Then do the udpate
conflict_list += self.addNode(xml=sub_xml,object=sub_object, conflict_list += self.addNode(xml=sub_xml,object=sub_object,
previous_xml=sub_previous_xml, force=force, previous_xml=sub_previous_xml, force=force,
...@@ -214,12 +214,12 @@ class ERP5Conduit(XMLSyncUtilsMixin): ...@@ -214,12 +214,12 @@ class ERP5Conduit(XMLSyncUtilsMixin):
A node is deleted A node is deleted
""" """
# In the case where we have to delete an object # In the case where we have to delete an object
LOG('ERP5Conduit.deleteNode', DEBUG, 'deleteNode, object path: %s' % repr(object.getPhysicalPath())) #LOG('ERP5Conduit.deleteNode', DEBUG, 'deleteNode, object path: %s' % repr(object.getPhysicalPath()))
conflict_list = [] conflict_list = []
if xml is not None: if xml is not None:
xml = self.convertToXml(xml) xml = self.convertToXml(xml)
if object_id is None: if object_id is None:
LOG('ERP5Conduit.deleteNode', DEBUG, 'deleteNode, SubObjectDepth: %i' % self.getSubObjectDepth(xml)) #LOG('ERP5Conduit.deleteNode', DEBUG, 'deleteNode, SubObjectDepth: %i' % self.getSubObjectDepth(xml))
if xml.nodeName == self.xml_object_tag: if xml.nodeName == self.xml_object_tag:
object_id = self.getAttribute(xml,'id') object_id = self.getAttribute(xml,'id')
elif self.getSubObjectDepth(xml)==1: elif self.getSubObjectDepth(xml)==1:
...@@ -233,7 +233,7 @@ class ERP5Conduit(XMLSyncUtilsMixin): ...@@ -233,7 +233,7 @@ class ERP5Conduit(XMLSyncUtilsMixin):
conflict_list += self.deleteNode(xml=sub_xml,object=sub_object, conflict_list += self.deleteNode(xml=sub_xml,object=sub_object,
force=force, simulate=simulate, **kw) force=force, simulate=simulate, **kw)
except (KeyError, AttributeError, TypeError): except (KeyError, AttributeError, TypeError):
LOG('ERP5Conduit.deleteNode', DEBUG, 'deleteNode, Unable to delete SubObject: %s' % str(sub_object_id)) #LOG('ERP5Conduit.deleteNode', DEBUG, 'deleteNode, Unable to delete SubObject: %s' % str(sub_object_id))
pass pass
if object_id is not None: # We do have an object_id if object_id is not None: # We do have an object_id
self.deleteObject(object, object_id) self.deleteObject(object, object_id)
...@@ -244,7 +244,7 @@ class ERP5Conduit(XMLSyncUtilsMixin): ...@@ -244,7 +244,7 @@ class ERP5Conduit(XMLSyncUtilsMixin):
if xml.nodeName in self.local_role_list and not simulate: if xml.nodeName in self.local_role_list and not simulate:
# We want to del a local role # We want to del a local role
user = self.getAttribute(xml,'id') user = self.getAttribute(xml,'id')
LOG('ERP5Conduit.deleteNode local_role: ', DEBUG, 'user: %s' % repr(user)) #LOG('ERP5Conduit.deleteNode local_role: ', DEBUG, 'user: %s' % repr(user))
if xml.nodeName.find(self.local_role_tag)>=0: if xml.nodeName.find(self.local_role_tag)>=0:
object.manage_delLocalRoles([user]) object.manage_delLocalRoles([user])
elif xml.nodeName.find(self.local_group_tag)>=0: elif xml.nodeName.find(self.local_group_tag)>=0:
...@@ -259,7 +259,7 @@ class ERP5Conduit(XMLSyncUtilsMixin): ...@@ -259,7 +259,7 @@ class ERP5Conduit(XMLSyncUtilsMixin):
try: try:
object._delObject(object_id) object._delObject(object_id)
except (AttributeError, KeyError): except (AttributeError, KeyError):
LOG('ERP5Conduit.deleteObject', DEBUG, 'Unable to delete: %s' % str(object_id)) #LOG('ERP5Conduit.deleteObject', DEBUG, 'Unable to delete: %s' % str(object_id))
pass pass
security.declareProtected(Permissions.ModifyPortalContent, 'updateNode') security.declareProtected(Permissions.ModifyPortalContent, 'updateNode')
...@@ -274,8 +274,8 @@ class ERP5Conduit(XMLSyncUtilsMixin): ...@@ -274,8 +274,8 @@ class ERP5Conduit(XMLSyncUtilsMixin):
""" """
conflict_list = [] conflict_list = []
xml = self.convertToXml(xml) xml = self.convertToXml(xml)
LOG('ERP5Conduit.updateNode', DEBUG, 'xml.nodeName: %s' % xml.nodeName) #LOG('ERP5Conduit.updateNode', DEBUG, 'xml.nodeName: %s' % xml.nodeName)
LOG('ERP5Conduit.updateNode, force: ', DEBUG, force) #LOG('ERP5Conduit.updateNode, force: ', DEBUG, force)
# we have an xupdate xml # we have an xupdate xml
if xml.nodeName == 'xupdate:modifications': if xml.nodeName == 'xupdate:modifications':
conflict_list += self.applyXupdate(object=object, xupdate=xml, conflict_list += self.applyXupdate(object=object, xupdate=xml,
...@@ -332,7 +332,7 @@ class ERP5Conduit(XMLSyncUtilsMixin): ...@@ -332,7 +332,7 @@ class ERP5Conduit(XMLSyncUtilsMixin):
if not (keyword in self.NOT_EDITABLE_PROPERTY): if not (keyword in self.NOT_EDITABLE_PROPERTY):
# We will look for the data to enter # We will look for the data to enter
data_type = object.getPropertyType(keyword) data_type = object.getPropertyType(keyword)
LOG('ERP5Conduit.updateNode', DEBUG, 'data_type: %s for keyword: %s' % (str(data_type), keyword)) #LOG('ERP5Conduit.updateNode', DEBUG, 'data_type: %s for keyword: %s' % (str(data_type), keyword))
data = self.convertXmlValue(data,data_type=data_type) data = self.convertXmlValue(data,data_type=data_type)
args[keyword] = data args[keyword] = data
args = self.getFormatedArgs(args=args) args = self.getFormatedArgs(args=args)
...@@ -349,12 +349,12 @@ class ERP5Conduit(XMLSyncUtilsMixin): ...@@ -349,12 +349,12 @@ class ERP5Conduit(XMLSyncUtilsMixin):
data_type=data_type) data_type=data_type)
#current_data = object.getProperty(keyword) #current_data = object.getProperty(keyword)
current_data = self.getProperty(object, keyword) current_data = self.getProperty(object, keyword)
LOG('ERP5Conduit.updateNode', DEBUG, 'Conflict data: %s' % str(data)) #LOG('ERP5Conduit.updateNode', DEBUG, 'Conflict data: %s' % str(data))
LOG('ERP5Conduit.updateNode', DEBUG, 'Conflict old_data: %s' % str(old_data)) #LOG('ERP5Conduit.updateNode', DEBUG, 'Conflict old_data: %s' % str(old_data))
LOG('ERP5Conduit.updateNode', DEBUG, 'Conflict current_data: %s' % str(current_data)) #LOG('ERP5Conduit.updateNode', DEBUG, 'Conflict current_data: %s' % str(current_data))
if (old_data != current_data) and (data != current_data) \ if (old_data != current_data) and (data != current_data) \
and keyword not in self.force_conflict_list: and keyword not in self.force_conflict_list:
LOG('ERP5Conduit.updateNode', DEBUG, 'Conflict on : %s' % keyword) #LOG('ERP5Conduit.updateNode', DEBUG, 'Conflict on : %s' % keyword)
# Hack in order to get the synchronization working for demo # Hack in order to get the synchronization working for demo
# XXX this have to be removed after # XXX this have to be removed after
#if not (data_type in self.binary_type_list): #if not (data_type in self.binary_type_list):
...@@ -398,10 +398,10 @@ class ERP5Conduit(XMLSyncUtilsMixin): ...@@ -398,10 +398,10 @@ class ERP5Conduit(XMLSyncUtilsMixin):
# We should find the object corresponding to # We should find the object corresponding to
# this update, so we have to look in the previous_xml # this update, so we have to look in the previous_xml
sub_object_id = self.getSubObjectId(xml) sub_object_id = self.getSubObjectId(xml)
LOG('ERP5Conduit.updateNode', DEBUG,'isSubObjectModification sub_object_id: %s' % sub_object_id) #LOG('ERP5Conduit.updateNode', DEBUG,'isSubObjectModification sub_object_id: %s' % sub_object_id)
if previous_xml is not None and sub_object_id is not None: if previous_xml is not None and sub_object_id is not None:
sub_previous_xml = self.getSubObjectXml(sub_object_id,previous_xml) sub_previous_xml = self.getSubObjectXml(sub_object_id,previous_xml)
LOG('ERP5Conduit.updateNode', DEBUG, 'isSubObjectModification sub_previous_xml: %s' % str(sub_previous_xml)) #LOG('ERP5Conduit.updateNode', DEBUG, 'isSubObjectModification sub_previous_xml: %s' % str(sub_previous_xml))
if sub_previous_xml is not None: if sub_previous_xml is not None:
sub_object = None sub_object = None
try: try:
...@@ -409,11 +409,11 @@ class ERP5Conduit(XMLSyncUtilsMixin): ...@@ -409,11 +409,11 @@ class ERP5Conduit(XMLSyncUtilsMixin):
except KeyError: except KeyError:
pass pass
if sub_object is not None: if sub_object is not None:
LOG('ERP5Conduit.updateNode', DEBUG, 'subobject.id: %s' % sub_object.id) #LOG('ERP5Conduit.updateNode', DEBUG, 'subobject.id: %s' % sub_object.id)
# Change the xml in order to directly apply # Change the xml in order to directly apply
# modifications to the subobject # modifications to the subobject
sub_xml = self.getSubObjectXupdate(xml) sub_xml = self.getSubObjectXupdate(xml)
LOG('ERP5Conduit.updateNode', DEBUG, 'sub_xml: %s' % str(sub_xml)) #LOG('ERP5Conduit.updateNode', DEBUG, 'sub_xml: %s' % str(sub_xml))
# Then do the udpate # Then do the udpate
conflict_list += self.updateNode(xml=sub_xml, object=sub_object, conflict_list += self.updateNode(xml=sub_xml, object=sub_object,
force=force, previous_xml=sub_previous_xml, force=force, previous_xml=sub_previous_xml,
...@@ -470,7 +470,7 @@ class ERP5Conduit(XMLSyncUtilsMixin): ...@@ -470,7 +470,7 @@ class ERP5Conduit(XMLSyncUtilsMixin):
data = data.encode(self.getEncoding()) data = data.encode(self.getEncoding())
data = data.replace('@@@','\n') data = data.replace('@@@','\n')
if keyword == 'binary_data': if keyword == 'binary_data':
LOG('ERP5Conduit.getFormatedArgs', DEBUG, 'binary_data keyword: %s' % str(keyword)) #LOG('ERP5Conduit.getFormatedArgs', DEBUG, 'binary_data keyword: %s' % str(keyword))
msg = MIMEBase('application','octet-stream') msg = MIMEBase('application','octet-stream')
Encoders.encode_base64(msg) Encoders.encode_base64(msg)
msg.set_payload(data) msg.set_payload(data)
...@@ -1173,9 +1173,9 @@ class ERP5Conduit(XMLSyncUtilsMixin): ...@@ -1173,9 +1173,9 @@ class ERP5Conduit(XMLSyncUtilsMixin):
""" """
return object.getId() return object.getId()
def getGidFromXML(self, xml, gid_from_xml_list): #def getGidFromXML(self, xml, gid_from_xml_list):
""" #"""
return the Gid composed with xml informations #return the Gid composed with xml informations
""" #"""
return None #return None
...@@ -230,7 +230,7 @@ class Publication(Subscription): ...@@ -230,7 +230,7 @@ class Publication(Subscription):
Reset all subscribers Reset all subscribers
""" """
for o in self.getSubscriberList(): for o in self.getSubscriberList():
self.activate().manage_delObjects(o.id) self.activate(activity='SQLQueue').manage_delObjects(o.id)
def getConflictList(self): def getConflictList(self):
""" """
......
...@@ -90,7 +90,7 @@ class PublicationSynchronization(XMLSyncUtils): ...@@ -90,7 +90,7 @@ class PublicationSynchronization(XMLSyncUtils):
next_anchor) next_anchor)
if subscriber.getNextAnchor() != last_anchor: if subscriber.getNextAnchor() != last_anchor:
if last_anchor in (None, ''): if last_anchor in (None, ''):
LOG('PubSyncInit', DEBUG, 'anchor null') LOG('PubSyncInit', INFO, 'anchor null')
else: else:
message = "bad anchors in PubSyncInit! " + \ message = "bad anchors in PubSyncInit! " + \
subscriber.getNextAnchor() + " and " + last_anchor subscriber.getNextAnchor() + " and " + last_anchor
...@@ -200,74 +200,6 @@ class PublicationSynchronization(XMLSyncUtils): ...@@ -200,74 +200,6 @@ class PublicationSynchronization(XMLSyncUtils):
return {'has_response':1, 'xml':xml_a} return {'has_response':1, 'xml':xml_a}
def PubSync(self, publication_path, msg=None, RESPONSE=None, subscriber=None):
"""
This is the synchronization method for the server
"""
LOG('PubSync', DEBUG, 'Starting... publication: %s' % (publication_path))
# Read the request from the client
publication = self.unrestrictedTraverse(publication_path)
xml_client = msg
if xml_client is None:
xml_client = self.readResponse(from_url=publication.getPublicationUrl())
LOG('PubSync', DEBUG, 'Starting... msg: %s' % str(xml_client))
result = None
if xml_client is not None:
if isinstance(xml_client, str) or isinstance(xml_client, unicode):
xml_client = Parse(xml_client)
first_node = xml_client.childNodes[0]
if first_node.nodeName != "SyncML":
LOG('PubSync', INFO, 'This is not a SyncML Message')
raise ValueError, "Sorry, This is not a SyncML Message"
alert_code = self.getAlertCodeFromXML(xml_client)
# Get informations from the header
client_header = first_node.childNodes[1]
if client_header.nodeName != "SyncHdr":
LOG('PubSync', INFO, 'This is not a SyncML Header')
raise ValueError, "Sorry, This is not a SyncML Header"
subscription_url = self.getSubscriptionUrl(client_header)
# Get the subscriber or create it if not already in the list
subscriber = publication.getSubscriber(subscription_url)
if subscriber == None:
subscriber = Subscriber(publication.generateNewId(),subscription_url)
subscriber.setXMLMapping(publication.getXMLMapping())
subscriber.setConduit(publication.getConduit())
publication.addSubscriber(subscriber)
# first synchronization
result = self.PubSyncInit(publication,xml_client,subscriber=subscriber,
sync_type=self.SLOW_SYNC)
elif self.checkAlert(xml_client) and \
alert_code in (self.TWO_WAY, self.SLOW_SYNC, \
self.ONE_WAY_FROM_SERVER):
subscriber.setXMLMapping(publication.getXMLMapping())
subscriber.setConduit(publication.getConduit())
result = self.PubSyncInit(publication=publication,
xml_client=xml_client, subscriber=subscriber, sync_type=alert_code)
else:
#we log the user authenticated to do the synchronization with him
if self.checkMap(xml_client) :
self.setRidWithMap(xml_client, subscriber)
if subscriber.isAuthenticated():
uf = self.getPortalObject().acl_users
user = uf.getUserById(subscriber.getUser()).__of__(uf)
newSecurityManager(None, user)
result = self.PubSyncModif(publication, xml_client)
else:
result = self.PubSyncModif(publication, xml_client)
elif subscriber is not None:
# This looks like we are starting a synchronization after
# a conflict resolution by the user
result = self.PubSyncInit(publication=publication, xml_client=None,
subscriber=subscriber, sync_type=self.TWO_WAY)
if RESPONSE is not None:
RESPONSE.redirect('managePublications')
elif result is not None:
return result
def PubSyncModif(self, publication, xml_client): def PubSyncModif(self, publication, xml_client):
""" """
The modidification message for the publication The modidification message for the publication
......
...@@ -262,7 +262,6 @@ class Signature(Folder, SyncCode): ...@@ -262,7 +262,6 @@ class Signature(Folder, SyncCode):
else: else:
self.setPath(None) self.setPath(None)
self.setId(id) self.setId(id)
self.setGid(id)
self.setRid(rid) self.setRid(rid)
self.status = status self.status = status
self.setXML(xml_string) self.setXML(xml_string)
...@@ -468,19 +467,11 @@ class Signature(Folder, SyncCode): ...@@ -468,19 +467,11 @@ class Signature(Folder, SyncCode):
""" """
return self.id return self.id
def setGid(self, gid):
"""
set the gid
"""
if gid is type(u'a'):
gid = gid.encode('utf-8')
self.gid = gid
def getGid(self): def getGid(self):
""" """
get the gid get the gid
""" """
return self.gid return self.getId()
def setObjectId(self, id): def setObjectId(self, id):
""" """
...@@ -503,6 +494,8 @@ class Signature(Folder, SyncCode): ...@@ -503,6 +494,8 @@ class Signature(Folder, SyncCode):
""" """
if type(xml) is type(u'a'): if type(xml) is type(u'a'):
xml = xml.encode('utf-8') xml = xml.encode('utf-8')
if xml is not None:
xml = self.xml.replace('@-@@-@','--') # need to put back '--'
self.partial_xml = xml self.partial_xml = xml
def getPartialXML(self): def getPartialXML(self):
...@@ -510,9 +503,6 @@ class Signature(Folder, SyncCode): ...@@ -510,9 +503,6 @@ class Signature(Folder, SyncCode):
Set the partial string we will have to Set the partial string we will have to
deliver in the future deliver in the future
""" """
#LOG('Subscriber.getPartialXML', DEBUG, 'partial_xml: %s' % str(self.partial_xml))
if self.partial_xml is not None:
self.partial_xml = self.partial_xml.replace('@-@@-@','--') # need to put back '--'
return self.partial_xml return self.partial_xml
def getAction(self): def getAction(self):
...@@ -531,11 +521,10 @@ class Signature(Folder, SyncCode): ...@@ -531,11 +521,10 @@ class Signature(Folder, SyncCode):
""" """
Return the actual action for a partial synchronization Return the actual action for a partial synchronization
""" """
conflict_list = [] returned_conflict_list = []
if len(self.conflict_list)>0: if len(self.conflict_list)>0:
for conflict in self.conflict_list: returned_conflict_list.extend(self.conflict_list)
conflict_list += [conflict] return returned_conflict_list
return conflict_list
def resetConflictList(self): def resetConflictList(self):
""" """
...@@ -547,7 +536,7 @@ class Signature(Folder, SyncCode): ...@@ -547,7 +536,7 @@ class Signature(Folder, SyncCode):
""" """
Return the actual action for a partial synchronization Return the actual action for a partial synchronization
""" """
if conflict_list is None or conflict_list==[]: if conflict_list is None or conflict_list == []:
self.resetConflictList() self.resetConflictList()
else: else:
self.conflict_list = conflict_list self.conflict_list = conflict_list
...@@ -556,7 +545,6 @@ class Signature(Folder, SyncCode): ...@@ -556,7 +545,6 @@ class Signature(Folder, SyncCode):
""" """
Return the actual action for a partial synchronization Return the actual action for a partial synchronization
""" """
LOG('delConflict, conflict', DEBUG, conflict)
conflict_list = [] conflict_list = []
for c in self.getConflictList(): for c in self.getConflictList():
#LOG('delConflict, c==conflict',0,c==aq_base(conflict)) #LOG('delConflict, c==conflict',0,c==aq_base(conflict))
...@@ -774,7 +762,7 @@ class Subscription(Folder, XMLSyncUtils): ...@@ -774,7 +762,7 @@ class Subscription(Folder, XMLSyncUtils):
# LOG('getSignature', DEBUG, 'signatures_status: %s' % str(dict_sign)) # LOG('getSignature', DEBUG, 'signatures_status: %s' % str(dict_sign))
# XXXXXXXXXXXXXXXXXXXXXXXXXXXXX # XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
code = self.SLOW_SYNC code = self.SLOW_SYNC
if len(self.getSignatureList()) > 0: if len(self.getSignatureList()[:1]) > 0:
code = self.getAlertCode() code = self.getAlertCode()
if default is not None: if default is not None:
code = default code = default
...@@ -825,8 +813,8 @@ class Subscription(Folder, XMLSyncUtils): ...@@ -825,8 +813,8 @@ class Subscription(Folder, XMLSyncUtils):
return True if the message id was not seen, False if already seen return True if the message id was not seen, False if already seen
""" """
last_message_id = getattr(self,'last_message_id',None) last_message_id = getattr(self,'last_message_id',None)
LOG('checkCorrectRemoteMessageId last_message_id = ', DEBUG, last_message_id) #LOG('checkCorrectRemoteMessageId last_message_id = ', DEBUG, last_message_id)
LOG('checkCorrectRemoteMessageId message_id = ', DEBUG, message_id) #LOG('checkCorrectRemoteMessageId message_id = ', DEBUG, message_id)
if last_message_id == message_id: if last_message_id == message_id:
return False return False
self.last_message_id = message_id self.last_message_id = message_id
...@@ -1015,7 +1003,7 @@ class Subscription(Folder, XMLSyncUtils): ...@@ -1015,7 +1003,7 @@ class Subscription(Folder, XMLSyncUtils):
if authentication_format in (None, ''): if authentication_format in (None, ''):
self.authentication_format = 'b64' self.authentication_format = 'b64'
else: else:
self.authentication_format=authentication_format self.authentication_format = authentication_format
def setAuthenticationType(self, authentication_type): def setAuthenticationType(self, authentication_type):
""" """
...@@ -1034,22 +1022,13 @@ class Subscription(Folder, XMLSyncUtils): ...@@ -1034,22 +1022,13 @@ class Subscription(Folder, XMLSyncUtils):
conduit_name = self.getConduit() conduit_name = self.getConduit()
conduit = self.getConduitByName(conduit_name) conduit = self.getConduitByName(conduit_name)
gid_gen = getattr(conduit, 'getGidFromObject', None) gid_gen = getattr(conduit, 'getGidFromObject', None)
LOG('getGidFromObject, Conduit :', DEBUG, conduit_name)
LOG('getGidFromObject, gid_gen:', DEBUG, gid_gen)
if callable(gid_gen): if callable(gid_gen):
o_gid = gid_gen(object) o_gid = gid_gen(object)
else: else:
raise ValueError, "The conduit "+conduit_name+"seems to not have a \ raise ValueError, "The conduit "+conduit_name+"seems to not have a \
getGidFromObject method and it must" getGidFromObject method and it must"
# elif getattr(o_base, gid_gen, None) is not None:
# generator = getattr(object, gid_gen)
# o_gid = generator() # XXX - used to be o_gid = generator(object=object) which is redundant
# elif gid_gen is not None:
# # It might be a script python
# generator = getattr(object,gid_gen)
# o_gid = generator() # XXX - used to be o_gid = generator(object=object) which is redundant
o_gid = b16encode(o_gid) o_gid = b16encode(o_gid)
LOG('getGidFromObject returning', DEBUG, o_gid) #LOG('getGidFromObject returning', DEBUG, o_gid)
return o_gid return o_gid
def getObjectFromGid(self, gid): def getObjectFromGid(self, gid):
...@@ -1074,17 +1053,17 @@ class Subscription(Folder, XMLSyncUtils): ...@@ -1074,17 +1053,17 @@ class Subscription(Folder, XMLSyncUtils):
o_id = signature.getObjectId() o_id = signature.getObjectId()
#try with id param too, because gid is not catalogged #try with id param too, because gid is not catalogged
object_list = self.getObjectList(gid = b16decode(gid), id = o_id) object_list = self.getObjectList(gid = b16decode(gid), id = o_id)
LOG('getObjectFromGid :', DEBUG, 'object_list=%s, gid=%s, o_id=%s' % (object_list, gid, o_id)) #LOG('getObjectFromGid :', DEBUG, 'object_list=%s, gid=%s, o_id=%s' % (object_list, gid, o_id))
if o is not None and o in object_list: if o is not None and o in object_list:
return o return o
#LOG('entering in the slow loop of getObjectFromGid !!!',0,'') #LOG('entering in the slow loop of getObjectFromGid !!!',0,'')
object_list = self.getObjectList(gid = b16decode(gid)) object_list = self.getObjectList(gid = b16decode(gid))
LOG('getObjectFromGid :', DEBUG, 'object_list slow loop=%s, gid=%s' % (object_list, gid)) #LOG('getObjectFromGid :', DEBUG, 'object_list slow loop=%s, gid=%s' % (object_list, gid))
for o in object_list: for o in object_list:
o_gid = self.getGidFromObject(o) o_gid = self.getGidFromObject(o)
if o_gid == gid: if o_gid == gid:
return o return o
LOG('getObjectFromGid', DEBUG, 'returning None') #LOG('getObjectFromGid', DEBUG, 'returning None')
return None return None
def getObjectFromId(self, id): def getObjectFromId(self, id):
...@@ -1149,7 +1128,7 @@ class Subscription(Folder, XMLSyncUtils): ...@@ -1149,7 +1128,7 @@ class Subscription(Folder, XMLSyncUtils):
# This is probably a python script # This is probably a python script
generator = getattr(object, id_generator) generator = getattr(object, id_generator)
new_id = generator(object=object, gid=gid) new_id = generator(object=object, gid=gid)
LOG('generateNewId, new_id: ', DEBUG, new_id) #LOG('generateNewId, new_id: ', DEBUG, new_id)
return new_id return new_id
return None return None
...@@ -1335,23 +1314,11 @@ class Subscription(Folder, XMLSyncUtils): ...@@ -1335,23 +1314,11 @@ class Subscription(Folder, XMLSyncUtils):
break break
return o return o
def getObjectIdList(self):
"""
Returns the list of gids from signature
"""
return [s for s in self.getSignatureList() if s.getObjectId() is not None]
def getGidList(self): def getGidList(self):
""" """
Returns the list of gids from signature Returns the list of gids from signature
""" """
return [s.getGid() for s in self.getSignatureList() if s.getGid() is not None] return [id for id in self.getObjectIds()]
def getRidList(self):
"""
Returns the list of rids from signature
"""
return [s.getRid() for s in self.getSignatureList() if s.getRid() is not None]
def getSignatureList(self): def getSignatureList(self):
""" """
...@@ -1373,7 +1340,7 @@ class Subscription(Folder, XMLSyncUtils): ...@@ -1373,7 +1340,7 @@ class Subscription(Folder, XMLSyncUtils):
object_list_len = len(object_id_list) object_list_len = len(object_id_list)
for i in xrange(0, object_list_len, 100): for i in xrange(0, object_list_len, 100):
current_id_list = object_id_list[i:i+100] current_id_list = object_id_list[i:i+100]
self.activate().manage_delObjects(current_id_list) self.activate(activity='SQLQueue').manage_delObjects(current_id_list)
def getConflictList(self): def getConflictList(self):
""" """
......
...@@ -87,54 +87,6 @@ class SubscriptionSynchronization(XMLSyncUtils): ...@@ -87,54 +87,6 @@ class SubscriptionSynchronization(XMLSyncUtils):
return {'has_response':1,'xml':xml_a} return {'has_response':1,'xml':xml_a}
def SubSync(self, subscription_path, msg=None, RESPONSE=None):
"""
This is the synchronization method for the client
"""
response = None #check if subsync replies to this messages
subscription = self.unrestrictedTraverse(subscription_path)
if msg==None and (subscription.getSubscriptionUrl()).find('file')>=0:
msg = self.readResponse(sync_id=subscription.getSubscriptionUrl(),
from_url=subscription.getSubscriptionUrl())
if msg==None:
response = self.SubSyncInit(subscription)
else:
xml_client = msg
if isinstance(xml_client, str) or isinstance(xml_client, unicode):
xml_client = Parse(xml_client)
status_list = self.getSyncBodyStatusList(xml_client)
if status_list not in (None, []):
status_code_syncHdr = status_list[0]['code']
if status_code_syncHdr.isdigit():
status_code_syncHdr = int(status_code_syncHdr)
LOG('SubSync status code : ', DEBUG, status_code_syncHdr)
if status_code_syncHdr == self.AUTH_REQUIRED:
if self.checkChal(xml_client):
authentication_format, authentication_type = self.getChal(xml_client)
LOG('SubSync auth_required :', DEBUG, 'format:%s, type:%s' % (authentication_format, authentication_type))
if authentication_format is not None and \
authentication_type is not None:
subscription.setAuthenticationFormat(authentication_format)
subscription.setAuthenticationType(authentication_type)
else:
raise ValueError, "Sorry, the server chalenge for an \
authentication, but the authentication format is not find"
LOG('SubSync', INFO, 'Authentication required')
response = self.SubSyncCred(subscription, xml_client)
elif status_code_syncHdr == self.UNAUTHORIZED:
LOG('SubSync', INFO, 'Bad authentication')
return {'has_response':0, 'xml':xml_client}
else:
response = self.SubSyncModif(subscription, xml_client)
else:
response = self.SubSyncModif(subscription, xml_client)
if RESPONSE is not None:
RESPONSE.redirect('manageSubscriptions')
else:
return response
def SubSyncCred (self, subscription, msg=None, RESPONSE=None): def SubSyncCred (self, subscription, msg=None, RESPONSE=None):
""" """
This method send crendentials This method send crendentials
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment