Commit 85ca8e71 authored by Gabriel Monnerat's avatar Gabriel Monnerat

refactor to load handlers only once

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@43752 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 34ec38f8
......@@ -47,16 +47,14 @@ def getHandlerObject(source_format, destination_format,
"""Select handler according to source_format and destination_format"""
source_mimetype = mimetypes.types_map.get('.%s' % source_format, "*")
destination_mimetype = mimetypes.types_map.get('.%s' % destination_format, "*")
# XXX - Find one way to don't need use iteration to find the handler
for pattern in mimetype_registry:
registry_list = pattern.split()
if fnmatch(source_mimetype, registry_list[0]) and \
(fnmatch(destination_mimetype, registry_list[1]) or destination_format is None):
handler_name = registry_list[2]
import_name = "cloudooo.handler.%s.handler" % handler_name
if import_name not in sys.modules:
__import__(import_name)
handler = sys.modules[import_name]
return getattr(handler, handler_dict[registry_list[2]])
handler = sys.modules[handler_name]
return getattr(handler, handler_dict[handler_name])
class Manager(object):
......
......@@ -30,6 +30,7 @@ import gc
from signal import signal, SIGINT, SIGQUIT, SIGHUP
from os import path, mkdir
import os
import sys
import cloudooo.handler.ooo.monitor as monitor
from cloudooo.handler.ooo.application.openoffice import openoffice
from cloudooo.wsgixmlrpcapplication import WSGIXMLRPCApplication
......@@ -110,14 +111,19 @@ def application(global_config, **local_config):
mimemapper.loadFilterList(application_hostname,
openoffice_port, **kw)
openoffice.release()
kw["mimetype_registry"] = filter(None,
local_config.get("mimetype_registry",
"").split("\n"))
mimetype_registry_str = local_config.get("mimetype_registry")
kw["handler_dict"] = {}
handler_mapping_list = local_config.get("handler_mapping", "").split("\n")
for line in filter(None, handler_mapping_list):
key, value = line.strip().split()
kw["handler_dict"][key] = value
handler_name, object_name = line.strip().split()
import_name = "cloudooo.handler.%s.handler" % handler_name
mimetype_registry_str = mimetype_registry_str.replace(handler_name,
import_name)
if import_name not in sys.modules:
__import__(import_name)
kw["handler_dict"][import_name] = object_name
kw["mimetype_registry"] = filter(None, mimetype_registry_str.split("\n"))
kw["env"] = environment_dict
from manager import Manager
......
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