[Erp5-report] r15796 - in /erp5/trunk/products/ERP5SyncML: ./ Conduit/
nobody at svn.erp5.org
nobody at svn.erp5.org
Thu Aug 23 11:51:27 CEST 2007
Author: nicolas
Date: Thu Aug 23 11:51:27 2007
New Revision: 15796
URL: http://svn.erp5.org?rev=15796&view=rev
Log:
Code typo improvements, bug fix on reset, hide logs for better performance
Modified:
erp5/trunk/products/ERP5SyncML/Conduit/ERP5Conduit.py
erp5/trunk/products/ERP5SyncML/Publication.py
erp5/trunk/products/ERP5SyncML/PublicationSynchronization.py
erp5/trunk/products/ERP5SyncML/Subscription.py
erp5/trunk/products/ERP5SyncML/SubscriptionSynchronization.py
erp5/trunk/products/ERP5SyncML/SynchronizationTool.py
Modified: erp5/trunk/products/ERP5SyncML/Conduit/ERP5Conduit.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5SyncML/Conduit/ERP5Conduit.py?rev=15796&r1=15795&r2=15796&view=diff
==============================================================================
--- erp5/trunk/products/ERP5SyncML/Conduit/ERP5Conduit.py (original)
+++ erp5/trunk/products/ERP5SyncML/Conduit/ERP5Conduit.py Thu Aug 23 11:51:27 2007
@@ -177,7 +177,7 @@
if previous_xml is not None and sub_object_id is not None:
# Find the previous xml corresponding to this subobject
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:
sub_object = None
try:
@@ -185,11 +185,11 @@
except (AttributeError, KeyError, TypeError):
pass
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
# modifications to the subobject
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
conflict_list += self.addNode(xml=sub_xml,object=sub_object,
previous_xml=sub_previous_xml, force=force,
@@ -214,12 +214,12 @@
A node is deleted
"""
# 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 = []
if xml is not None:
xml = self.convertToXml(xml)
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:
object_id = self.getAttribute(xml,'id')
elif self.getSubObjectDepth(xml)==1:
@@ -233,7 +233,7 @@
conflict_list += self.deleteNode(xml=sub_xml,object=sub_object,
force=force, simulate=simulate, **kw)
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
if object_id is not None: # We do have an object_id
self.deleteObject(object, object_id)
@@ -244,7 +244,7 @@
if xml.nodeName in self.local_role_list and not simulate:
# We want to del a local role
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:
object.manage_delLocalRoles([user])
elif xml.nodeName.find(self.local_group_tag)>=0:
@@ -259,7 +259,7 @@
try:
object._delObject(object_id)
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
security.declareProtected(Permissions.ModifyPortalContent, 'updateNode')
@@ -274,8 +274,8 @@
"""
conflict_list = []
xml = self.convertToXml(xml)
- LOG('ERP5Conduit.updateNode', DEBUG, 'xml.nodeName: %s' % xml.nodeName)
- LOG('ERP5Conduit.updateNode, force: ', DEBUG, force)
+ #LOG('ERP5Conduit.updateNode', DEBUG, 'xml.nodeName: %s' % xml.nodeName)
+ #LOG('ERP5Conduit.updateNode, force: ', DEBUG, force)
# we have an xupdate xml
if xml.nodeName == 'xupdate:modifications':
conflict_list += self.applyXupdate(object=object, xupdate=xml,
@@ -332,7 +332,7 @@
if not (keyword in self.NOT_EDITABLE_PROPERTY):
# We will look for the data to enter
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)
args[keyword] = data
args = self.getFormatedArgs(args=args)
@@ -349,12 +349,12 @@
data_type=data_type)
#current_data = object.getProperty(keyword)
current_data = self.getProperty(object, keyword)
- 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 current_data: %s' % str(current_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 current_data: %s' % str(current_data))
if (old_data != current_data) and (data != current_data) \
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
# XXX this have to be removed after
#if not (data_type in self.binary_type_list):
@@ -398,10 +398,10 @@
# We should find the object corresponding to
# this update, so we have to look in the previous_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:
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:
sub_object = None
try:
@@ -409,11 +409,11 @@
except KeyError:
pass
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
# modifications to the subobject
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
conflict_list += self.updateNode(xml=sub_xml, object=sub_object,
force=force, previous_xml=sub_previous_xml,
@@ -470,7 +470,7 @@
data = data.encode(self.getEncoding())
data = data.replace('@@@','\n')
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')
Encoders.encode_base64(msg)
msg.set_payload(data)
@@ -1173,9 +1173,9 @@
"""
return object.getId()
- def getGidFromXML(self, xml, gid_from_xml_list):
- """
- return the Gid composed with xml informations
- """
- return None
-
+ #def getGidFromXML(self, xml, gid_from_xml_list):
+ #"""
+ #return the Gid composed with xml informations
+ #"""
+ #return None
+
Modified: erp5/trunk/products/ERP5SyncML/Publication.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5SyncML/Publication.py?rev=15796&r1=15795&r2=15796&view=diff
==============================================================================
--- erp5/trunk/products/ERP5SyncML/Publication.py (original)
+++ erp5/trunk/products/ERP5SyncML/Publication.py Thu Aug 23 11:51:27 2007
@@ -230,7 +230,7 @@
Reset all subscribers
"""
for o in self.getSubscriberList():
- self.activate().manage_delObjects(o.id)
+ self.activate(activity='SQLQueue').manage_delObjects(o.id)
def getConflictList(self):
"""
Modified: erp5/trunk/products/ERP5SyncML/PublicationSynchronization.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5SyncML/PublicationSynchronization.py?rev=15796&r1=15795&r2=15796&view=diff
==============================================================================
--- erp5/trunk/products/ERP5SyncML/PublicationSynchronization.py (original)
+++ erp5/trunk/products/ERP5SyncML/PublicationSynchronization.py Thu Aug 23 11:51:27 2007
@@ -90,7 +90,7 @@
next_anchor)
if subscriber.getNextAnchor() != last_anchor:
if last_anchor in (None, ''):
- LOG('PubSyncInit', DEBUG, 'anchor null')
+ LOG('PubSyncInit', INFO, 'anchor null')
else:
message = "bad anchors in PubSyncInit! " + \
subscriber.getNextAnchor() + " and " + last_anchor
@@ -200,74 +200,6 @@
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):
"""
The modidification message for the publication
Modified: erp5/trunk/products/ERP5SyncML/Subscription.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5SyncML/Subscription.py?rev=15796&r1=15795&r2=15796&view=diff
==============================================================================
--- erp5/trunk/products/ERP5SyncML/Subscription.py (original)
+++ erp5/trunk/products/ERP5SyncML/Subscription.py Thu Aug 23 11:51:27 2007
@@ -262,7 +262,6 @@
else:
self.setPath(None)
self.setId(id)
- self.setGid(id)
self.setRid(rid)
self.status = status
self.setXML(xml_string)
@@ -468,19 +467,11 @@
"""
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):
"""
get the gid
"""
- return self.gid
+ return self.getId()
def setObjectId(self, id):
"""
@@ -503,6 +494,8 @@
"""
if type(xml) is type(u'a'):
xml = xml.encode('utf-8')
+ if xml is not None:
+ xml = self.xml.replace('@-@@-@','--') # need to put back '--'
self.partial_xml = xml
def getPartialXML(self):
@@ -510,9 +503,6 @@
Set the partial string we will have to
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
def getAction(self):
@@ -531,11 +521,10 @@
"""
Return the actual action for a partial synchronization
"""
- conflict_list = []
+ returned_conflict_list = []
if len(self.conflict_list)>0:
- for conflict in self.conflict_list:
- conflict_list += [conflict]
- return conflict_list
+ returned_conflict_list.extend(self.conflict_list)
+ return returned_conflict_list
def resetConflictList(self):
"""
@@ -547,7 +536,7 @@
"""
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()
else:
self.conflict_list = conflict_list
@@ -556,7 +545,6 @@
"""
Return the actual action for a partial synchronization
"""
- LOG('delConflict, conflict', DEBUG, conflict)
conflict_list = []
for c in self.getConflictList():
#LOG('delConflict, c==conflict',0,c==aq_base(conflict))
@@ -774,7 +762,7 @@
# LOG('getSignature', DEBUG, 'signatures_status: %s' % str(dict_sign))
# XXXXXXXXXXXXXXXXXXXXXXXXXXXXX
code = self.SLOW_SYNC
- if len(self.getSignatureList()) > 0:
+ if len(self.getSignatureList()[:1]) > 0:
code = self.getAlertCode()
if default is not None:
code = default
@@ -825,8 +813,8 @@
return True if the message id was not seen, False if already seen
"""
last_message_id = getattr(self,'last_message_id',None)
- LOG('checkCorrectRemoteMessageId last_message_id = ', DEBUG, last_message_id)
- LOG('checkCorrectRemoteMessageId message_id = ', DEBUG, message_id)
+ #LOG('checkCorrectRemoteMessageId last_message_id = ', DEBUG, last_message_id)
+ #LOG('checkCorrectRemoteMessageId message_id = ', DEBUG, message_id)
if last_message_id == message_id:
return False
self.last_message_id = message_id
@@ -1015,7 +1003,7 @@
if authentication_format in (None, ''):
self.authentication_format = 'b64'
else:
- self.authentication_format=authentication_format
+ self.authentication_format = authentication_format
def setAuthenticationType(self, authentication_type):
"""
@@ -1034,22 +1022,13 @@
conduit_name = self.getConduit()
conduit = self.getConduitByName(conduit_name)
gid_gen = getattr(conduit, 'getGidFromObject', None)
- LOG('getGidFromObject, Conduit :', DEBUG, conduit_name)
- LOG('getGidFromObject, gid_gen:', DEBUG, gid_gen)
if callable(gid_gen):
o_gid = gid_gen(object)
else:
raise ValueError, "The conduit "+conduit_name+"seems to not have a \
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)
- LOG('getGidFromObject returning', DEBUG, o_gid)
+ #LOG('getGidFromObject returning', DEBUG, o_gid)
return o_gid
def getObjectFromGid(self, gid):
@@ -1074,17 +1053,17 @@
o_id = signature.getObjectId()
#try with id param too, because gid is not catalogged
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:
return o
#LOG('entering in the slow loop of getObjectFromGid !!!',0,'')
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:
o_gid = self.getGidFromObject(o)
if o_gid == gid:
return o
- LOG('getObjectFromGid', DEBUG, 'returning None')
+ #LOG('getObjectFromGid', DEBUG, 'returning None')
return None
def getObjectFromId(self, id):
@@ -1149,7 +1128,7 @@
# This is probably a python script
generator = getattr(object, id_generator)
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 None
@@ -1335,23 +1314,11 @@
break
return o
- def getObjectIdList(self):
+ def getGidList(self):
"""
Returns the list of gids from signature
"""
- return [s for s in self.getSignatureList() if s.getObjectId() is not None]
-
- def getGidList(self):
- """
- Returns the list of gids from signature
- """
- return [s.getGid() for s in self.getSignatureList() if s.getGid() is not None]
-
- def getRidList(self):
- """
- Returns the list of rids from signature
- """
- return [s.getRid() for s in self.getSignatureList() if s.getRid() is not None]
+ return [id for id in self.getObjectIds()]
def getSignatureList(self):
"""
@@ -1372,8 +1339,8 @@
object_id_list = [id for id in self.getObjectIds()]
object_list_len = len(object_id_list)
for i in xrange(0, object_list_len, 100):
- current_id_list = object_id_list[i:i+100]
- self.activate().manage_delObjects(current_id_list)
+ current_id_list = object_id_list[i:i+100]
+ self.activate(activity='SQLQueue').manage_delObjects(current_id_list)
def getConflictList(self):
"""
Modified: erp5/trunk/products/ERP5SyncML/SubscriptionSynchronization.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5SyncML/SubscriptionSynchronization.py?rev=15796&r1=15795&r2=15796&view=diff
==============================================================================
--- erp5/trunk/products/ERP5SyncML/SubscriptionSynchronization.py (original)
+++ erp5/trunk/products/ERP5SyncML/SubscriptionSynchronization.py Thu Aug 23 11:51:27 2007
@@ -87,54 +87,6 @@
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):
"""
This method send crendentials
Modified: erp5/trunk/products/ERP5SyncML/SynchronizationTool.py
URL: http://svn.erp5.org/erp5/trunk/products/ERP5SyncML/SynchronizationTool.py?rev=15796&r1=15795&r2=15796&view=diff
==============================================================================
--- erp5/trunk/products/ERP5SyncML/SynchronizationTool.py (original)
+++ erp5/trunk/products/ERP5SyncML/SynchronizationTool.py Thu Aug 23 11:51:27 2007
@@ -37,9 +37,9 @@
from Products.CMFCore import CMFCorePermissions
from Products.ERP5SyncML import _dtmldir
from Products.ERP5SyncML import Conduit
-from Publication import Publication,Subscriber
+from Publication import Publication, Subscriber
from Products.BTreeFolder2.BTreeFolder2 import BTreeFolder2
-from Subscription import Subscription,Signature
+from Subscription import Subscription, Signature
from XMLSyncUtils import Parse
#from Ft.Xml import Parse
from Products.ERP5Type import Permissions
@@ -449,8 +449,8 @@
conflict_list += [conflict.__of__(subscriber)]
for subscription in self.getSubscriptionList():
sub_conflict_list = subscription.getConflictList()
- LOG('SynchronizationTool.getConflictList, sub_conflict_list', DEBUG,
- sub_conflict_list)
+ #LOG('SynchronizationTool.getConflictList, sub_conflict_list', DEBUG,
+ #sub_conflict_list)
for conflict in sub_conflict_list:
conflict.setSubscriber(subscription)
if path is None or conflict.getObjectPath() == path:
@@ -487,32 +487,32 @@
path = self.resolveContext(context)
conflict_list = self.getConflictList()
state_list= []
- LOG('getSynchronizationState', DEBUG, 'path: %s' % str(path))
+ #LOG('getSynchronizationState', DEBUG, 'path: %s' % str(path))
for conflict in conflict_list:
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]]
for domain in self.getSynchronizationList():
destination = domain.getDestinationPath()
- LOG('getSynchronizationState', TRACE, 'destination: %s' % str(destination))
+ #LOG('getSynchronizationState', TRACE, 'destination: %s' % str(destination))
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:
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 = []
if domain.domain_type==self.PUB:
subscriber_list = domain.getSubscriberList()
else:
subscriber_list = [domain]
- LOG('getSynchronizationState, subscriber_list:', TRACE, subscriber_list)
+ #LOG('getSynchronizationState, subscriber_list:', TRACE, subscriber_list)
for subscriber in subscriber_list:
signature = subscriber.getSignatureFromObjectId(o_id)
#XXX check if signature could be not None ...
if signature is not None:
state = signature.getStatus()
- LOG('getSynchronizationState:', TRACE, 'sub.dest :%s, state: %s' % \
- (subscriber.getSubscriptionUrl(),str(state)))
+ #LOG('getSynchronizationState:', TRACE, 'sub.dest :%s, state: %s' % \
+ #(subscriber.getSubscriptionUrl(),str(state)))
found = None
# Make sure there is not already a conflict giving the state
for state_item in state_list:
@@ -537,21 +537,20 @@
object = self.unrestrictedTraverse(conflict.getObjectPath())
subscriber = conflict.getSubscriber()
# 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
copy_path = conflict.getCopyPath()
- LOG('p_sync.applyPublisherValue, copy_path: ', TRACE, copy_path)
signature.delConflict(conflict)
- if signature.getConflictList() == []:
+ if len(signature.getConflictList()) == 0:
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
directory = object.aq_parent
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'):
# 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):
directory._delObject(copy_id)
elif copy_id in directory.objectIds():
@@ -567,7 +566,7 @@
subscriber = conflict.getSubscriber()
for c in self.getConflictList(conflict.getObjectPath()):
if c.getSubscriber() == subscriber:
- LOG('applyPublisherDocument, applying on conflict: ', DEBUG, conflict)
+ #LOG('applyPublisherDocument, applying on conflict: ', DEBUG, conflict)
c.applyPublisherValue()
security.declareProtected(Permissions.AccessContentsInformation,
@@ -586,7 +585,7 @@
apply the publisher value for all conflict of the given document
"""
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)
return publisher_object
@@ -704,13 +703,12 @@
solve_conflict=0
subscriber = conflict.getSubscriber()
# get the signature:
- #LOG('p_sync.setRemoteObject, subscriber: ',0,subscriber)
signature = subscriber.getSignatureFromObjectId(object.getId()) # XXX may be change for rid
# Import the conduit and get it
conduit_name = subscriber.getConduit()
conduit = self.getConduitByName(conduit_name)
for xupdate in conflict.getXupdateList():
- conduit.updateNode(xml=xupdate,object=object,force=1)
+ conduit.updateNode(xml=xupdate, object=object, force=1)
if solve_conflict:
copy_path = conflict.getCopyPath()
signature.delConflict(conflict)
@@ -742,9 +740,9 @@
Version=Version CPS
"""
# Retrieve the conflict object
- LOG('manageLocalValue', DEBUG, '%s %s %s' % (str(subscription_url),
- str(property_id),
- str(object_path)))
+ #LOG('manageLocalValue', DEBUG, '%s %s %s' % (str(subscription_url),
+ #str(property_id),
+ #str(object_path)))
for conflict in self.getConflictList():
if conflict.getPropertyId() == property_id:
if '/'.join(conflict.getObjectPath()) == object_path:
@@ -761,9 +759,9 @@
Do whatever needed in order to store the remote value locally
and confirmed that the remote box should keep it's value
"""
- LOG('manageLocalValue', DEBUG, '%s %s %s' % (str(subscription_url),
- str(property_id),
- str(object_path)))
+ #LOG('manageLocalValue', DEBUG, '%s %s %s' % (str(subscription_url),
+ #str(property_id),
+ #str(object_path)))
for conflict in self.getConflictList():
if conflict.getPropertyId() == property_id:
if '/'.join(conflict.getObjectPath()) == object_path:
@@ -816,17 +814,17 @@
return context.getPhysicalPath()
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'):
"""
We will look at the url and we will see if we need to send mail, http
response, or just copy to a file.
"""
- LOG('sendResponse, self.getPhysicalPath: ', DEBUG, self.getPhysicalPath())
- LOG('sendResponse, to_url: ', DEBUG, to_url)
- LOG('sendResponse, from_url: ', DEBUG, from_url)
- LOG('sendResponse, sync_id: ', DEBUG, sync_id)
- LOG('sendResponse, xml: \n', DEBUG, xml)
+ #LOG('sendResponse, self.getPhysicalPath: ', DEBUG, self.getPhysicalPath())
+ #LOG('sendResponse, to_url: ', DEBUG, to_url)
+ #LOG('sendResponse, from_url: ', DEBUG, from_url)
+ #LOG('sendResponse, sync_id: ', DEBUG, sync_id)
+ #LOG('sendResponse, xml: \n', DEBUG, xml)
if content_type == self.CONTENT_TYPE['SYNCML_WBXML']:
xml = self.xml2wbxml(xml)
@@ -852,26 +850,27 @@
commands.getstatusoutput('rm -f /tmp/%s.gz.gpg' % filename)
if send:
if isinstance(to_url, str):
- if to_url.find('http://')==0:
+ if to_url.find('http://') == 0:
domain = aq_base(domain)
if domain.domain_type == self.PUB and not domain.getActivityEnabled():
# not use activity
# XXX Make sure this is not a problem
return None
#use activities to send send an http response
- LOG('sendResponse, will start sendHttpResponse, xml', DEBUG, '')
- self.activate(activity='RAMQueue').sendHttpResponse(sync_id=sync_id,
+ #LOG('sendResponse, will start sendHttpResponse, xml', DEBUG, '')
+ activity = self.getActivityType(domain=domain)
+ self.activate(activity=activity).sendHttpResponse(sync_id=sync_id,
to_url=to_url,
xml=xml,
domain_path=domain.getPath(),
content_type=content_type)
- elif to_url.find('file://')==0:
+ elif to_url.find('file://') == 0:
filename = to_url[len('file:/'):]
stream = file(filename,'w')
stream.write(xml)
stream.close()
# 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
to_address = to_url[len('mailto:'):]
from_address = from_url[len('mailto:'):]
@@ -882,15 +881,15 @@
def sendHttpResponse(self, to_url=None, sync_id=None, xml=None,
domain_path=None, content_type='application/vnd.syncml+xml'):
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.domain_type == self.PUB and not domain.getActivityEnabled():
- return xml
+ return xml
# Retrieve the proxy from os variables
proxy_url = ''
if os.environ.has_key('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 !='':
proxy_handler = urllib2.ProxyHandler({"http" :proxy_url})
else:
@@ -923,11 +922,11 @@
# - http://svn.zope.org/soap/trunk/
if domain.getSynchronizeWithERP5Sites():
- LOG('Synchronization with another ERP5 instance ...', DEBUG, '')
+ #LOG('Synchronization with another ERP5 instance ...', DEBUG, '')
if to_url.find('readResponse')<0:
to_url = to_url + '/portal_synchronizations/readResponse'
encoded = urllib.urlencode(to_encode)
- data=encoded
+ data = encoded
request = urllib2.Request(url=to_url, data=data)
else:
#XXX only to synchronize with other server than erp5 (must be improved):
@@ -938,9 +937,13 @@
url_file = urllib2.urlopen(request)
result = url_file.read()
except socket.error, msg:
- self.activate(activity='RAMQueue').sendHttpResponse(to_url=to_url,
- sync_id=sync_id, xml=xml, domain_path=domain.getPath(),
- content_type=content_type)
+ activity = self.getActivityType(domain=domain)
+ self.activate(activity=activity).sendHttpResponse(
+ 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, url, data', INFO, (url, data))
return
@@ -951,10 +954,10 @@
if domain is not None:
if domain.domain_type == self.SUB and not domain.getActivityEnabled():
- #if we don't use activity :
- gpg_key = domain.getGPGKey()
- if result not in (None, ''):
- self.readResponse(sync_id=sync_id, text=result)
+ #if we don't use activity :
+ gpg_key = domain.getGPGKey()
+ if result not in (None, ''):
+ self.readResponse(sync_id=sync_id, text=result)
return result
security.declarePublic('sync')
@@ -963,14 +966,15 @@
This will try to synchronize every subscription
"""
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:
for subscription in self.getSubscriptionList():
user_id = subscription.getZopeUser()
uf = self.getPortalObject().acl_users
user = uf.getUserById(user_id).__of__(uf)
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')
def readResponse(self, text='', sync_id=None, to_url=None, from_url=None):
@@ -978,7 +982,7 @@
We will look at the url and we will see if we need to send mail, http
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))
status_code = None
if text not in ('', None):
@@ -986,7 +990,7 @@
# 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
gpg_key = ''
- LOG('readResponse, sync_id :', DEBUG, sync_id)
+ #LOG('readResponse, sync_id :', DEBUG, sync_id)
for publication in self.getPublicationList():
if publication.getTitle() == sync_id:
gpg_key = publication.getGPGKey()
@@ -997,7 +1001,7 @@
gpg_key = subscription.getGPGKey()
domain = subscription
user = domain.getZopeUser()
- LOG('readResponse, user :', DEBUG, user)
+ #LOG('readResponse, user :', DEBUG, user)
newSecurityManager(None, user)
# decrypt the message if needed
if gpg_key not in (None,''):
@@ -1021,7 +1025,7 @@
LOG('type(text) : ', TRACE, type(text))
if domain.getSyncContentType() == self.CONTENT_TYPE['SYNCML_WBXML']:
text = self.wbxml2xml(text)
- LOG('readResponse, text after wbxml :\n', TRACE, text)
+ #LOG('readResponse, text after wbxml :\n', TRACE, text)
xml = Parse(text)
url = self.getTarget(xml)
for publication in self.getPublicationList():
@@ -1029,8 +1033,9 @@
publication.getTitle()==sync_id:
if publication.getActivityEnabled():
#use activities to send SyncML data.
- self.activate(activity='RAMQueue').PubSync(publication.getPath(),
- text)
+ publication.activate(activity='SQLDict').PubSync(
+ publication.getPath(),
+ text)
return ' '
else:
result = self.PubSync(publication.getPath(), xml)
@@ -1043,21 +1048,22 @@
for subscription in self.getSubscriptionList():
if subscription.getSubscriptionUrl() == url and \
subscription.getTitle() == sync_id:
- subscription_path = self.getSubscription(sync_id).getPath()
- self.activate(activity='RAMQueue').SubSync(subscription_path,
+ subscription_path = subscription.getPath()
+ activity = self.getActivityType(domain=subscription)
+ self.activate(activity=activity).SubSync(subscription_path,
text)
return ' '
- # we use from only if we have a file
+ # we use from only if we have a file
elif isinstance(from_url, str):
if from_url.find('file://') == 0:
try:
filename = from_url[len('file:/'):]
stream = file(filename, 'r')
xml = stream.read()
- LOG('readResponse', DEBUG, 'file... msg: %s' % str(stream.read()))
+ #LOG('readResponse', DEBUG, 'file... msg: %s' % str(stream.read()))
except IOError:
- LOG('readResponse, cannot read file: ', DEBUG, filename)
+ LOG('readResponse, cannot read file: ', INFO, filename)
xml = None
if xml is not None and len(xml) == 0:
xml = None
More information about the Erp5-report
mailing list