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):
""" """
...@@ -1372,8 +1339,8 @@ class Subscription(Folder, XMLSyncUtils): ...@@ -1372,8 +1339,8 @@ class Subscription(Folder, XMLSyncUtils):
object_id_list = [id for id in self.getObjectIds()] object_id_list = [id for id in self.getObjectIds()]
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
......
...@@ -37,9 +37,9 @@ from AccessControl import ClassSecurityInfo, getSecurityManager ...@@ -37,9 +37,9 @@ from AccessControl import ClassSecurityInfo, getSecurityManager
from Products.CMFCore import CMFCorePermissions from Products.CMFCore import CMFCorePermissions
from Products.ERP5SyncML import _dtmldir from Products.ERP5SyncML import _dtmldir
from Products.ERP5SyncML import Conduit from Products.ERP5SyncML import Conduit
from Publication import Publication,Subscriber from Publication import Publication, Subscriber
from Products.BTreeFolder2.BTreeFolder2 import BTreeFolder2 from Products.BTreeFolder2.BTreeFolder2 import BTreeFolder2
from Subscription import Subscription,Signature from Subscription import Subscription, Signature
from XMLSyncUtils import Parse from XMLSyncUtils import Parse
#from Ft.Xml import Parse #from Ft.Xml import Parse
from Products.ERP5Type import Permissions from Products.ERP5Type import Permissions
...@@ -449,8 +449,8 @@ class SynchronizationTool( SubscriptionSynchronization, ...@@ -449,8 +449,8 @@ class SynchronizationTool( SubscriptionSynchronization,
conflict_list += [conflict.__of__(subscriber)] conflict_list += [conflict.__of__(subscriber)]
for subscription in self.getSubscriptionList(): for subscription in self.getSubscriptionList():
sub_conflict_list = subscription.getConflictList() sub_conflict_list = subscription.getConflictList()
LOG('SynchronizationTool.getConflictList, sub_conflict_list', DEBUG, #LOG('SynchronizationTool.getConflictList, sub_conflict_list', DEBUG,
sub_conflict_list) #sub_conflict_list)
for conflict in sub_conflict_list: for conflict in sub_conflict_list:
conflict.setSubscriber(subscription) conflict.setSubscriber(subscription)
if path is None or conflict.getObjectPath() == path: if path is None or conflict.getObjectPath() == path:
...@@ -487,32 +487,32 @@ class SynchronizationTool( SubscriptionSynchronization, ...@@ -487,32 +487,32 @@ class SynchronizationTool( SubscriptionSynchronization,
path = self.resolveContext(context) path = self.resolveContext(context)
conflict_list = self.getConflictList() conflict_list = self.getConflictList()
state_list= [] state_list= []
LOG('getSynchronizationState', DEBUG, 'path: %s' % str(path)) #LOG('getSynchronizationState', DEBUG, 'path: %s' % str(path))
for conflict in conflict_list: for conflict in conflict_list:
if conflict.getObjectPath() == path: if conflict.getObjectPath() == path:
LOG('getSynchronizationState', DEBUG, 'found a conflict: %s' % str(conflict)) #LOG('getSynchronizationState', DEBUG, 'found a conflict: %s' % str(conflict))
state_list += [[conflict.getSubscriber(),self.CONFLICT]] state_list += [[conflict.getSubscriber(),self.CONFLICT]]
for domain in self.getSynchronizationList(): for domain in self.getSynchronizationList():
destination = domain.getDestinationPath() destination = domain.getDestinationPath()
LOG('getSynchronizationState', TRACE, 'destination: %s' % str(destination)) #LOG('getSynchronizationState', TRACE, 'destination: %s' % str(destination))
j_path = '/'.join(path) j_path = '/'.join(path)
LOG('getSynchronizationState', TRACE, 'j_path: %s' % str(j_path)) #LOG('getSynchronizationState', TRACE, 'j_path: %s' % str(j_path))
if j_path.find(destination)==0: if j_path.find(destination)==0:
o_id = j_path[len(destination)+1:].split('/')[0] o_id = j_path[len(destination)+1:].split('/')[0]
LOG('getSynchronizationState', TRACE, 'o_id: %s' % o_id) #LOG('getSynchronizationState', TRACE, 'o_id: %s' % o_id)
subscriber_list = [] subscriber_list = []
if domain.domain_type==self.PUB: if domain.domain_type==self.PUB:
subscriber_list = domain.getSubscriberList() subscriber_list = domain.getSubscriberList()
else: else:
subscriber_list = [domain] subscriber_list = [domain]
LOG('getSynchronizationState, subscriber_list:', TRACE, subscriber_list) #LOG('getSynchronizationState, subscriber_list:', TRACE, subscriber_list)
for subscriber in subscriber_list: for subscriber in subscriber_list:
signature = subscriber.getSignatureFromObjectId(o_id) signature = subscriber.getSignatureFromObjectId(o_id)
#XXX check if signature could be not None ... #XXX check if signature could be not None ...
if signature is not None: if signature is not None:
state = signature.getStatus() state = signature.getStatus()
LOG('getSynchronizationState:', TRACE, 'sub.dest :%s, state: %s' % \ #LOG('getSynchronizationState:', TRACE, 'sub.dest :%s, state: %s' % \
(subscriber.getSubscriptionUrl(),str(state))) #(subscriber.getSubscriptionUrl(),str(state)))
found = None found = None
# Make sure there is not already a conflict giving the state # Make sure there is not already a conflict giving the state
for state_item in state_list: for state_item in state_list:
...@@ -537,21 +537,20 @@ class SynchronizationTool( SubscriptionSynchronization, ...@@ -537,21 +537,20 @@ class SynchronizationTool( SubscriptionSynchronization,
object = self.unrestrictedTraverse(conflict.getObjectPath()) object = self.unrestrictedTraverse(conflict.getObjectPath())
subscriber = conflict.getSubscriber() subscriber = conflict.getSubscriber()
# get the signature: # get the signature:
LOG('p_sync.applyPublisherValue, subscriber: ', DEBUG, subscriber) #LOG('p_sync.applyPublisherValue, subscriber: ', DEBUG, subscriber)
signature = subscriber.getSignatureFromObjectId(object.getId()) # XXX may be change for rid signature = subscriber.getSignatureFromObjectId(object.getId()) # XXX may be change for rid
copy_path = conflict.getCopyPath() copy_path = conflict.getCopyPath()
LOG('p_sync.applyPublisherValue, copy_path: ', TRACE, copy_path)
signature.delConflict(conflict) signature.delConflict(conflict)
if signature.getConflictList() == []: if len(signature.getConflictList()) == 0:
if copy_path is not None: if copy_path is not None:
LOG('p_sync.applyPublisherValue, conflict_list empty on : ', TRACE, signature) #LOG('p_sync.applyPublisherValue, conflict_list empty on : ', TRACE, signature)
# Delete the copy of the object if the there is one # Delete the copy of the object if the there is one
directory = object.aq_parent directory = object.aq_parent
copy_id = copy_path[-1] copy_id = copy_path[-1]
LOG('p_sync.applyPublisherValue, copy_id: ', TRACE, copy_id) #LOG('p_sync.applyPublisherValue, copy_id: ', TRACE, copy_id)
if hasattr(directory.aq_base, 'hasObject'): if hasattr(directory.aq_base, 'hasObject'):
# optimize the case of a BTree folder # optimize the case of a BTree folder
LOG('p_sync.applyPublisherValue, deleting...: ', TRACE, copy_id) #LOG('p_sync.applyPublisherValue, deleting...: ', TRACE, copy_id)
if directory.hasObject(copy_id): if directory.hasObject(copy_id):
directory._delObject(copy_id) directory._delObject(copy_id)
elif copy_id in directory.objectIds(): elif copy_id in directory.objectIds():
...@@ -567,7 +566,7 @@ class SynchronizationTool( SubscriptionSynchronization, ...@@ -567,7 +566,7 @@ class SynchronizationTool( SubscriptionSynchronization,
subscriber = conflict.getSubscriber() subscriber = conflict.getSubscriber()
for c in self.getConflictList(conflict.getObjectPath()): for c in self.getConflictList(conflict.getObjectPath()):
if c.getSubscriber() == subscriber: if c.getSubscriber() == subscriber:
LOG('applyPublisherDocument, applying on conflict: ', DEBUG, conflict) #LOG('applyPublisherDocument, applying on conflict: ', DEBUG, conflict)
c.applyPublisherValue() c.applyPublisherValue()
security.declareProtected(Permissions.AccessContentsInformation, security.declareProtected(Permissions.AccessContentsInformation,
...@@ -586,7 +585,7 @@ class SynchronizationTool( SubscriptionSynchronization, ...@@ -586,7 +585,7 @@ class SynchronizationTool( SubscriptionSynchronization,
apply the publisher value for all conflict of the given document apply the publisher value for all conflict of the given document
""" """
publisher_object_path = self.getPublisherDocumentPath(conflict) publisher_object_path = self.getPublisherDocumentPath(conflict)
LOG('getPublisherDocument publisher_object_path', TRACE, publisher_object_path) #LOG('getPublisherDocument publisher_object_path', TRACE, publisher_object_path)
publisher_object = self.unrestrictedTraverse(publisher_object_path) publisher_object = self.unrestrictedTraverse(publisher_object_path)
return publisher_object return publisher_object
...@@ -704,13 +703,12 @@ class SynchronizationTool( SubscriptionSynchronization, ...@@ -704,13 +703,12 @@ class SynchronizationTool( SubscriptionSynchronization,
solve_conflict=0 solve_conflict=0
subscriber = conflict.getSubscriber() subscriber = conflict.getSubscriber()
# get the signature: # get the signature:
#LOG('p_sync.setRemoteObject, subscriber: ',0,subscriber)
signature = subscriber.getSignatureFromObjectId(object.getId()) # XXX may be change for rid signature = subscriber.getSignatureFromObjectId(object.getId()) # XXX may be change for rid
# Import the conduit and get it # Import the conduit and get it
conduit_name = subscriber.getConduit() conduit_name = subscriber.getConduit()
conduit = self.getConduitByName(conduit_name) conduit = self.getConduitByName(conduit_name)
for xupdate in conflict.getXupdateList(): for xupdate in conflict.getXupdateList():
conduit.updateNode(xml=xupdate,object=object,force=1) conduit.updateNode(xml=xupdate, object=object, force=1)
if solve_conflict: if solve_conflict:
copy_path = conflict.getCopyPath() copy_path = conflict.getCopyPath()
signature.delConflict(conflict) signature.delConflict(conflict)
...@@ -742,9 +740,9 @@ class SynchronizationTool( SubscriptionSynchronization, ...@@ -742,9 +740,9 @@ class SynchronizationTool( SubscriptionSynchronization,
Version=Version CPS Version=Version CPS
""" """
# Retrieve the conflict object # Retrieve the conflict object
LOG('manageLocalValue', DEBUG, '%s %s %s' % (str(subscription_url), #LOG('manageLocalValue', DEBUG, '%s %s %s' % (str(subscription_url),
str(property_id), #str(property_id),
str(object_path))) #str(object_path)))
for conflict in self.getConflictList(): for conflict in self.getConflictList():
if conflict.getPropertyId() == property_id: if conflict.getPropertyId() == property_id:
if '/'.join(conflict.getObjectPath()) == object_path: if '/'.join(conflict.getObjectPath()) == object_path:
...@@ -761,9 +759,9 @@ class SynchronizationTool( SubscriptionSynchronization, ...@@ -761,9 +759,9 @@ class SynchronizationTool( SubscriptionSynchronization,
Do whatever needed in order to store the remote value locally Do whatever needed in order to store the remote value locally
and confirmed that the remote box should keep it's value and confirmed that the remote box should keep it's value
""" """
LOG('manageLocalValue', DEBUG, '%s %s %s' % (str(subscription_url), #LOG('manageLocalValue', DEBUG, '%s %s %s' % (str(subscription_url),
str(property_id), #str(property_id),
str(object_path))) #str(object_path)))
for conflict in self.getConflictList(): for conflict in self.getConflictList():
if conflict.getPropertyId() == property_id: if conflict.getPropertyId() == property_id:
if '/'.join(conflict.getObjectPath()) == object_path: if '/'.join(conflict.getObjectPath()) == object_path:
...@@ -816,17 +814,17 @@ class SynchronizationTool( SubscriptionSynchronization, ...@@ -816,17 +814,17 @@ class SynchronizationTool( SubscriptionSynchronization,
return context.getPhysicalPath() return context.getPhysicalPath()
security.declarePublic('sendResponse') security.declarePublic('sendResponse')
def sendResponse(self, to_url=None, from_url=None, sync_id=None,xml=None, def sendResponse(self, to_url=None, from_url=None, sync_id=None, xml=None,
domain=None, send=1, content_type='application/vnd.syncml+xml'): domain=None, send=1, content_type='application/vnd.syncml+xml'):
""" """
We will look at the url and we will see if we need to send mail, http We will look at the url and we will see if we need to send mail, http
response, or just copy to a file. response, or just copy to a file.
""" """
LOG('sendResponse, self.getPhysicalPath: ', DEBUG, self.getPhysicalPath()) #LOG('sendResponse, self.getPhysicalPath: ', DEBUG, self.getPhysicalPath())
LOG('sendResponse, to_url: ', DEBUG, to_url) #LOG('sendResponse, to_url: ', DEBUG, to_url)
LOG('sendResponse, from_url: ', DEBUG, from_url) #LOG('sendResponse, from_url: ', DEBUG, from_url)
LOG('sendResponse, sync_id: ', DEBUG, sync_id) #LOG('sendResponse, sync_id: ', DEBUG, sync_id)
LOG('sendResponse, xml: \n', DEBUG, xml) #LOG('sendResponse, xml: \n', DEBUG, xml)
if content_type == self.CONTENT_TYPE['SYNCML_WBXML']: if content_type == self.CONTENT_TYPE['SYNCML_WBXML']:
xml = self.xml2wbxml(xml) xml = self.xml2wbxml(xml)
...@@ -852,26 +850,27 @@ class SynchronizationTool( SubscriptionSynchronization, ...@@ -852,26 +850,27 @@ class SynchronizationTool( SubscriptionSynchronization,
commands.getstatusoutput('rm -f /tmp/%s.gz.gpg' % filename) commands.getstatusoutput('rm -f /tmp/%s.gz.gpg' % filename)
if send: if send:
if isinstance(to_url, str): if isinstance(to_url, str):
if to_url.find('http://')==0: if to_url.find('http://') == 0:
domain = aq_base(domain) domain = aq_base(domain)
if domain.domain_type == self.PUB and not domain.getActivityEnabled(): if domain.domain_type == self.PUB and not domain.getActivityEnabled():
# not use activity # not use activity
# XXX Make sure this is not a problem # XXX Make sure this is not a problem
return None return None
#use activities to send send an http response #use activities to send send an http response
LOG('sendResponse, will start sendHttpResponse, xml', DEBUG, '') #LOG('sendResponse, will start sendHttpResponse, xml', DEBUG, '')
self.activate(activity='RAMQueue').sendHttpResponse(sync_id=sync_id, activity = self.getActivityType(domain=domain)
self.activate(activity=activity).sendHttpResponse(sync_id=sync_id,
to_url=to_url, to_url=to_url,
xml=xml, xml=xml,
domain_path=domain.getPath(), domain_path=domain.getPath(),
content_type=content_type) content_type=content_type)
elif to_url.find('file://')==0: elif to_url.find('file://') == 0:
filename = to_url[len('file:/'):] filename = to_url[len('file:/'):]
stream = file(filename,'w') stream = file(filename,'w')
stream.write(xml) stream.write(xml)
stream.close() stream.close()
# we have to use local files (unit testing for example # we have to use local files (unit testing for example
elif to_url.find('mailto:')==0: elif to_url.find('mailto:') == 0:
# we will send an email # we will send an email
to_address = to_url[len('mailto:'):] to_address = to_url[len('mailto:'):]
from_address = from_url[len('mailto:'):] from_address = from_url[len('mailto:'):]
...@@ -882,15 +881,15 @@ class SynchronizationTool( SubscriptionSynchronization, ...@@ -882,15 +881,15 @@ class SynchronizationTool( SubscriptionSynchronization,
def sendHttpResponse(self, to_url=None, sync_id=None, xml=None, def sendHttpResponse(self, to_url=None, sync_id=None, xml=None,
domain_path=None, content_type='application/vnd.syncml+xml'): domain_path=None, content_type='application/vnd.syncml+xml'):
domain = self.unrestrictedTraverse(domain_path) domain = self.unrestrictedTraverse(domain_path)
LOG('sendHttpResponse, starting with domain:', DEBUG, domain) #LOG('sendHttpResponse, starting with domain:', DEBUG, domain)
if domain is not None: if domain is not None:
if domain.domain_type == self.PUB and not domain.getActivityEnabled(): if domain.domain_type == self.PUB and not domain.getActivityEnabled():
return xml return xml
# Retrieve the proxy from os variables # Retrieve the proxy from os variables
proxy_url = '' proxy_url = ''
if os.environ.has_key('http_proxy'): if os.environ.has_key('http_proxy'):
proxy_url = os.environ['http_proxy'] proxy_url = os.environ['http_proxy']
LOG('sendHttpResponse, proxy_url:', DEBUG, proxy_url) #LOG('sendHttpResponse, proxy_url:', DEBUG, proxy_url)
if proxy_url !='': if proxy_url !='':
proxy_handler = urllib2.ProxyHandler({"http" :proxy_url}) proxy_handler = urllib2.ProxyHandler({"http" :proxy_url})
else: else:
...@@ -923,11 +922,11 @@ class SynchronizationTool( SubscriptionSynchronization, ...@@ -923,11 +922,11 @@ class SynchronizationTool( SubscriptionSynchronization,
# - http://svn.zope.org/soap/trunk/ # - http://svn.zope.org/soap/trunk/
if domain.getSynchronizeWithERP5Sites(): if domain.getSynchronizeWithERP5Sites():
LOG('Synchronization with another ERP5 instance ...', DEBUG, '') #LOG('Synchronization with another ERP5 instance ...', DEBUG, '')
if to_url.find('readResponse')<0: if to_url.find('readResponse')<0:
to_url = to_url + '/portal_synchronizations/readResponse' to_url = to_url + '/portal_synchronizations/readResponse'
encoded = urllib.urlencode(to_encode) encoded = urllib.urlencode(to_encode)
data=encoded data = encoded
request = urllib2.Request(url=to_url, data=data) request = urllib2.Request(url=to_url, data=data)
else: else:
#XXX only to synchronize with other server than erp5 (must be improved): #XXX only to synchronize with other server than erp5 (must be improved):
...@@ -938,9 +937,13 @@ class SynchronizationTool( SubscriptionSynchronization, ...@@ -938,9 +937,13 @@ class SynchronizationTool( SubscriptionSynchronization,
url_file = urllib2.urlopen(request) url_file = urllib2.urlopen(request)
result = url_file.read() result = url_file.read()
except socket.error, msg: except socket.error, msg:
self.activate(activity='RAMQueue').sendHttpResponse(to_url=to_url, activity = self.getActivityType(domain=domain)
sync_id=sync_id, xml=xml, domain_path=domain.getPath(), self.activate(activity=activity).sendHttpResponse(
content_type=content_type) to_url=to_url,
sync_id=sync_id,
xml=xml,
domain_path=domain.getPath(),
content_type=content_type)
LOG('sendHttpResponse, socket ERROR:', INFO, msg) LOG('sendHttpResponse, socket ERROR:', INFO, msg)
LOG('sendHttpResponse, url, data', INFO, (url, data)) LOG('sendHttpResponse, url, data', INFO, (url, data))
return return
...@@ -951,10 +954,10 @@ class SynchronizationTool( SubscriptionSynchronization, ...@@ -951,10 +954,10 @@ class SynchronizationTool( SubscriptionSynchronization,
if domain is not None: if domain is not None:
if domain.domain_type == self.SUB and not domain.getActivityEnabled(): if domain.domain_type == self.SUB and not domain.getActivityEnabled():
#if we don't use activity : #if we don't use activity :
gpg_key = domain.getGPGKey() gpg_key = domain.getGPGKey()
if result not in (None, ''): if result not in (None, ''):
self.readResponse(sync_id=sync_id, text=result) self.readResponse(sync_id=sync_id, text=result)
return result return result
security.declarePublic('sync') security.declarePublic('sync')
...@@ -963,14 +966,15 @@ class SynchronizationTool( SubscriptionSynchronization, ...@@ -963,14 +966,15 @@ class SynchronizationTool( SubscriptionSynchronization,
This will try to synchronize every subscription This will try to synchronize every subscription
""" """
message_list = self.portal_activities.getMessageList() message_list = self.portal_activities.getMessageList()
LOG('sync, len(message_list):', DEBUG, len(message_list)) #LOG('sync, len(message_list):', DEBUG, len(message_list))
if len(message_list) == 0: if len(message_list) == 0:
for subscription in self.getSubscriptionList(): for subscription in self.getSubscriptionList():
user_id = subscription.getZopeUser() user_id = subscription.getZopeUser()
uf = self.getPortalObject().acl_users uf = self.getPortalObject().acl_users
user = uf.getUserById(user_id).__of__(uf) user = uf.getUserById(user_id).__of__(uf)
newSecurityManager(None, user) newSecurityManager(None, user)
self.activate(activity='RAMQueue').SubSync(subscription.getPath()) activity = self.getActivityType(domain=subscription)
subscription.activate(activity=activity).SubSync(subscription.getPath())
security.declarePublic('readResponse') security.declarePublic('readResponse')
def readResponse(self, text='', sync_id=None, to_url=None, from_url=None): def readResponse(self, text='', sync_id=None, to_url=None, from_url=None):
...@@ -978,7 +982,7 @@ class SynchronizationTool( SubscriptionSynchronization, ...@@ -978,7 +982,7 @@ class SynchronizationTool( SubscriptionSynchronization,
We will look at the url and we will see if we need to send mail, http We will look at the url and we will see if we need to send mail, http
response, or just copy to a file. response, or just copy to a file.
""" """
LOG('readResponse, text :', DEBUG, text) #LOG('readResponse, text :', DEBUG, text)
#LOG('readResponse, hexdump(text) :', DEBUG, self.hexdump(text)) #LOG('readResponse, hexdump(text) :', DEBUG, self.hexdump(text))
status_code = None status_code = None
if text not in ('', None): if text not in ('', None):
...@@ -986,7 +990,7 @@ class SynchronizationTool( SubscriptionSynchronization, ...@@ -986,7 +990,7 @@ class SynchronizationTool( SubscriptionSynchronization,
# the id sync_id, this is not so good, but there is no way yet # the id sync_id, this is not so good, but there is no way yet
# to know if we will call a publication or subscription XXX # to know if we will call a publication or subscription XXX
gpg_key = '' gpg_key = ''
LOG('readResponse, sync_id :', DEBUG, sync_id) #LOG('readResponse, sync_id :', DEBUG, sync_id)
for publication in self.getPublicationList(): for publication in self.getPublicationList():
if publication.getTitle() == sync_id: if publication.getTitle() == sync_id:
gpg_key = publication.getGPGKey() gpg_key = publication.getGPGKey()
...@@ -997,7 +1001,7 @@ class SynchronizationTool( SubscriptionSynchronization, ...@@ -997,7 +1001,7 @@ class SynchronizationTool( SubscriptionSynchronization,
gpg_key = subscription.getGPGKey() gpg_key = subscription.getGPGKey()
domain = subscription domain = subscription
user = domain.getZopeUser() user = domain.getZopeUser()
LOG('readResponse, user :', DEBUG, user) #LOG('readResponse, user :', DEBUG, user)
newSecurityManager(None, user) newSecurityManager(None, user)
# decrypt the message if needed # decrypt the message if needed
if gpg_key not in (None,''): if gpg_key not in (None,''):
...@@ -1021,7 +1025,7 @@ class SynchronizationTool( SubscriptionSynchronization, ...@@ -1021,7 +1025,7 @@ class SynchronizationTool( SubscriptionSynchronization,
LOG('type(text) : ', TRACE, type(text)) LOG('type(text) : ', TRACE, type(text))
if domain.getSyncContentType() == self.CONTENT_TYPE['SYNCML_WBXML']: if domain.getSyncContentType() == self.CONTENT_TYPE['SYNCML_WBXML']:
text = self.wbxml2xml(text) text = self.wbxml2xml(text)
LOG('readResponse, text after wbxml :\n', TRACE, text) #LOG('readResponse, text after wbxml :\n', TRACE, text)
xml = Parse(text) xml = Parse(text)
url = self.getTarget(xml) url = self.getTarget(xml)
for publication in self.getPublicationList(): for publication in self.getPublicationList():
...@@ -1029,8 +1033,9 @@ class SynchronizationTool( SubscriptionSynchronization, ...@@ -1029,8 +1033,9 @@ class SynchronizationTool( SubscriptionSynchronization,
publication.getTitle()==sync_id: publication.getTitle()==sync_id:
if publication.getActivityEnabled(): if publication.getActivityEnabled():
#use activities to send SyncML data. #use activities to send SyncML data.
self.activate(activity='RAMQueue').PubSync(publication.getPath(), publication.activate(activity='SQLDict').PubSync(
text) publication.getPath(),
text)
return ' ' return ' '
else: else:
result = self.PubSync(publication.getPath(), xml) result = self.PubSync(publication.getPath(), xml)
...@@ -1043,21 +1048,22 @@ class SynchronizationTool( SubscriptionSynchronization, ...@@ -1043,21 +1048,22 @@ class SynchronizationTool( SubscriptionSynchronization,
for subscription in self.getSubscriptionList(): for subscription in self.getSubscriptionList():
if subscription.getSubscriptionUrl() == url and \ if subscription.getSubscriptionUrl() == url and \
subscription.getTitle() == sync_id: subscription.getTitle() == sync_id:
subscription_path = self.getSubscription(sync_id).getPath() subscription_path = subscription.getPath()
self.activate(activity='RAMQueue').SubSync(subscription_path, activity = self.getActivityType(domain=subscription)
self.activate(activity=activity).SubSync(subscription_path,
text) text)
return ' ' return ' '
# we use from only if we have a file # we use from only if we have a file
elif isinstance(from_url, str): elif isinstance(from_url, str):
if from_url.find('file://') == 0: if from_url.find('file://') == 0:
try: try:
filename = from_url[len('file:/'):] filename = from_url[len('file:/'):]
stream = file(filename, 'r') stream = file(filename, 'r')
xml = stream.read() xml = stream.read()
LOG('readResponse', DEBUG, 'file... msg: %s' % str(stream.read())) #LOG('readResponse', DEBUG, 'file... msg: %s' % str(stream.read()))
except IOError: except IOError:
LOG('readResponse, cannot read file: ', DEBUG, filename) LOG('readResponse, cannot read file: ', INFO, filename)
xml = None xml = None
if xml is not None and len(xml) == 0: if xml is not None and len(xml) == 0:
xml = None xml = None
......
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