[Erp5-report] r43561 gabriel - in /erp5/trunk/utils/cloudooo/cloudooo: ./ samples/
nobody at svn.erp5.org
nobody at svn.erp5.org
Tue Feb 22 14:46:04 CET 2011
Author: gabriel
Date: Tue Feb 22 14:46:03 2011
New Revision: 43561
URL: http://svn.erp5.org?rev=43561&view=rev
Log:
Initial commit to multi handler. Addcode to select handler according to mimetype registry declared in cloudooo.conf. The next step is refactor this code and add specific tests
Modified:
erp5/trunk/utils/cloudooo/cloudooo/manager.py
erp5/trunk/utils/cloudooo/cloudooo/paster_application.py
erp5/trunk/utils/cloudooo/cloudooo/samples/sample.conf
Modified: erp5/trunk/utils/cloudooo/cloudooo/manager.py
URL: http://svn.erp5.org/erp5/trunk/utils/cloudooo/cloudooo/manager.py?rev=43561&r1=43560&r2=43561&view=diff
==============================================================================
--- erp5/trunk/utils/cloudooo/cloudooo/manager.py [utf8] (original)
+++ erp5/trunk/utils/cloudooo/cloudooo/manager.py [utf8] Tue Feb 22 14:46:03 2011
@@ -32,10 +32,27 @@ from base64 import encodestring, decodes
from zope.interface import implements
from interfaces.manager import IManager, IERP5Compatibility
from handler.ooo.handler import OOHandler
+from handler.pdf.handler import PDFHandler
+from handler.ffmpeg.handler import FFMPEGHandler
from handler.ooo.mimemapper import mimemapper
from utils.utils import logger
+from fnmatch import fnmatch
+import mimetypes
+handler_dict = {"pdf": PDFHandler, "ooo": OOHandler, "ffmpeg": FFMPEGHandler}
+
+def getHandlerObject(source_format, destination_format, mimetype_registry):
+ """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, '*')
+ for pattern in mimetype_registry:
+ registry_list = pattern.split()
+ if fnmatch(source_mimetype, registry_list[0]) and \
+ fnmatch(destination_mimetype, registry_list[1]):
+ return handler_dict[registry_list[2]]
+ return handler_dict["ooo"]
+
class Manager(object):
"""Manipulates requisitons of client and temporary files in file system."""
implements(IManager, IERP5Compatibility)
@@ -44,6 +61,7 @@ class Manager(object):
"""Need pass the path where the temporary document will be created."""
self._path_tmp_dir = path_tmp_dir
self.kw = kw
+ self.mimetype_registry = self.kw.pop("mimetype_registry")
def convertFile(self, file, source_format, destination_format, zip=False,
refresh=False):
@@ -60,10 +78,13 @@ class Manager(object):
"or is invalid" % destination_format)
self.kw['zip'] = zip
self.kw['refresh'] = refresh
- document = OOHandler(self._path_tmp_dir,
- decodestring(file),
- source_format,
- **self.kw)
+ handler = getHandlerObject(source_format,
+ destination_format,
+ self.mimetype_registry)
+ document = handler(self._path_tmp_dir,
+ decodestring(file),
+ source_format,
+ **self.kw)
decode_data = document.convert(destination_format)
return encodestring(decode_data)
@@ -100,10 +121,13 @@ class Manager(object):
{"title":"abc","description":...})
return encodestring(document_with_metadata)
"""
- document = OOHandler(self._path_tmp_dir,
- decodestring(file),
- source_format,
- **self.kw)
+ handler = getHandlerObject(source_format,
+ "*",
+ self.mimetype_registry)
+ document = handler(self._path_tmp_dir,
+ decodestring(file),
+ source_format,
+ **self.kw)
metadata_dict = dict([(key.capitalize(), value) \
for key, value in metadata_dict.iteritems()])
decode_data = document.setMetadata(metadata_dict)
@@ -123,12 +147,15 @@ class Manager(object):
Note that all keys of the dictionary have the first word in uppercase.
"""
- document = OOHandler(self._path_tmp_dir,
- decodestring(file),
- source_format,
- **self.kw)
+ handler = getHandlerObject(source_format,
+ "*",
+ self.mimetype_registry)
+ document = handler(self._path_tmp_dir,
+ decodestring(file),
+ source_format,
+ **self.kw)
metadata_dict = document.getMetadata(base_document)
- metadata_dict['Data'] = encodestring(metadata_dict['Data'])
+ metadata_dict['Data'] = encodestring(metadata_dict.get('Data', ''))
return metadata_dict
def getAllowedExtensionList(self, request_dict={}):
Modified: erp5/trunk/utils/cloudooo/cloudooo/paster_application.py
URL: http://svn.erp5.org/erp5/trunk/utils/cloudooo/cloudooo/paster_application.py?rev=43561&r1=43560&r2=43561&view=diff
==============================================================================
--- erp5/trunk/utils/cloudooo/cloudooo/paster_application.py [utf8] (original)
+++ erp5/trunk/utils/cloudooo/cloudooo/paster_application.py [utf8] Tue Feb 22 14:46:03 2011
@@ -110,6 +110,9 @@ def application(global_config, **local_c
mimemapper.loadFilterList(application_hostname,
openoffice_port, **kw)
openoffice.release()
+ kw["mimetype_registry"] = filter(None,
+ local_config.get("mimetype_registry", "").split("\n"))
+ kw["env"] = environment_dict
from manager import Manager
cloudooo_manager = Manager(cloudooo_path_tmp_dir, **kw)
return WSGIXMLRPCApplication(instance=cloudooo_manager)
Modified: erp5/trunk/utils/cloudooo/cloudooo/samples/sample.conf
URL: http://svn.erp5.org/erp5/trunk/utils/cloudooo/cloudooo/samples/sample.conf?rev=43561&r1=43560&r2=43561&view=diff
==============================================================================
--- erp5/trunk/utils/cloudooo/cloudooo/samples/sample.conf [utf8] (original)
+++ erp5/trunk/utils/cloudooo/cloudooo/samples/sample.conf [utf8] Tue Feb 22 14:46:03 2011
@@ -41,6 +41,14 @@ openoffice_port = 4062
# specify preferrable executable locations
# env-PATH = /opt/erp5/trunk/parts/imagemagick/bin:/opt/erp5/trunk/parts/w3m/bin
+#
+# Mimetype Registry
+# It is used to select the handler that will be used in conversion
+#
+mimetype_registry =
+ application/pdf * pdf
+ video/* * ffmpeg
+
[server:main]
use = egg:PasteScript#wsgiutils
host = 0.0.0.0
More information about the Erp5-report
mailing list