Commit 12a8a363 authored by Gabriel Monnerat's avatar Gabriel Monnerat

- Fix issue to convert odt to sxg.

- Added one more flag to be ignored, because is not possible convert documents with this filters.
- refactor code to send the possible filters to unoconverter.py according to Document Type.
  i.e com.sun.star.text.GlobalDocument


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@41760 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 0cc2058a
......@@ -28,7 +28,7 @@
from zope.interface import implements
from cloudooo.interfaces.application import IApplication
from cloudooo.utils import logger, socketStatus
from cloudooo.utils import logger, socketStatus, waitStopDaemon
from psutil import pid_exists, Process
......@@ -53,6 +53,7 @@ class Application(object):
logger.debug("Stop Pid - %s" % process_pid)
try:
self.process.terminate()
waitStopDaemon(self, self.timeout)
finally:
if pid_exists(process_pid) or self.status():
Process(process_pid).kill()
......
......@@ -27,6 +27,7 @@
##############################################################################
import json
import re
import pkg_resources
from base64 import decodestring, encodestring
from os import environ, path
......@@ -119,35 +120,30 @@ class OOHandler:
openoffice.start()
command = self._getCommand(*feature_list, **kw)
stdout, stderr = self._subprocess(command)
if not stdout and stderr != '':
if not stdout and len(re.findall("[A-Za-z]*Exception", stderr)) >= 1:
logger.debug(stderr)
if "NoConnectException" in stderr or \
"RuntimeException" in stderr or \
"DisposedException" in stderr:
self.document.restoreOriginal()
openoffice.restart()
kw['document_url'] = self.document.getUrl()
command = self._getCommand(*feature_list, **kw)
stdout, stderr = self._subprocess(command)
elif "ErrorCodeIOException" in stderr:
raise Exception, stderr + \
"This document can not be converted to this format"
else:
raise Exception, stderr
self.document.restoreOriginal()
openoffice.restart()
kw['document_url'] = self.document.getUrl()
command = self._getCommand(*feature_list, **kw)
stdout, stderr = self._subprocess(command)
if stderr != "":
raise Exception, stderr
return stdout, stderr
def _serializeMimemapper(self):
def _serializeMimemapper(self, extension=None):
"""Serialize parts of mimemapper"""
filter_list = []
for extension in mimemapper.extension_list:
for service_type in mimemapper.document_service_list:
if service_type in mimemapper._doc_type_list_by_extension[extension]:
filter_list.append((extension,
service_type,
mimemapper.getFilterName(extension,
service_type)))
if extension is None:
return json.dumps(dict(mimetype_by_filter_type=mimemapper._mimetype_by_filter_type))
filter_list = []
for service_type in mimemapper._doc_type_list_by_extension[extension]:
for extension in mimemapper.extension_list_by_doc_type[service_type]:
filter_list.append((extension,
service_type,
mimemapper.getFilterName(extension,
service_type)))
return json.dumps(dict(doc_type_list_by_extension=mimemapper._doc_type_list_by_extension,
filter_list=filter_list,
mimetype_by_filter_type=mimemapper._mimetype_by_filter_type))
......@@ -162,7 +158,7 @@ class OOHandler:
kw['source_format'] = self.source_format
if destination_format:
kw['destination_format'] = destination_format
kw['mimemapper'] = self._serializeMimemapper()
kw['mimemapper'] = self._serializeMimemapper(destination_format)
kw['refresh'] = json.dumps(self.refresh)
try:
stdout, stderr = self._callUnoConverter(*['convert'], **kw)
......
......@@ -136,19 +136,20 @@ class UnoConverter(object):
return [property,]
def _getFilterName(self, destination_format, type):
for filter_tuple in mimemapper["filter_list"]:
if destination_format == filter_tuple[0] and filter_tuple[1] == type:
return filter_tuple[2]
document_type_list = mimemapper["doc_type_list_by_extension"].get(destination_format)
if type in document_type_list:
for filter_tuple in mimemapper["filter_list"]:
if destination_format == filter_tuple[0] and filter_tuple[1] == type:
return filter_tuple[2]
else:
for filter_tuple in mimemapper["filter_list"]:
if destination_format == filter_tuple[0]:
return filter_tuple[2]
def _getPropertyToExport(self, destination_format=None):
"""Create the property according to the extension of the file."""
if destination_format and self.document_loaded:
doc_type_list = mimemapper["doc_type_list_by_extension"].get(destination_format)
if self.document_type not in doc_type_list:
raise AttributeError, \
"This Document can not be converted for this format"
type = self.document_type
filter_name = self._getFilterName(destination_format, type)
filter_name = self._getFilterName(destination_format, self.document_type)
property_list = []
property = self._createProperty("Overwrite", True)
property_list.append(property)
......
......@@ -54,9 +54,9 @@ class MimeMapper(object):
self._doc_type_list_by_extension = {}
# List of extensions that are ODF
self._odf_extension_list = []
self.extension_list = []
self._mimetype_by_filter_type = {}
self._document_type_dict = {}
self.extension_list = []
def _addFilter(self, filter):
"""Add filter in mimemapper catalog."""
......@@ -104,7 +104,8 @@ class MimeMapper(object):
# Filters that has flag in bad_flag_list is ignored.
# XXX - Is not good way to remove unnecessary filters
# XXX - try find a good way to remove filters that are not used for export
bad_flag_list = [65, 94217, 536641, 1572929, 268959937, 524373, 85, 524353]
bad_flag_list = [65, 94217, 536641, 1572929, 268959937,
524373, 85, 524353, 524391]
uno_path = kw.get("uno_path", environ.get('uno_path'))
office_binary_path = kw.get("office_binary_path",
environ.get('office_binary_path'))
......@@ -122,7 +123,6 @@ class MimeMapper(object):
close_fds=True,
env=getCleanPythonEnvironment()).communicate()
filter_dict, type_dict = json.loads(stdout)
for filter_name, value in filter_dict.iteritems():
flag = value.get("Flags")
if flag in bad_flag_list:
......@@ -185,6 +185,9 @@ class MimeMapper(object):
# Adds the object in filter_by_extension_dict
self._addFilter(filter)
self.document_service_list = self._extension_list_by_type.keys()
self.extension_list_by_doc_type =\
dict([(type, [extension[0] for extension in extension_list])\
for type, extension_list in self._extension_list_by_type.iteritems()])
self._loaded = True
def getMimetypeByFilterType(self, filter_type):
......
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