Commit 0476f32f authored by Nicolas Delaby's avatar Nicolas Delaby

Improve backward compatibility between oood and cloudooo.

All oood method signatures are based in this tuple:
  ('filename', 'data', 'meta', 'extension', 'orig_format')
This commit consist into modifying default parameters of methods 
to reflect better old API.
Some variable names are modified to follow order of parameters.

reviewed by Gabriel.


git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@39026 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent 508a7cdc
# -*- coding: utf-8 -*-
############################################################################## ##############################################################################
# #
# Copyright (c) 2002-2010 Nexedi SA and Contributors. All Rights Reserved. # Copyright (c) 2002-2010 Nexedi SA and Contributors. All Rights Reserved.
...@@ -133,18 +134,20 @@ class Manager(object): ...@@ -133,18 +134,20 @@ class Manager(object):
else: else:
return [('','')] return [('','')]
def run_convert(self, filename, file): def run_convert(self, filename='', data=None, meta=None, extension=None,
orig_format=None):
"""Method to support the old API. Wrapper getFileMetadataItemList but """Method to support the old API. Wrapper getFileMetadataItemList but
returns a dict. returns a dict.
This is a Backwards compatibility provided for ERP5 Project, in order to This is a Backwards compatibility provided for ERP5 Project, in order to
keep compatibility with OpenOffice.org Daemon. keep compatibility with OpenOffice.org Daemon.
""" """
orig_format = filename.split('.')[-1] if not extension:
extension = filename.split('.')[-1]
try: try:
response_dict = {} response_dict = {}
response_dict['meta'] = self.getFileMetadataItemList(file, orig_format, True) response_dict['meta'] = self.getFileMetadataItemList(data, extension, True)
response_dict['meta']['MIMEType'] = self.getFileMetadataItemList(response_dict['meta']['Data'], response_dict['meta']['MIMEType'] = self.getFileMetadataItemList(response_dict['meta']['Data'],
orig_format)['MIMEType'] extension)['MIMEType']
# XXX - Backward compatibility: Previous API expects 'mime' now we use 'MIMEType'" # XXX - Backward compatibility: Previous API expects 'mime' now we use 'MIMEType'"
response_dict['meta']['mime'] = response_dict['meta']['MIMEType'] response_dict['meta']['mime'] = response_dict['meta']['MIMEType']
response_dict['data'] = response_dict['meta']['Data'] response_dict['data'] = response_dict['meta']['Data']
...@@ -155,29 +158,33 @@ class Manager(object): ...@@ -155,29 +158,33 @@ class Manager(object):
logger.error(e) logger.error(e)
return (402, {}, e.args[0]) return (402, {}, e.args[0])
def run_setmetadata(self, filename, file, meta): def run_setmetadata(self, filename='', data=None, meta=None,
extension=None, orig_format=None):
"""Wrapper updateFileMetadata but returns a dict. """Wrapper updateFileMetadata but returns a dict.
This is a Backwards compatibility provided for ERP5 Project, in order to This is a Backwards compatibility provided for ERP5 Project, in order to
keep compatibility with OpenOffice.org Daemon. keep compatibility with OpenOffice.org Daemon.
""" """
orig_format = filename.split('.')[-1] if not extension:
extension = filename.split('.')[-1]
response_dict = {} response_dict = {}
try: try:
response_dict['data'] = self.updateFileMetadata(file, orig_format, meta) response_dict['data'] = self.updateFileMetadata(data, extension, meta)
return (200, response_dict, '') return (200, response_dict, '')
except Exception, e: except Exception, e:
logger.error(e) logger.error(e)
return (402, {}, e.args[0]) return (402, {}, e.args[0])
def run_getmetadata(self, filename, file): def run_getmetadata(self, filename='', data=None, meta=None,
extension=None, orig_format=None):
"""Wrapper for getFileMetadataItemList. """Wrapper for getFileMetadataItemList.
This is a Backwards compatibility provided for ERP5 Project, in order to This is a Backwards compatibility provided for ERP5 Project, in order to
keep compatibility with OpenOffice.org Daemon. keep compatibility with OpenOffice.org Daemon.
""" """
orig_format = filename.split('.')[-1] if not extension:
extension = filename.split('.')[-1]
response_dict = {} response_dict = {}
try: try:
response_dict['meta'] = self.getFileMetadataItemList(file, orig_format) response_dict['meta'] = self.getFileMetadataItemList(data, extension)
# XXX - Backward compatibility: Previous API expects 'title' now we use 'Title'" # XXX - Backward compatibility: Previous API expects 'title' now we use 'Title'"
response_dict['meta']['title'] = response_dict['meta']['Title'] response_dict['meta']['title'] = response_dict['meta']['Title']
return (200, response_dict, '') return (200, response_dict, '')
...@@ -185,7 +192,8 @@ class Manager(object): ...@@ -185,7 +192,8 @@ class Manager(object):
logger.error(e) logger.error(e)
return (402, {}, e.args[0]) return (402, {}, e.args[0])
def run_generate(self, filename, file, something, format, orig_format): def run_generate(self, filename='', data=None, meta=None, extension=None,
orig_format=''):
"""Wrapper convertFile but returns a dict which includes mimetype. """Wrapper convertFile but returns a dict which includes mimetype.
This is a Backwards compatibility provided for ERP5 Project, in order to keep This is a Backwards compatibility provided for ERP5 Project, in order to keep
compatibility with OpenOffice.org Daemon. compatibility with OpenOffice.org Daemon.
...@@ -193,28 +201,30 @@ class Manager(object): ...@@ -193,28 +201,30 @@ class Manager(object):
# XXX - ugly way to remove "/" and "." # XXX - ugly way to remove "/" and "."
orig_format = orig_format.split('.')[-1] orig_format = orig_format.split('.')[-1]
orig_format = orig_format.split('/')[-1] orig_format = orig_format.split('/')[-1]
if "htm" in format: if "htm" in extension:
zip = True zip = True
else: else:
zip = False zip = False
try: try:
response_dict = {} response_dict = {}
# XXX - use html format instead of xhtml # XXX - use html format instead of xhtml
if orig_format == "presentation" and format == "xhtml": if orig_format == "presentation" and extension == "xhtml":
format = 'html' extension = 'html'
elif orig_format == "spreadsheet" and format in ("html", "xhtml"): elif orig_format == "spreadsheet" and extension in ("html", "xhtml"):
format = "htm" extension = "htm"
response_dict['data'] = self.convertFile(file, orig_format, format, zip) response_dict['data'] = self.convertFile(data, orig_format, extension,
zip)
# FIXME: Fast solution to obtain the html or pdf mimetypes # FIXME: Fast solution to obtain the html or pdf mimetypes
if zip: if zip:
response_dict['mime'] = "application/zip" response_dict['mime'] = "application/zip"
elif format in ("html", "htm", "xhtml"): elif extension in ("html", "htm", "xhtml"):
response_dict['mime'] = "text/html" response_dict['mime'] = "text/html"
elif format == "pdf": elif extension == "pdf":
response_dict['mime'] = "application/pdf" response_dict['mime'] = "application/pdf"
else: else:
response_dict['mime'] = self.getFileMetadataItemList(response_dict['data'], response_dict['mime'] = self.getFileMetadataItemList(
format)['MIMEType'] response_dict['data'],
extension)['MIMEType']
return (200, response_dict, "") return (200, response_dict, "")
except Exception, e: except Exception, e:
logger.error(e) logger.error(e)
......
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