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