[FIX] Remove leftover instances of libxslt and libxml2, replace them by lxml
bzr revid: xmo@tinyerp.com-20091128100104-n0s3sv3p1601mn50
This commit is contained in:
parent
fdcbed339b
commit
752e88e521
|
@ -34,11 +34,10 @@ from osv.orm import browse_null
|
||||||
from osv.orm import browse_record_list
|
from osv.orm import browse_record_list
|
||||||
import pooler
|
import pooler
|
||||||
from xml.dom import minidom
|
from xml.dom import minidom
|
||||||
import libxml2
|
|
||||||
import libxslt
|
|
||||||
from pychart import *
|
from pychart import *
|
||||||
import misc
|
import misc
|
||||||
import cStringIO
|
import cStringIO
|
||||||
|
from lxml import etree
|
||||||
|
|
||||||
class external_pdf(render.render):
|
class external_pdf(render.render):
|
||||||
def __init__(self, pdf):
|
def __init__(self, pdf):
|
||||||
|
@ -351,11 +350,11 @@ class report_custom(report_int):
|
||||||
|
|
||||||
new_doc.childNodes[0].appendChild(lines)
|
new_doc.childNodes[0].appendChild(lines)
|
||||||
|
|
||||||
styledoc = libxml2.parseFile(os.path.join(tools.config['root_path'],'addons/base/report/custom_new.xsl'))
|
transform = etree.XSLT(
|
||||||
style = libxslt.parseStylesheetDoc(styledoc)
|
etree.parse(os.path.join(tools.config['root_path'],
|
||||||
doc = libxml2.parseDoc(new_doc.toxml())
|
'addons/base/report/custom_new.xsl')))
|
||||||
rml_obj = style.applyStylesheet(doc, None)
|
rml = etree.tostring(
|
||||||
rml = style.saveResultToString(rml_obj)
|
transform(etree.fromstring(new_doc.toxml())))
|
||||||
|
|
||||||
self.obj = render.rml(rml)
|
self.obj = render.rml(rml)
|
||||||
self.obj.render()
|
self.obj.render()
|
||||||
|
@ -649,13 +648,11 @@ class report_custom(report_int):
|
||||||
|
|
||||||
new_doc.childNodes[0].appendChild(lines)
|
new_doc.childNodes[0].appendChild(lines)
|
||||||
|
|
||||||
# file('/tmp/terp.xml','w+').write(new_doc.toxml())
|
transform = etree.XSLT(
|
||||||
|
etree.parse(os.path.join(tools.config['root_path'],
|
||||||
styledoc = libxml2.parseFile(os.path.join(tools.config['root_path'],'addons/base/report/custom_new.xsl'))
|
'addons/base/report/custom_new.xsl')))
|
||||||
style = libxslt.parseStylesheetDoc(styledoc)
|
rml = etree.tostring(
|
||||||
doc = libxml2.parseDoc(new_doc.toxml())
|
transform(etree.fromstring(new_doc.toxml())))
|
||||||
rml_obj = style.applyStylesheet(doc, None)
|
|
||||||
rml = style.saveResultToString(rml_obj)
|
|
||||||
|
|
||||||
self.obj = render.rml(rml)
|
self.obj = render.rml(rml)
|
||||||
self.obj.render()
|
self.obj.render()
|
||||||
|
|
|
@ -23,8 +23,6 @@
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
|
||||||
import libxml2
|
|
||||||
import libxslt
|
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
import netsvc
|
import netsvc
|
||||||
import pooler
|
import pooler
|
||||||
|
@ -145,48 +143,34 @@ class report_rml(report_int):
|
||||||
if not self.xsl:
|
if not self.xsl:
|
||||||
return xml
|
return xml
|
||||||
|
|
||||||
# load XSL (parse it to the XML level)
|
stylesheet = etree.parse(tools.file_open(self.xsl))
|
||||||
styledoc = libxml2.parseDoc(tools.file_open(self.xsl).read())
|
xsl_path, _ = os.path.split(self.xsl)
|
||||||
xsl_path, tail = os.path.split(self.xsl)
|
for import_child in stylesheet.findall('./import'):
|
||||||
for child in styledoc.children:
|
if 'href' in import_child.attrib:
|
||||||
if child.name == 'import':
|
imp_file = import_child.get('href')
|
||||||
if child.hasProp('href'):
|
_, imp_file = tools.file_open(imp_file, subdir=xsl_path, pathinfo=True)
|
||||||
imp_file = child.prop('href')
|
import_child.set('href', urllib.quote(str(imp_file)))
|
||||||
_x, imp_file = tools.file_open(imp_file, subdir=xsl_path, pathinfo=True)
|
|
||||||
child.setProp('href', urllib.quote(str(imp_file)))
|
|
||||||
|
|
||||||
#TODO: get all the translation in one query. That means we have to:
|
#TODO: get all the translation in one query. That means we have to:
|
||||||
# * build a list of items to translate,
|
# * build a list of items to translate,
|
||||||
# * issue the query to translate them,
|
# * issue the query to translate them,
|
||||||
# * (re)build/update the stylesheet with the translated items
|
# * (re)build/update the stylesheet with the translated items
|
||||||
|
|
||||||
# translate the XSL stylesheet
|
def translate(doc, lang):
|
||||||
def look_down(child, lang):
|
for node in doc.xpath('//*[@t]'):
|
||||||
while child is not None:
|
translation = service.execute(
|
||||||
if (child.type == "element") and child.hasProp('t'):
|
cr.dbname, uid, 'ir.translation', '_get_source',
|
||||||
#FIXME: use cursor
|
self.name2, 'xsl', lang, node.text)
|
||||||
res = service.execute(cr.dbname, uid, 'ir.translation',
|
if translation:
|
||||||
'_get_source', self.name2, 'xsl', lang, child.content)
|
node.text = translation
|
||||||
if res:
|
|
||||||
child.setContent(res.encode('utf-8'))
|
|
||||||
look_down(child.children, lang)
|
|
||||||
child = child.next
|
|
||||||
|
|
||||||
if context.get('lang', False):
|
if context.get('lang', False):
|
||||||
look_down(styledoc.children, context['lang'])
|
translate(stylesheet, context['lang'])
|
||||||
|
|
||||||
# parse XSL
|
transform = etree.XSLT(stylesheet)
|
||||||
style = libxslt.parseStylesheetDoc(styledoc)
|
xml = etree.tostring(
|
||||||
# load XML (data)
|
transform(etree.fromstring(xml)))
|
||||||
doc = libxml2.parseMemory(xml,len(xml))
|
|
||||||
# create RML (apply XSL to XML data)
|
|
||||||
result = style.applyStylesheet(doc, None)
|
|
||||||
# save result to string
|
|
||||||
xml = style.saveResultToString(result)
|
|
||||||
|
|
||||||
style.freeStylesheet()
|
|
||||||
doc.freeDoc()
|
|
||||||
result.freeDoc()
|
|
||||||
return xml
|
return xml
|
||||||
|
|
||||||
def create_pdf(self, rml, localcontext = None, logo=None, title=None):
|
def create_pdf(self, rml, localcontext = None, logo=None, title=None):
|
||||||
|
|
|
@ -26,8 +26,6 @@ import tools
|
||||||
|
|
||||||
from report import render
|
from report import render
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
import libxml2
|
|
||||||
import libxslt
|
|
||||||
|
|
||||||
import time, os
|
import time, os
|
||||||
|
|
||||||
|
@ -140,11 +138,11 @@ class report_printscreen_list(report_int):
|
||||||
lines.append(node_line)
|
lines.append(node_line)
|
||||||
new_doc.append(node_line)
|
new_doc.append(node_line)
|
||||||
|
|
||||||
styledoc = libxml2.parseFile(os.path.join(tools.config['root_path'],'addons/base/report/custom_new.xsl'))
|
transform = etree.XSLT(
|
||||||
style = libxslt.parseStylesheetDoc(styledoc)
|
etree.parse(os.path.join(tools.config['root_path'],
|
||||||
doc = libxml2.parseDoc(new_doc.toxml())
|
'addons/base/report/custom_new.xsl')))
|
||||||
rml_obj = style.applyStylesheet(doc, None)
|
rml = etree.tostring(transform(new_doc))
|
||||||
rml = style.saveResultToString(rml_obj)
|
|
||||||
self.obj = render.rml(rml, self.title)
|
self.obj = render.rml(rml, self.title)
|
||||||
self.obj.render()
|
self.obj.render()
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -25,8 +25,6 @@ import pooler
|
||||||
import tools
|
import tools
|
||||||
from lxml import etree
|
from lxml import etree
|
||||||
from report import render
|
from report import render
|
||||||
import libxml2
|
|
||||||
import libxslt
|
|
||||||
import locale
|
import locale
|
||||||
|
|
||||||
import time, os
|
import time, os
|
||||||
|
@ -236,11 +234,12 @@ class report_printscreen_list(report_int):
|
||||||
lines.append(node_line)
|
lines.append(node_line)
|
||||||
|
|
||||||
new_doc.append(lines)
|
new_doc.append(lines)
|
||||||
styledoc = libxml2.parseFile(os.path.join(tools.config['root_path'],'addons/base/report/custom_new.xsl'))
|
|
||||||
style = libxslt.parseStylesheetDoc(styledoc)
|
transform = etree.XSLT(
|
||||||
doc = libxml2.parseDoc(etree.tostring(new_doc))
|
etree.parse(os.path.join(tools.config['root_path'],
|
||||||
rml_obj = style.applyStylesheet(doc, None)
|
'addons/base/report/custom_new.xsl')))
|
||||||
rml = style.saveResultToString(rml_obj)
|
rml = etree.tostring(transform(new_doc))
|
||||||
|
|
||||||
self.obj = render.rml(rml, title=self.title)
|
self.obj = render.rml(rml, title=self.title)
|
||||||
self.obj.render()
|
self.obj.render()
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -35,12 +35,6 @@ from config import config
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
try:
|
|
||||||
from lxml import etree
|
|
||||||
except:
|
|
||||||
sys.stderr.write("ERROR: pythonic binding for the libxml2 and libxslt libraries is missing\n")
|
|
||||||
sys.stderr.write("ERROR: Try to install python-lxml package\n")
|
|
||||||
sys.exit(2)
|
|
||||||
import pickle
|
import pickle
|
||||||
|
|
||||||
|
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -55,8 +55,6 @@ py_short_version = '%s.%s' % sys.version_info[:2]
|
||||||
required_modules = [
|
required_modules = [
|
||||||
('psycopg2', 'PostgreSQL module'),
|
('psycopg2', 'PostgreSQL module'),
|
||||||
('xml', 'XML Tools for python'),
|
('xml', 'XML Tools for python'),
|
||||||
('libxml2', 'libxml2 python bindings'),
|
|
||||||
('libxslt', 'libxslt python bindings'),
|
|
||||||
('reportlab', 'reportlab module'),
|
('reportlab', 'reportlab module'),
|
||||||
('pychart', 'pychart module'),
|
('pychart', 'pychart module'),
|
||||||
('pydot', 'pydot module'),
|
('pydot', 'pydot module'),
|
||||||
|
|
Loading…
Reference in New Issue