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
b3328e6b
Commit
b3328e6b
authored
Oct 18, 2016
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
+1
parent
c827410b
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
21 additions
and
18 deletions
+21
-18
cloudooo/handler/wkhtmltopdf/handler.py
cloudooo/handler/wkhtmltopdf/handler.py
+14
-11
cloudooo/manager.py
cloudooo/manager.py
+7
-7
No files found.
cloudooo/handler/wkhtmltopdf/handler.py
View file @
b3328e6b
...
...
@@ -37,19 +37,22 @@ from base64 import b64decode
def
keyNameToOption
(
key_name
,
prefix
=
""
):
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
):
"""ImageMagic Handler is used to handler images."""
implements
(
IHandler
)
def
__init__
(
self
,
base_folder_url
,
data
,
source_format
,
**
kw
):
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 """
source_format
=
hackMimetypeToFormatTRISTAN
(
source_format
)
self
.
source_mimetype
=
source_mimetype
source_format
=
self
.
mimetypeToFormat
(
source_mimetype
)
self
.
base_folder_url
=
base_folder_url
self
.
file
=
File
(
base_folder_url
,
data
,
source_format
)
self
.
environment
=
kw
.
get
(
"env"
,
{})
...
...
@@ -66,10 +69,10 @@ class Handler(object):
return
"file://"
+
path
raise
ValueError
(
"path %r is not absolute"
%
path
)
def
convert
(
self
,
destination_
format
=
None
,
**
kw
):
def
convert
(
self
,
destination_
mimetype
=
None
,
**
kw
):
"""Convert a image"""
destination_format
=
hackMimetypeToFormatTRISTAN
(
destination_format
)
logger
.
debug
(
"wkhtmltopdf convert: %s > %s"
%
(
self
.
file
.
source_format
,
destination_format
)
)
logger
.
debug
(
"wkhtmltopdf convert: %r > %r"
%
(
self
.
source_mimetype
,
destination_mimetype
)
)
destination_format
=
self
.
mimetypeToFormat
(
destination_mimetype
)
output_path
=
self
.
makeTempFile
(
destination_format
)
command
=
self
.
makeWkhtmltopdfCommandList
(
self
.
convertPathToUrl
(
self
.
file
.
getUrl
()),
...
...
@@ -94,7 +97,7 @@ class Handler(object):
"""Returns a dictionary with all metadata of document.
along with the metadata.
"""
r
eturn
NotImplementedError
r
aise
NotImplementedError
def
setMetadata
(
self
,
metadata
=
{}):
"""Returns image with new metadata.
...
...
cloudooo/manager.py
View file @
b3328e6b
...
...
@@ -78,27 +78,27 @@ class Manager(object):
self
.
mimetype_registry
=
self
.
kw
.
pop
(
"mimetype_registry"
)
self
.
handler_dict
=
self
.
kw
.
pop
(
"handler_dict"
)
def
convertFile
(
self
,
file
,
source_
format
,
destination_format
,
zip
=
False
,
def
convertFile
(
self
,
file
,
source_
mimetype
,
destination_mimetype
,
zip
=
False
,
refresh
=
False
,
conversion_kw
=
{}):
"""Returns the converted file in the given format.
Keywords arguments:
file -- File as string in base64
source_
format -- Format
of original file as string
destination_
format -- Target format
as string
source_
mimetype -- Mimetype
of original file as string
destination_
mimetype -- Target mimetype
as string
zip -- Boolean Attribute. If true, returns the file in the form of a
zip archive
"""
self
.
kw
[
'zip'
]
=
zip
self
.
kw
[
'refresh'
]
=
refresh
handler_class
=
getHandlerClass
(
source_
format
,
destination_
format
,
handler_class
=
getHandlerClass
(
source_
mimetype
,
destination_
mimetype
,
self
.
mimetype_registry
,
self
.
handler_dict
)
handler
=
handler_class
(
self
.
_path_tmp_dir
,
decodestring
(
file
),
source_
format
,
source_
mimetype
,
**
self
.
kw
)
decode_data
=
handler
.
convert
(
destination_
format
,
**
conversion_kw
)
decode_data
=
handler
.
convert
(
destination_
mimetype
,
**
conversion_kw
)
return
encodestring
(
decode_data
)
def
updateFileMetadata
(
self
,
file
,
source_format
,
metadata_dict
):
...
...
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