Commit eacbecf5 authored by Nicolas Delaby's avatar Nicolas Delaby

Add log management, optimisation, typo

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@15587 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 7c1ab281
This diff is collapsed.
...@@ -95,7 +95,7 @@ def addPublication( self, id, title='', REQUEST=None ): ...@@ -95,7 +95,7 @@ def addPublication( self, id, title='', REQUEST=None ):
Add a new Category and generate UID by calling the Add a new Category and generate UID by calling the
ZSQLCatalog ZSQLCatalog
""" """
o = Publication( id ,'','','','','') o = Publication( id, '', '', '', '', '')
self._setObject( id, o ) self._setObject( id, o )
if REQUEST is not None: if REQUEST is not None:
return self.manage_main(self, REQUEST, update_menu=1) return self.manage_main(self, REQUEST, update_menu=1)
...@@ -157,7 +157,6 @@ class Publication(Subscription): ...@@ -157,7 +157,6 @@ class Publication(Subscription):
self.setSourceURI(source_uri) self.setSourceURI(source_uri)
self.setQuery(query) self.setQuery(query)
self.xml_mapping = xml_mapping self.xml_mapping = xml_mapping
#self.list_subscribers = PersistentMapping()
self.domain_type = self.PUB self.domain_type = self.PUB
self.gpg_key = gpg_key self.gpg_key = gpg_key
self.setGidGenerator(gid_generator) self.setGidGenerator(gid_generator)
...@@ -231,26 +230,24 @@ class Publication(Subscription): ...@@ -231,26 +230,24 @@ class Publication(Subscription):
""" """
Add a new subscriber to the publication Add a new subscriber to the publication
""" """
LOG('addSubscriber starting ...',0,'')
# We have to remove the subscriber if it already exist (there were probably a reset on the client) # We have to remove the subscriber if it already exist (there were probably a reset on the client)
self.delSubscriber(subscriber.getSubscriptionUrl()) self.delSubscriber(subscriber.getSubscriptionUrl())
new_id = subscriber.getId() new_id = subscriber.getId()
if new_id is None: if new_id is None:
new_id = str(self.generateNewId()) new_id = str(self.generateNewId())
subscriber.id = new_id subscriber.id = new_id
#if len(self.list_subscribers) == 0: self._setObject(new_id, subscriber)
# self.list_subscribers = []
#self.list_subscribers = self.list_subscribers + [subscriber]
self._setObject(new_id,subscriber)
def getSubscriber(self, subscription_url): def getSubscriber(self, subscription_url):
""" """
return the subscriber corresponding the to subscription_url return the subscriber corresponding the to subscription_url
""" """
for o in self.objectValues(): o = None
if o.getSubscriptionUrl() == subscription_url: for sub in self.getSubscriberList():
if sub.getSubscriptionUrl() == subscription_url:
o = sub
break
return o return o
return None
def getSubscriberList(self): def getSubscriberList(self):
""" """
...@@ -263,16 +260,16 @@ class Publication(Subscription): ...@@ -263,16 +260,16 @@ class Publication(Subscription):
""" """
Delete a subscriber for this publication Delete a subscriber for this publication
""" """
for o in self.objectValues(): for o in self.getSubscriberList():
if o.getSubscriptionUrl() == subscription_url: if o.getSubscriptionUrl() == subscription_url:
self._delObject(o.id) self.activate().manage_delObjects(o.id)
def resetAllSubscribers(self): def resetAllSubscribers(self):
""" """
Reset all subscribers Reset all subscribers
""" """
for o in self.objectValues(): for o in self.getSubscriberList():
self._delObject(o.id) self.activate().manage_delObjects(o.id)
def getConflictList(self): def getConflictList(self):
""" """
...@@ -280,6 +277,6 @@ class Publication(Subscription): ...@@ -280,6 +277,6 @@ class Publication(Subscription):
""" """
conflict_list = [] conflict_list = []
for subscriber in self.getSubscriberList(): for subscriber in self.getSubscriberList():
conflict_list += subscriber.getConflictList() conflict_list.extend(subscriber.getConflictList())
return conflict_list return conflict_list
...@@ -39,11 +39,11 @@ from Products.PluggableAuthService.interfaces.plugins import\ ...@@ -39,11 +39,11 @@ from Products.PluggableAuthService.interfaces.plugins import\
from AccessControl.SecurityManagement import newSecurityManager from AccessControl.SecurityManagement import newSecurityManager
import commands import commands
from DateTime import DateTime from DateTime import DateTime
from zLOG import LOG from zLOG import LOG, DEBUG, INFO, WARNING
class PublicationSynchronization(XMLSyncUtils): class PublicationSynchronization(XMLSyncUtils):
""" """
Receive the first XML message from the client
""" """
def PubSyncInit(self, publication=None, xml_client=None, subscriber=None, def PubSyncInit(self, publication=None, xml_client=None, subscriber=None,
...@@ -52,8 +52,7 @@ class PublicationSynchronization(XMLSyncUtils): ...@@ -52,8 +52,7 @@ class PublicationSynchronization(XMLSyncUtils):
Read the client xml message Read the client xml message
Send the first XML message from the server Send the first XML message from the server
""" """
LOG('PubSyncInit',0,'Starting... publication: %s' % str(publication)) LOG('PubSyncInit', DEBUG, 'Starting... publication: %s' % (publication.getPath()))
#the session id is set at the same value of those of the client #the session id is set at the same value of those of the client
subscriber.setSessionId(self.getSessionId(xml_client)) subscriber.setSessionId(self.getSessionId(xml_client))
#same for the message id #same for the message id
...@@ -80,8 +79,8 @@ class PublicationSynchronization(XMLSyncUtils): ...@@ -80,8 +79,8 @@ class PublicationSynchronization(XMLSyncUtils):
# If slow sync, then resend everything # If slow sync, then resend everything
if alert_code == self.SLOW_SYNC: if alert_code == self.SLOW_SYNC:
LOG('Warning !!!, reseting client synchronization for subscriber:',0, LOG('Warning !!!, reseting client synchronization for subscriber:', WARNING,
subscriber) subscriber.getPath())
subscriber.resetAllSignatures() subscriber.resetAllSignatures()
# Check if the last time synchronization is the same as the client one # Check if the last time synchronization is the same as the client one
...@@ -89,16 +88,12 @@ class PublicationSynchronization(XMLSyncUtils): ...@@ -89,16 +88,12 @@ class PublicationSynchronization(XMLSyncUtils):
\nlast_anchor:\t\t\t%s\nnext_anchor:\t\t\t%s' % \ \nlast_anchor:\t\t\t%s\nnext_anchor:\t\t\t%s' % \
(subscriber.getNextAnchor(), subscriber.getLastAnchor(), last_anchor, \ (subscriber.getNextAnchor(), subscriber.getLastAnchor(), last_anchor, \
next_anchor) next_anchor)
#LOG('PubSyncInit',0,mess)
if subscriber.getNextAnchor() != last_anchor: if subscriber.getNextAnchor() != last_anchor:
if last_anchor in (None, ''): if last_anchor in (None, ''):
LOG('PubSyncInit',0,'anchor null') LOG('PubSyncInit', DEBUG, 'anchor null')
#raise ValueError, "Sorry, the anchor was null"
else: else:
message = "bad anchors in PubSyncInit! " + \ message = "bad anchors in PubSyncInit! " + \
subscriber.getNextAnchor() + " and " + last_anchor subscriber.getNextAnchor() + " and " + last_anchor
LOG('PubSyncInit',0,message)
else: else:
subscriber.setNextAnchor(next_anchor) subscriber.setNextAnchor(next_anchor)
...@@ -118,10 +113,10 @@ class PublicationSynchronization(XMLSyncUtils): ...@@ -118,10 +113,10 @@ class PublicationSynchronization(XMLSyncUtils):
if publication.isAuthenticationRequired(): if publication.isAuthenticationRequired():
#at the begining, the code is initialised at UNAUTHORIZED #at the begining, the code is initialised at UNAUTHORIZED
auth_code=self.UNAUTHORIZED auth_code=self.UNAUTHORIZED
LOG('PubSyncInit',0,'authentication required') LOG('PubSyncInit', INFO, 'authentication required')
if not cred: if not cred:
auth_code=self.AUTH_REQUIRED auth_code=self.AUTH_REQUIRED
LOG("there's no credential !!!",0,'') LOG("PubSyncInit there's no credential !!!", INFO,'')
# Prepare the xml message for the Sync initialization package # Prepare the xml message for the Sync initialization package
xml(self.SyncMLChal(cmd_id, "SyncHdr", xml(self.SyncMLChal(cmd_id, "SyncHdr",
publication.getPublicationUrl(), subscriber.getSubscriptionUrl(), publication.getPublicationUrl(), subscriber.getSubscriptionUrl(),
...@@ -156,7 +151,6 @@ class PublicationSynchronization(XMLSyncUtils): ...@@ -156,7 +151,6 @@ class PublicationSynchronization(XMLSyncUtils):
auth_code=self.UNAUTHORIZED auth_code=self.UNAUTHORIZED
#in all others cases, the auth_code is set to UNAUTHORIZED #in all others cases, the auth_code is set to UNAUTHORIZED
# Prepare the xml message for the Sync initialization package # Prepare the xml message for the Sync initialization package
if auth_code == self.AUTH_ACCEPTED: if auth_code == self.AUTH_ACCEPTED:
xml_status, cmd_id = self.SyncMLStatus(xml_client, auth_code, xml_status, cmd_id = self.SyncMLStatus(xml_client, auth_code,
...@@ -203,7 +197,6 @@ class PublicationSynchronization(XMLSyncUtils): ...@@ -203,7 +197,6 @@ class PublicationSynchronization(XMLSyncUtils):
xml(' </SyncBody>\n') xml(' </SyncBody>\n')
xml('</SyncML>\n') xml('</SyncML>\n')
xml_a = ''.join(xml_list) xml_a = ''.join(xml_list)
if publication.getSyncContentType() == self.CONTENT_TYPE['SYNCML_WBXML']: if publication.getSyncContentType() == self.CONTENT_TYPE['SYNCML_WBXML']:
xml_a = self.xml2wbxml(xml_a) xml_a = self.xml2wbxml(xml_a)
self.sendResponse(from_url=publication.getPublicationUrl(), self.sendResponse(from_url=publication.getPublicationUrl(),
...@@ -211,20 +204,20 @@ class PublicationSynchronization(XMLSyncUtils): ...@@ -211,20 +204,20 @@ class PublicationSynchronization(XMLSyncUtils):
xml=xml_a, domain=publication, xml=xml_a, domain=publication,
content_type=publication.getSyncContentType()) content_type=publication.getSyncContentType())
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): def PubSync(self, publication_path, msg=None, RESPONSE=None, subscriber=None):
""" """
This is the synchronization method for the server This is the synchronization method for the server
""" """
LOG('PubSync',0,'Starting... publication: %s' % str(publication_path)) LOG('PubSync', DEBUG, 'Starting... publication: %s' % (publication_path))
# Read the request from the client # Read the request from the client
publication = self.unrestrictedTraverse(publication_path) publication = self.unrestrictedTraverse(publication_path)
xml_client = msg xml_client = msg
if xml_client is None: if xml_client is None:
xml_client = self.readResponse(from_url=publication.getPublicationUrl()) xml_client = self.readResponse(from_url=publication.getPublicationUrl())
#LOG('PubSync',0,'Starting... msg: %s' % str(xml_client)) LOG('PubSync', DEBUG, 'Starting... msg: %s' % str(xml_client))
result = None result = None
if xml_client is not None: if xml_client is not None:
...@@ -233,14 +226,13 @@ class PublicationSynchronization(XMLSyncUtils): ...@@ -233,14 +226,13 @@ class PublicationSynchronization(XMLSyncUtils):
first_node = xml_client.childNodes[0] first_node = xml_client.childNodes[0]
if first_node.nodeName != "SyncML": if first_node.nodeName != "SyncML":
#LOG('PubSync',0,'This is not a SyncML Message') LOG('PubSync', INFO, 'This is not a SyncML Message')
raise ValueError, "Sorry, This is not a SyncML Message" raise ValueError, "Sorry, This is not a SyncML Message"
alert_code = self.getAlertCode(xml_client) alert_code = self.getAlertCode(xml_client)
# Get informations from the header # Get informations from the header
client_header = first_node.childNodes[1] client_header = first_node.childNodes[1]
if client_header.nodeName != "SyncHdr": if client_header.nodeName != "SyncHdr":
#LOG('PubSync',0,'This is not a SyncML Header') LOG('PubSync', INFO, 'This is not a SyncML Header')
raise ValueError, "Sorry, This is not a SyncML Header" raise ValueError, "Sorry, This is not a SyncML Header"
subscription_url = self.getSubscriptionUrl(client_header) subscription_url = self.getSubscriptionUrl(client_header)
# Get the subscriber or create it if not already in the list # Get the subscriber or create it if not already in the list
...@@ -273,7 +265,7 @@ class PublicationSynchronization(XMLSyncUtils): ...@@ -273,7 +265,7 @@ class PublicationSynchronization(XMLSyncUtils):
# This looks like we are starting a synchronization after # This looks like we are starting a synchronization after
# a conflict resolution by the user # a conflict resolution by the user
result = self.PubSyncInit(publication=publication, xml_client=None, result = self.PubSyncInit(publication=publication, xml_client=None,
subscriber=subscriber,sync_type=self.TWO_WAY) subscriber=subscriber, sync_type=self.TWO_WAY)
if RESPONSE is not None: if RESPONSE is not None:
RESPONSE.redirect('managePublications') RESPONSE.redirect('managePublications')
...@@ -284,4 +276,4 @@ class PublicationSynchronization(XMLSyncUtils): ...@@ -284,4 +276,4 @@ class PublicationSynchronization(XMLSyncUtils):
""" """
The modidification message for the publication The modidification message for the publication
""" """
return self.SyncModif(publication,xml_client) return self.SyncModif(publication, xml_client)
This diff is collapsed.
...@@ -32,7 +32,7 @@ from XMLSyncUtils import XMLSyncUtils, Parse ...@@ -32,7 +32,7 @@ from XMLSyncUtils import XMLSyncUtils, Parse
import commands import commands
from Conduit.ERP5Conduit import ERP5Conduit from Conduit.ERP5Conduit import ERP5Conduit
from DateTime import DateTime from DateTime import DateTime
from zLOG import LOG from zLOG import LOG, DEBUG, INFO
class SubscriptionSynchronization(XMLSyncUtils): class SubscriptionSynchronization(XMLSyncUtils):
...@@ -100,11 +100,11 @@ class SubscriptionSynchronization(XMLSyncUtils): ...@@ -100,11 +100,11 @@ class SubscriptionSynchronization(XMLSyncUtils):
status_code_syncHdr = status_list[0]['code'] status_code_syncHdr = status_list[0]['code']
if status_code_syncHdr.isdigit(): if status_code_syncHdr.isdigit():
status_code_syncHdr = int(status_code_syncHdr) status_code_syncHdr = int(status_code_syncHdr)
#LOG('readResponse status code :',0,status_code_syncHdr) LOG('SubSync status code : ', DEBUG, status_code_syncHdr)
if status_code_syncHdr == self.AUTH_REQUIRED: if status_code_syncHdr == self.AUTH_REQUIRED:
if self.checkChal(xml_client): if self.checkChal(xml_client):
authentication_format, authentication_type = self.getChal(xml_client) authentication_format, authentication_type = self.getChal(xml_client)
#LOG('auth_required :',0, 'format:%s, type:%s' % (authentication_format, authentication_type)) LOG('SubSync auth_required :', DEBUG, 'format:%s, type:%s' % (authentication_format, authentication_type))
if authentication_format is not None and \ if authentication_format is not None and \
authentication_type is not None: authentication_type is not None:
subscription.setAuthenticationFormat(authentication_format) subscription.setAuthenticationFormat(authentication_format)
...@@ -113,11 +113,11 @@ class SubscriptionSynchronization(XMLSyncUtils): ...@@ -113,11 +113,11 @@ class SubscriptionSynchronization(XMLSyncUtils):
raise ValueError, "Sorry, the server chalenge for an \ raise ValueError, "Sorry, the server chalenge for an \
authentication, but the authentication format is not find" authentication, but the authentication format is not find"
#LOG('readResponse', 0, 'Authentication required') LOG('SubSync', INFO, 'Authentication required')
response = self.SubSyncCred(subscription, xml_client) response = self.SubSyncCred(subscription, xml_client)
elif status_code_syncHdr == self.UNAUTHORIZED: elif status_code_syncHdr == self.UNAUTHORIZED:
LOG('readResponse', 0, 'Bad authentication') LOG('SubSync', INFO, 'Bad authentication')
return {'has_response':0,'xml':xml_client} return {'has_response':0, 'xml':xml_client}
else: else:
response = self.SubSyncModif(subscription, xml_client) response = self.SubSyncModif(subscription, xml_client)
else: else:
...@@ -174,7 +174,7 @@ class SubscriptionSynchronization(XMLSyncUtils): ...@@ -174,7 +174,7 @@ class SubscriptionSynchronization(XMLSyncUtils):
xml=xml_a,domain=subscription, xml=xml_a,domain=subscription,
content_type=subscription.getSyncContentType()) content_type=subscription.getSyncContentType())
return {'has_response':1,'xml':xml_a} return {'has_response':1, 'xml':xml_a}
def SubSyncModif(self, subscription, xml_client): def SubSyncModif(self, subscription, xml_client):
""" """
......
...@@ -40,6 +40,7 @@ class SyncCode(Persistent): ...@@ -40,6 +40,7 @@ class SyncCode(Persistent):
ONE_WAY_FROM_SERVER = 204 ONE_WAY_FROM_SERVER = 204
WAITING_DATA = 214 WAITING_DATA = 214
REFRESH_REQUIRED = 508 REFRESH_REQUIRED = 508
CODE_LIST = ( TWO_WAY, ONE_WAY_FROM_SERVER )
# SyncML Status Codes # SyncML Status Codes
SUCCESS = 200 SUCCESS = 200
......
This diff is collapsed.
This diff is collapsed.
...@@ -48,7 +48,7 @@ class XupdateUtils(XMLSyncUtilsMixin): ...@@ -48,7 +48,7 @@ class XupdateUtils(XMLSyncUtilsMixin):
for subnode in self.getElementNodeList(xupdate): for subnode in self.getElementNodeList(xupdate):
selection_name = '' selection_name = ''
if subnode.nodeName in self.XUPDATE_INSERT_OR_ADD: if subnode.nodeName in self.XUPDATE_INSERT_OR_ADD:
conflict_list += conduit.addNode(xml=subnode,object=object, \ conflict_list += conduit.addNode(xml=subnode, object=object, \
force=force, **kw) force=force, **kw)
elif subnode.nodeName in self.XUPDATE_DEL: elif subnode.nodeName in self.XUPDATE_DEL:
conflict_list += conduit.deleteNode(xml=subnode, object=object, \ conflict_list += conduit.deleteNode(xml=subnode, object=object, \
...@@ -56,9 +56,6 @@ class XupdateUtils(XMLSyncUtilsMixin): ...@@ -56,9 +56,6 @@ class XupdateUtils(XMLSyncUtilsMixin):
elif subnode.nodeName in self.XUPDATE_UPDATE: elif subnode.nodeName in self.XUPDATE_UPDATE:
conflict_list += conduit.updateNode(xml=subnode, object=object, \ conflict_list += conduit.updateNode(xml=subnode, object=object, \
force=force, **kw) force=force, **kw)
#elif subnode.nodeName in self.XUPDATE_INSERT:
# conflict_list += conduit.addNode(xml=subnode, object=object, force=force, **kw)
return conflict_list return conflict_list
...@@ -69,9 +69,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ...@@ -69,9 +69,10 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
<select name="alert_code"> <select name="alert_code">
<dtml-in getAlertCodeList> <dtml-in getAlertCodeList>
<dtml-let item=sequence-item> <dtml-let item=sequence-item>
<option value="<dtml-var item>" <dtml-if expr="getAlertCode() == str(item)">SELECTED</dtml-if>><dtml-var item></option> <option value="<dtml-var item>" <dtml-if expr="getAlertCode() == item">SELECTED</dtml-if>><dtml-var item></option>
</dtml-let> </dtml-let>
</dtml-in> </dtml-in>
</select>
</td> </td>
</tr> </tr>
<tr> <tr>
......
...@@ -147,7 +147,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. ...@@ -147,7 +147,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
</label></div> </label></div>
</td> </td>
<td align="left" valign="top"> <td align="left" valign="top">
<input type="checkbox" name="synchronize_with_erp5_sites" value="1"> <input type="checkbox" name="synchronize_with_erp5_sites" value="1" checked="checked">
</td> </td>
</tr> </tr>
<tr> <tr>
......
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