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): ...@@ -139,14 +139,11 @@ class Handler(object):
filter_list = [] filter_list = []
service_type_list = mimemapper._doc_type_list_by_extension.get( 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 service_type in service_type_list:
for extension in mimemapper.extension_list_by_doc_type[service_type]: filter_list.append((destination_extension,
if extension == destination_extension:
filter_list.append((extension,
service_type, service_type,
mimemapper.getFilterName(extension, mimemapper.getFilterName(destination_extension, service_type)))
service_type)))
logger.debug("Filter List: %r" % filter_list) logger.debug("Filter List: %r" % filter_list)
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,
......
...@@ -191,9 +191,6 @@ class MimeMapper(object): ...@@ -191,9 +191,6 @@ class MimeMapper(object):
'xls': ['com.sun.star.sheet.SpreadsheetDocument'], 'xls': ['com.sun.star.sheet.SpreadsheetDocument'],
}) })
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 getFilterName(self, extension, document_service): def getFilterName(self, extension, document_service):
...@@ -205,22 +202,18 @@ class MimeMapper(object): ...@@ -205,22 +202,18 @@ class MimeMapper(object):
>>> mimemapper.getFilterName("sdw", "com.sun.star.text.TextDocument") >>> mimemapper.getFilterName("sdw", "com.sun.star.text.TextDocument")
'StarWriter 3.0' '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 filter.getDocumentService() == document_service]
if len(filter_list) > 1: if len(filter_list) > 1:
for filter in iter(filter_list): for filter in iter(filter_list):
if filter.isPreferred(): if filter.isPreferred():
return filter.getName() return filter.getName()
else: 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): for filter in iter(filter_list):
if filter.getName().endswith("Export"): if filter.getName().endswith("Export"):
return filter.getName() return filter.getName()
for filter in iter(filter_list): filter_list.sort(key=lambda x: x.getSortIndex())
if filter.getSortIndex() == num_max_int: return filter_list[-1].getName()
return filter.getName()
else: else:
return filter_list[0].getName() 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