Commit c830f60c authored by Nicolas Delaby's avatar Nicolas Delaby

Optimisation to avoid duplicates filter in --mimemaper parameter pass to unoconverter helper


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@45058 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 571a0f2f
......@@ -139,14 +139,11 @@ class Handler(object):
filter_list = []
service_type_list = mimemapper._doc_type_list_by_extension.get(
source_extension, mimemapper.extension_list_by_doc_type.keys())
source_extension, mimemapper.document_service_list)
for service_type in service_type_list:
for extension in mimemapper.extension_list_by_doc_type[service_type]:
if extension == destination_extension:
filter_list.append((extension,
filter_list.append((destination_extension,
service_type,
mimemapper.getFilterName(extension,
service_type)))
mimemapper.getFilterName(destination_extension, service_type)))
logger.debug("Filter List: %r" % filter_list)
return json.dumps(dict(doc_type_list_by_extension=mimemapper._doc_type_list_by_extension,
filter_list=filter_list,
......
......@@ -191,9 +191,6 @@ class MimeMapper(object):
'xls': ['com.sun.star.sheet.SpreadsheetDocument'],
})
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 getFilterName(self, extension, document_service):
......@@ -205,22 +202,18 @@ class MimeMapper(object):
>>> mimemapper.getFilterName("sdw", "com.sun.star.text.TextDocument")
'StarWriter 3.0'
"""
filter_list = [filter for filter in iter(self.getFilterList(extension)) \
filter_list = [filter for filter in self.getFilterList(extension) \
if filter.getDocumentService() == document_service]
if len(filter_list) > 1:
for filter in iter(filter_list):
if filter.isPreferred():
return filter.getName()
else:
sort_index_list = [filter.getSortIndex() \
for filter in iter(filter_list)]
num_max_int = max(sort_index_list)
for filter in iter(filter_list):
if filter.getName().endswith("Export"):
return filter.getName()
for filter in iter(filter_list):
if filter.getSortIndex() == num_max_int:
return filter.getName()
filter_list.sort(key=lambda x: x.getSortIndex())
return filter_list[-1].getName()
else:
return filter_list[0].getName()
......
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