Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cloudooo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Tristan Cavelier
cloudooo
Commits
c827410b
Commit
c827410b
authored
Sep 09, 2016
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
hack to handle mimetypes quickly
parent
a985974c
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
15 additions
and
2 deletions
+15
-2
cloudooo/handler/wkhtmltopdf/handler.py
cloudooo/handler/wkhtmltopdf/handler.py
+7
-0
cloudooo/manager.py
cloudooo/manager.py
+8
-2
No files found.
cloudooo/handler/wkhtmltopdf/handler.py
View file @
c827410b
...
@@ -37,6 +37,11 @@ from base64 import b64decode
...
@@ -37,6 +37,11 @@ from base64 import b64decode
def
keyNameToOption
(
key_name
,
prefix
=
""
):
def
keyNameToOption
(
key_name
,
prefix
=
""
):
return
"--"
+
prefix
+
key_name
.
replace
(
"_"
,
"-"
)
return
"--"
+
prefix
+
key_name
.
replace
(
"_"
,
"-"
)
def
hackMimetypeToFormatTRISTAN
(
mimetype
):
if
mimetype
in
(
"application/x-pdf-report"
,
"application/pdf"
):
return
"pdf"
if
mimetype
in
(
"text/html"
,):
return
"html"
return
mimetype
class
Handler
(
object
):
class
Handler
(
object
):
"""ImageMagic Handler is used to handler images."""
"""ImageMagic Handler is used to handler images."""
...
@@ -44,6 +49,7 @@ class Handler(object):
...
@@ -44,6 +49,7 @@ class Handler(object):
def
__init__
(
self
,
base_folder_url
,
data
,
source_format
,
**
kw
):
def
__init__
(
self
,
base_folder_url
,
data
,
source_format
,
**
kw
):
""" Load pdf document """
""" Load pdf document """
source_format
=
hackMimetypeToFormatTRISTAN
(
source_format
)
self
.
base_folder_url
=
base_folder_url
self
.
base_folder_url
=
base_folder_url
self
.
file
=
File
(
base_folder_url
,
data
,
source_format
)
self
.
file
=
File
(
base_folder_url
,
data
,
source_format
)
self
.
environment
=
kw
.
get
(
"env"
,
{})
self
.
environment
=
kw
.
get
(
"env"
,
{})
...
@@ -62,6 +68,7 @@ class Handler(object):
...
@@ -62,6 +68,7 @@ class Handler(object):
def
convert
(
self
,
destination_format
=
None
,
**
kw
):
def
convert
(
self
,
destination_format
=
None
,
**
kw
):
"""Convert a image"""
"""Convert a image"""
destination_format
=
hackMimetypeToFormatTRISTAN
(
destination_format
)
logger
.
debug
(
"wkhtmltopdf convert: %s > %s"
%
(
self
.
file
.
source_format
,
destination_format
))
logger
.
debug
(
"wkhtmltopdf convert: %s > %s"
%
(
self
.
file
.
source_format
,
destination_format
))
output_path
=
self
.
makeTempFile
(
destination_format
)
output_path
=
self
.
makeTempFile
(
destination_format
)
command
=
self
.
makeWkhtmltopdfCommandList
(
command
=
self
.
makeWkhtmltopdfCommandList
(
...
...
cloudooo/manager.py
View file @
c827410b
...
@@ -49,7 +49,13 @@ def getHandlerClass(source_format, destination_format, mimetype_registry,
...
@@ -49,7 +49,13 @@ def getHandlerClass(source_format, destination_format, mimetype_registry,
handler_dict
):
handler_dict
):
"""Select handler according to source_format and destination_format
"""Select handler according to source_format and destination_format
"""
"""
if
"/"
in
source_format
:
source_mimetype
=
source_format
else
:
source_mimetype
=
mimetypes
.
types_map
.
get
(
'.%s'
%
source_format
,
"*"
)
source_mimetype
=
mimetypes
.
types_map
.
get
(
'.%s'
%
source_format
,
"*"
)
if
"/"
in
destination_format
:
destination_mimetype
=
destination_format
else
:
destination_mimetype
=
mimetypes
.
types_map
.
get
(
'.%s'
%
destination_format
,
"*"
)
destination_mimetype
=
mimetypes
.
types_map
.
get
(
'.%s'
%
destination_format
,
"*"
)
for
pattern
in
mimetype_registry
:
for
pattern
in
mimetype_registry
:
registry_list
=
pattern
.
split
()
registry_list
=
pattern
.
split
()
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment