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
b3bcd840
Commit
b3bcd840
authored
Oct 20, 2016
by
Tristan Cavelier
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
+1
parent
fe92b22f
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
15 deletions
+32
-15
cloudooo/handler/wkhtmltopdf/handler.py
cloudooo/handler/wkhtmltopdf/handler.py
+7
-9
cloudooo/handler/x2t/handler.py
cloudooo/handler/x2t/handler.py
+25
-6
No files found.
cloudooo/handler/wkhtmltopdf/handler.py
View file @
b3bcd840
...
@@ -34,6 +34,11 @@ from tempfile import mktemp
...
@@ -34,6 +34,11 @@ from tempfile import mktemp
from
os.path
import
basename
from
os.path
import
basename
from
base64
import
b64decode
from
base64
import
b64decode
mimetype_format_dict
=
{
"application/pdf"
:
"pdf"
,
"text/html"
:
"html"
,
}
def
keyNameToOption
(
key_name
,
prefix
=
""
):
def
keyNameToOption
(
key_name
,
prefix
=
""
):
return
"--"
+
prefix
+
key_name
.
replace
(
"_"
,
"-"
)
return
"--"
+
prefix
+
key_name
.
replace
(
"_"
,
"-"
)
...
@@ -42,17 +47,10 @@ class Handler(object):
...
@@ -42,17 +47,10 @@ class Handler(object):
implements
(
IHandler
)
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
):
def
__init__
(
self
,
base_folder_url
,
data
,
source_mimetype
,
**
kw
):
""" Load pdf document """
""" Load pdf document """
self
.
source_mimetype
=
source_mimetype
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
.
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"
,
{})
...
@@ -72,7 +70,7 @@ class Handler(object):
...
@@ -72,7 +70,7 @@ class Handler(object):
def
convert
(
self
,
destination_mimetype
=
None
,
**
kw
):
def
convert
(
self
,
destination_mimetype
=
None
,
**
kw
):
"""Convert a image"""
"""Convert a image"""
logger
.
debug
(
"wkhtmltopdf convert: %r > %r"
%
(
self
.
source_mimetype
,
destination_mimetype
))
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
)
output_path
=
self
.
makeTempFile
(
destination_format
)
command
=
self
.
makeWkhtmltopdfCommandList
(
command
=
self
.
makeWkhtmltopdfCommandList
(
self
.
convertPathToUrl
(
self
.
file
.
getUrl
()),
self
.
convertPathToUrl
(
self
.
file
.
getUrl
()),
...
...
cloudooo/handler/x2t/handler.py
View file @
b3bcd840
...
@@ -61,6 +61,23 @@ format_code_map = {
...
@@ -61,6 +61,23 @@ format_code_map = {
"pptx"
:
AVS_OFFICESTUDIO_FILE_PRESENTATION_PPTX
,
"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"
)
yformat_tuple
=
(
"docy"
,
"xlsy"
,
"ppty"
)
class
Handler
(
object
):
class
Handler
(
object
):
...
@@ -68,23 +85,25 @@ class Handler(object):
...
@@ -68,23 +85,25 @@ class Handler(object):
implements
(
IHandler
)
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)
base_folder_url(string)
The requested url for data base folder
The requested url for data base folder
data(string)
data(string)
The opened and readed file into a string
The opened and readed file into a string
source_
format
(string)
source_
mimetype
(string)
The source
format
of the inputed file
The source
mimetype
of the inputed file
"""
"""
self
.
base_folder_url
=
base_folder_url
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"
,
{})
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 """
""" Convert the inputed file to output as format that were informed """
source_format
=
self
.
file
.
source_format
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
# init vars and xml configuration file
in_format
=
format_code_map
[
source_format
]
in_format
=
format_code_map
[
source_format
]
...
...
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