Commit b3bcd840 authored by Tristan Cavelier's avatar Tristan Cavelier

+1

parent fe92b22f
......@@ -34,6 +34,11 @@ from tempfile import mktemp
from os.path import basename
from base64 import b64decode
mimetype_format_dict = {
"application/pdf": "pdf",
"text/html": "html",
}
def keyNameToOption(key_name, prefix=""):
return "--" + prefix + key_name.replace("_", "-")
......@@ -42,17 +47,10 @@ class Handler(object):
implements(IHandler)
def mimetypeToFormat(self, mimetype):
if mimetype == "application/pdf": return "pdf"
if mimetype == "text/html": return "html"
if "/" in mimetype:
raise ValueError("Unhandled mimetype %r" % mimetype)
return mimetype
def __init__(self, base_folder_url, data, source_mimetype, **kw):
""" Load pdf document """
self.source_mimetype = source_mimetype
source_format = self.mimetypeToFormat(source_mimetype)
source_format = mimetype_format_dict[source_mimetype] if "/" in source_mimetype else source_mimetype
self.base_folder_url = base_folder_url
self.file = File(base_folder_url, data, source_format)
self.environment = kw.get("env", {})
......@@ -72,7 +70,7 @@ class Handler(object):
def convert(self, destination_mimetype=None, **kw):
"""Convert a image"""
logger.debug("wkhtmltopdf convert: %r > %r" % (self.source_mimetype, destination_mimetype))
destination_format = self.mimetypeToFormat(destination_mimetype)
destination_format = mimetype_format_dict[destination_mimetype] if "/" in destination_mimetype else destination_mimetype
output_path = self.makeTempFile(destination_format)
command = self.makeWkhtmltopdfCommandList(
self.convertPathToUrl(self.file.getUrl()),
......
......@@ -61,6 +61,23 @@ format_code_map = {
"pptx": AVS_OFFICESTUDIO_FILE_PRESENTATION_PPTX,
}
mimetype_format_dict = {
"application/vnd.openxmlformats-officedocument.wordprocessingml.document": "docx",
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet": "xlsx",
"application/vnd.openxmlformats-officedocument.presentationml.presentation": "pptx",
"application/x-asc-text": "docy",
"application/x-asc-spreadsheet": "xlsy",
"application/x-asc-presentation": "ppty",
}
#format_mimetype_dict = {
# "docx": "application/vnd.openxmlformats-officedocument.wordprocessingml.document",
# "xlsx": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
# "pptx": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
# "docy": "application/x-asc-text",
# "xlsy": "application/x-asc-spreadsheet",
# "ppty": "application/x-asc-presentation",
#}
yformat_tuple = ("docy", "xlsy", "ppty")
class Handler(object):
......@@ -68,23 +85,25 @@ class Handler(object):
implements(IHandler)
def __init__(self, base_folder_url, data, source_format, **kw):
def __init__(self, base_folder_url, data, source_mimetype, **kw):
"""
base_folder_url(string)
The requested url for data base folder
data(string)
The opened and readed file into a string
source_format(string)
The source format of the inputed file
source_mimetype(string)
The source mimetype of the inputed file
"""
self.base_folder_url = base_folder_url
self.file = File(base_folder_url, data, source_format)
self.source_mimetype = source_mimetype# if "/" in source_mimetype else format_mimetype_dict[source_mimetype]
self.file = File(base_folder_url, data, mimetype_format_dict[source_mimetype] if "/" in source_mimetype else source_mimetype)
self.environment = kw.get("env", {})
def convert(self, destination_format=None, **kw):
def convert(self, destination_mimetype=None, **kw):
""" Convert the inputed file to output as format that were informed """
source_format = self.file.source_format
logger.debug("x2t convert: %s > %s" % (source_format, destination_format))
destination_format = mimetype_format_dict[destination_mimetype] if "/" in destination_mimetype else destination_mimetype)
logger.debug("x2t convert: %s > %s" % (self.source_mimetype, destination_mimetype))
# init vars and xml configuration file
in_format = format_code_map[source_format]
......
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