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
No related merge requests found
This diff is collapsed.
......@@ -95,7 +95,7 @@ def addPublication( self, id, title='', REQUEST=None ):
Add a new Category and generate UID by calling the
ZSQLCatalog
"""
o = Publication( id ,'','','','','')
o = Publication( id, '', '', '', '', '')
self._setObject( id, o )
if REQUEST is not None:
return self.manage_main(self, REQUEST, update_menu=1)
......@@ -143,9 +143,9 @@ class Publication(Subscription):
# Constructor
def __init__(self, id, title, publication_url, destination_path,
source_uri, query, xml_mapping, conduit, gpg_key, id_generator,
gid_generator, media_type, auth_required, authentication_format,
authentication_type, activity_enabled, synchronize_with_erp5_sites,
source_uri, query, xml_mapping, conduit, gpg_key, id_generator,
gid_generator, media_type, auth_required, authentication_format,
authentication_type, activity_enabled, synchronize_with_erp5_sites,
sync_content_type):
"""
constructor
......@@ -157,7 +157,6 @@ class Publication(Subscription):
self.setSourceURI(source_uri)
self.setQuery(query)
self.xml_mapping = xml_mapping
#self.list_subscribers = PersistentMapping()
self.domain_type = self.PUB
self.gpg_key = gpg_key
self.setGidGenerator(gid_generator)
......@@ -231,26 +230,24 @@ class Publication(Subscription):
"""
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)
self.delSubscriber(subscriber.getSubscriptionUrl())
new_id = subscriber.getId()
if new_id is None:
new_id = str(self.generateNewId())
subscriber.id = new_id
#if len(self.list_subscribers) == 0:
# self.list_subscribers = []
#self.list_subscribers = self.list_subscribers + [subscriber]
self._setObject(new_id,subscriber)
self._setObject(new_id, subscriber)
def getSubscriber(self, subscription_url):
"""
return the subscriber corresponding the to subscription_url
"""
for o in self.objectValues():
if o.getSubscriptionUrl() == subscription_url:
return o
return None
o = None
for sub in self.getSubscriberList():
if sub.getSubscriptionUrl() == subscription_url:
o = sub
break
return o
def getSubscriberList(self):
"""
......@@ -263,16 +260,16 @@ class Publication(Subscription):
"""
Delete a subscriber for this publication
"""
for o in self.objectValues():
for o in self.getSubscriberList():
if o.getSubscriptionUrl() == subscription_url:
self._delObject(o.id)
self.activate().manage_delObjects(o.id)
def resetAllSubscribers(self):
"""
Reset all subscribers
"""
for o in self.objectValues():
self._delObject(o.id)
for o in self.getSubscriberList():
self.activate().manage_delObjects(o.id)
def getConflictList(self):
"""
......@@ -280,6 +277,6 @@ class Publication(Subscription):
"""
conflict_list = []
for subscriber in self.getSubscriberList():
conflict_list += subscriber.getConflictList()
conflict_list.extend(subscriber.getConflictList())
return conflict_list
......@@ -39,11 +39,11 @@ from Products.PluggableAuthService.interfaces.plugins import\
from AccessControl.SecurityManagement import newSecurityManager
import commands
from DateTime import DateTime
from zLOG import LOG
from zLOG import LOG, DEBUG, INFO, WARNING
class PublicationSynchronization(XMLSyncUtils):
"""
Receive the first XML message from the client
"""
def PubSyncInit(self, publication=None, xml_client=None, subscriber=None,
......@@ -52,8 +52,7 @@ class PublicationSynchronization(XMLSyncUtils):
Read the client xml message
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
subscriber.setSessionId(self.getSessionId(xml_client))
#same for the message id
......@@ -80,8 +79,8 @@ class PublicationSynchronization(XMLSyncUtils):
# If slow sync, then resend everything
if alert_code == self.SLOW_SYNC:
LOG('Warning !!!, reseting client synchronization for subscriber:',0,
subscriber)
LOG('Warning !!!, reseting client synchronization for subscriber:', WARNING,
subscriber.getPath())
subscriber.resetAllSignatures()
# Check if the last time synchronization is the same as the client one
......@@ -89,16 +88,12 @@ class PublicationSynchronization(XMLSyncUtils):
\nlast_anchor:\t\t\t%s\nnext_anchor:\t\t\t%s' % \
(subscriber.getNextAnchor(), subscriber.getLastAnchor(), last_anchor, \
next_anchor)
#LOG('PubSyncInit',0,mess)
if subscriber.getNextAnchor() != last_anchor:
if last_anchor in (None, ''):
LOG('PubSyncInit',0,'anchor null')
#raise ValueError, "Sorry, the anchor was null"
LOG('PubSyncInit', DEBUG, 'anchor null')
else:
message = "bad anchors in PubSyncInit! " + \
subscriber.getNextAnchor() + " and " + last_anchor
LOG('PubSyncInit',0,message)
else:
subscriber.setNextAnchor(next_anchor)
......@@ -118,14 +113,14 @@ class PublicationSynchronization(XMLSyncUtils):
if publication.isAuthenticationRequired():
#at the begining, the code is initialised at UNAUTHORIZED
auth_code=self.UNAUTHORIZED
LOG('PubSyncInit',0,'authentication required')
LOG('PubSyncInit', INFO, 'authentication required')
if not cred:
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
xml(self.SyncMLChal(cmd_id, "SyncHdr",
publication.getPublicationUrl(), subscriber.getSubscriptionUrl(),
publication.getAuthenticationFormat(),
xml(self.SyncMLChal(cmd_id, "SyncHdr",
publication.getPublicationUrl(), subscriber.getSubscriptionUrl(),
publication.getAuthenticationFormat(),
publication.getAuthenticationType(), auth_code))
cmd_id += 1
# chal message
......@@ -154,8 +149,7 @@ class PublicationSynchronization(XMLSyncUtils):
break
else:
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
if auth_code == self.AUTH_ACCEPTED:
......@@ -163,25 +157,25 @@ class PublicationSynchronization(XMLSyncUtils):
cmd_id, next_anchor, subscription=subscriber).values()
xml(xml_status)
# alert message
xml(self.SyncMLAlert(cmd_id, sync_type, subscriber.getTargetURI(),
subscriber.getSourceURI(), subscriber.getLastAnchor(),
xml(self.SyncMLAlert(cmd_id, sync_type, subscriber.getTargetURI(),
subscriber.getSourceURI(), subscriber.getLastAnchor(),
next_anchor))
cmd_id += 1
else:
# chal message
xml(self.SyncMLChal(cmd_id, "SyncHdr",
publication.getPublicationUrl(), subscriber.getSubscriptionUrl(),
publication.getAuthenticationFormat(),
xml(self.SyncMLChal(cmd_id, "SyncHdr",
publication.getPublicationUrl(), subscriber.getSubscriptionUrl(),
publication.getAuthenticationFormat(),
publication.getAuthenticationType(), auth_code))
cmd_id += 1
xml_status, cmd_id = self.SyncMLStatus(xml_client,
self.AUTH_REQUIRED, cmd_id, next_anchor,
xml_status, cmd_id = self.SyncMLStatus(xml_client,
self.AUTH_REQUIRED, cmd_id, next_anchor,
subscription=subscriber).values()
xml(xml_status)
elif alert is not None: #if no identification is required :
# syncml header
xml_status, cmd_id = self.SyncMLStatus(xml_client, self.AUTH_ACCEPTED,
xml_status, cmd_id = self.SyncMLStatus(xml_client, self.AUTH_ACCEPTED,
cmd_id, next_anchor, subscription=subscriber).values()
xml(xml_status)
# alert message
......@@ -203,28 +197,27 @@ class PublicationSynchronization(XMLSyncUtils):
xml(' </SyncBody>\n')
xml('</SyncML>\n')
xml_a = ''.join(xml_list)
if publication.getSyncContentType() == self.CONTENT_TYPE['SYNCML_WBXML']:
xml_a = self.xml2wbxml(xml_a)
self.sendResponse(from_url=publication.getPublicationUrl(),
to_url=subscriber.getSubscriptionUrl(), sync_id=publication.getTitle(),
xml=xml_a, domain=publication,
to_url=subscriber.getSubscriptionUrl(), sync_id=publication.getTitle(),
xml=xml_a, domain=publication,
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):
"""
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
publication = self.unrestrictedTraverse(publication_path)
xml_client = msg
if xml_client is None:
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
if xml_client is not None:
......@@ -233,14 +226,13 @@ class PublicationSynchronization(XMLSyncUtils):
first_node = xml_client.childNodes[0]
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"
alert_code = self.getAlertCode(xml_client)
# Get informations from the header
client_header = first_node.childNodes[1]
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"
subscription_url = self.getSubscriptionUrl(client_header)
# Get the subscriber or create it if not already in the list
......@@ -272,8 +264,8 @@ class PublicationSynchronization(XMLSyncUtils):
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)
result = self.PubSyncInit(publication=publication, xml_client=None,
subscriber=subscriber, sync_type=self.TWO_WAY)
if RESPONSE is not None:
RESPONSE.redirect('managePublications')
......@@ -284,4 +276,4 @@ class PublicationSynchronization(XMLSyncUtils):
"""
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
import commands
from Conduit.ERP5Conduit import ERP5Conduit
from DateTime import DateTime
from zLOG import LOG
from zLOG import LOG, DEBUG, INFO
class SubscriptionSynchronization(XMLSyncUtils):
......@@ -48,8 +48,8 @@ class SubscriptionSynchronization(XMLSyncUtils):
xml = xml_list.append
xml('<SyncML>\n')
# syncml header
xml(self.SyncMLHeader(subscription.incrementSessionId(),
subscription.incrementMessageId(), subscription.getPublicationUrl(),
xml(self.SyncMLHeader(subscription.incrementSessionId(),
subscription.incrementMessageId(), subscription.getPublicationUrl(),
subscription.getSubscriptionUrl(), source_name=subscription.getLogin()))
# syncml body
......@@ -62,7 +62,7 @@ class SubscriptionSynchronization(XMLSyncUtils):
xml(self.SyncMLAlert(cmd_id, subscription.getSynchronizationType(),
subscription.getTargetURI(),
subscription.getSourceURI(),
subscription.getLastAnchor(),
subscription.getLastAnchor(),
subscription.getNextAnchor()))
cmd_id += 1
syncml_put = self.SyncMLPut(cmd_id, subscription)
......@@ -74,9 +74,9 @@ class SubscriptionSynchronization(XMLSyncUtils):
xml_a = ''.join(xml_list)
self.sendResponse(from_url=subscription.subscription_url,
to_url=subscription.publication_url, sync_id=subscription.getTitle(),
xml=xml_a,domain=subscription,
content_type=subscription.getSyncContentType())
to_url=subscription.publication_url, sync_id=subscription.getTitle(),
xml=xml_a,domain=subscription,
content_type=subscription.getSyncContentType())
return {'has_response':1,'xml':xml_a}
......@@ -87,7 +87,7 @@ class SubscriptionSynchronization(XMLSyncUtils):
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(),
msg = self.readResponse(sync_id=subscription.getSubscriptionUrl(),
from_url=subscription.getSubscriptionUrl())
if msg==None:
response = self.SubSyncInit(subscription)
......@@ -100,11 +100,11 @@ class SubscriptionSynchronization(XMLSyncUtils):
status_code_syncHdr = status_list[0]['code']
if status_code_syncHdr.isdigit():
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 self.checkChal(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 \
authentication_type is not None:
subscription.setAuthenticationFormat(authentication_format)
......@@ -113,14 +113,14 @@ class SubscriptionSynchronization(XMLSyncUtils):
raise ValueError, "Sorry, the server chalenge for an \
authentication, but the authentication format is not find"
#LOG('readResponse', 0, 'Authentication required')
LOG('SubSync', INFO, 'Authentication required')
response = self.SubSyncCred(subscription, xml_client)
elif status_code_syncHdr == self.UNAUTHORIZED:
LOG('readResponse', 0, 'Bad authentication')
return {'has_response':0,'xml':xml_client}
LOG('SubSync', INFO, 'Bad authentication')
return {'has_response':0, 'xml':xml_client}
else:
response = self.SubSyncModif(subscription, xml_client)
else:
else:
response = self.SubSyncModif(subscription, xml_client)
if RESPONSE is not None:
......@@ -141,12 +141,12 @@ class SubscriptionSynchronization(XMLSyncUtils):
data=subscription.encode(subscription.getAuthenticationFormat(), data)
xml(self.SyncMLHeader(
subscription.incrementSessionId(),
subscription.incrementMessageId(),
subscription.incrementMessageId(),
subscription.getPublicationUrl(),
subscription.getSubscriptionUrl(),
source_name=subscription.getLogin(),
subscription.getSubscriptionUrl(),
source_name=subscription.getLogin(),
dataCred=data,
authentication_format=subscription.getAuthenticationFormat(),
authentication_format=subscription.getAuthenticationFormat(),
authentication_type=subscription.getAuthenticationType()))
# syncml body
......@@ -174,7 +174,7 @@ class SubscriptionSynchronization(XMLSyncUtils):
xml=xml_a,domain=subscription,
content_type=subscription.getSyncContentType())
return {'has_response':1,'xml':xml_a}
return {'has_response':1, 'xml':xml_a}
def SubSyncModif(self, subscription, xml_client):
"""
......
......@@ -40,6 +40,7 @@ class SyncCode(Persistent):
ONE_WAY_FROM_SERVER = 204
WAITING_DATA = 214
REFRESH_REQUIRED = 508
CODE_LIST = ( TWO_WAY, ONE_WAY_FROM_SERVER )
# SyncML Status Codes
SUCCESS = 200
......
This diff is collapsed.
This diff is collapsed.
......@@ -48,7 +48,7 @@ class XupdateUtils(XMLSyncUtilsMixin):
for subnode in self.getElementNodeList(xupdate):
selection_name = ''
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)
elif subnode.nodeName in self.XUPDATE_DEL:
conflict_list += conduit.deleteNode(xml=subnode, object=object, \
......@@ -56,9 +56,6 @@ class XupdateUtils(XMLSyncUtilsMixin):
elif subnode.nodeName in self.XUPDATE_UPDATE:
conflict_list += conduit.updateNode(xml=subnode, object=object, \
force=force, **kw)
#elif subnode.nodeName in self.XUPDATE_INSERT:
# conflict_list += conduit.addNode(xml=subnode, object=object, force=force, **kw)
return conflict_list
......@@ -66,12 +66,13 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
</label></div>
</td>
<td align="left" valign="top">
<select name="alert_code">
<dtml-in getAlertCodeList>
<dtml-let item=sequence-item>
<option value="<dtml-var item>" <dtml-if expr="getAlertCode() == str(item)">SELECTED</dtml-if>><dtml-var item></option>
</dtml-let>
</dtml-in>
<select name="alert_code">
<dtml-in getAlertCodeList>
<dtml-let item=sequence-item>
<option value="<dtml-var item>" <dtml-if expr="getAlertCode() == item">SELECTED</dtml-if>><dtml-var item></option>
</dtml-let>
</dtml-in>
</select>
</td>
</tr>
<tr>
......
......@@ -147,7 +147,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
</label></div>
</td>
<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>
</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