Commit 20884bac authored by Nicolas Delaby's avatar Nicolas Delaby

replace xupdate generator

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk@14956 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 225c6823
...@@ -32,6 +32,7 @@ from Products.ERP5SyncML.Subscription import Signature ...@@ -32,6 +32,7 @@ from Products.ERP5SyncML.Subscription import Signature
from DateTime import DateTime from DateTime import DateTime
from StringIO import StringIO from StringIO import StringIO
from xml.dom.ext import PrettyPrint from xml.dom.ext import PrettyPrint
from ERP5Diff import ERP5Diff
import random import random
from zLOG import LOG from zLOG import LOG
try: try:
...@@ -378,27 +379,23 @@ class XMLSyncUtilsMixin(SyncCode): ...@@ -378,27 +379,23 @@ class XMLSyncUtilsMixin(SyncCode):
xml_a = ''.join(xml_list) xml_a = ''.join(xml_list)
return xml_a return xml_a
def getXupdateObject(self, object=None, xml_mapping=None, old_xml=None): def getXupdateObject(self, object_xml=None, old_xml=None):
""" """
Generate the xupdate with the new object and the old xml Generate the xupdate with the new object and the old xml
We have to use xmldiff as a command line tool, because all """
over the xmldiff code, there's some print to the standard erp5diff = ERP5Diff()
output, so this is unusable erp5diff.compare(old_xml, object_xml)
""" xupdate_doc = erp5diff._result
filename = str(random.randrange(1,2147483600)) #minidom is buggy, add namespace declaration, and version
old_filename = filename + '.old' attr_ns = xupdate_doc.createAttribute('xmlns:xupdate')
new_filename = filename + '.new' attr_ns.value = 'http://www.xmldb.org/xupdate'
file1 = open('/tmp/%s' % new_filename,'w') attr_version = xupdate_doc.createAttribute('version')
file1.write(self.getXMLObject(object=object,xml_mapping=xml_mapping)) attr_version.value='1.0'
file1.close() xupdate_doc.documentElement.setAttributeNode(attr_ns)
file2 = open('/tmp/%s'% old_filename,'w') xupdate_doc.documentElement.setAttributeNode(attr_version)
file2.write(old_xml) xupdate = xupdate_doc.toxml()
file2.close() #omit xml declaration
xupdate = commands.getoutput('erp5diff /tmp/%s /tmp/%s' %
(old_filename,new_filename))
xupdate = xupdate[xupdate.find('<xupdate:modifications'):] xupdate = xupdate[xupdate.find('<xupdate:modifications'):]
commands.getstatusoutput('rm -f /tmp/%s' % old_filename)
commands.getstatusoutput('rm -f /tmp/%s' % new_filename)
return xupdate return xupdate
def getXMLObject(self, object=None, xml_mapping=None): def getXMLObject(self, object=None, xml_mapping=None):
...@@ -858,8 +855,7 @@ class XMLSyncUtilsMixin(SyncCode): ...@@ -858,8 +855,7 @@ class XMLSyncUtilsMixin(SyncCode):
if not signature.checkMD5(xml_object): if not signature.checkMD5(xml_object):
set_synchronized = 0 set_synchronized = 0
# This object has changed on this side, we have to generate some xmldiff # This object has changed on this side, we have to generate some xmldiff
xml_string = self.getXupdateObject(object=object, xml_string = self.getXupdateObject(object_xml = domain.getXMLFromObject(object),
xml_mapping=domain.xml_mapping,
old_xml=signature.getXML()) old_xml=signature.getXML())
if xml_string.count('\n') > self.MAX_LINES: if xml_string.count('\n') > self.MAX_LINES:
if xml_string.find('--') >= 0: # This make comment fails, so we need to replace if xml_string.find('--') >= 0: # This make comment fails, so we need to replace
......
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