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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boris Kocherov
cloudooo
Commits
7f44ed79
Commit
7f44ed79
authored
Dec 12, 2016
by
Boris Kocherov
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'nexedi'
parents
9a104b68
c0752dba
Changes
29
Expand all
Show whitespace changes
Inline
Side-by-side
Showing
29 changed files
with
1022 additions
and
83 deletions
+1022
-83
CHANGELOG.rst
CHANGELOG.rst
+0
-0
MANIFEST.in
MANIFEST.in
+2
-2
README.rst
README.rst
+0
-0
cloudooo/handler/imagemagick/tests/testImagemagickHandler.py
cloudooo/handler/imagemagick/tests/testImagemagickHandler.py
+1
-1
cloudooo/handler/ooo/helper/unoconverter.py
cloudooo/handler/ooo/helper/unoconverter.py
+6
-1
cloudooo/handler/ooo/helper/unomimemapper.py
cloudooo/handler/ooo/helper/unomimemapper.py
+7
-1
cloudooo/handler/ooo/mimemapper.py
cloudooo/handler/ooo/mimemapper.py
+4
-4
cloudooo/handler/ooo/tests/testOooMimemapper.py
cloudooo/handler/ooo/tests/testOooMimemapper.py
+6
-4
cloudooo/handler/ooo/tests/testOooServer.py
cloudooo/handler/ooo/tests/testOooServer.py
+13
-15
cloudooo/handler/wkhtmltopdf/__init__.py
cloudooo/handler/wkhtmltopdf/__init__.py
+0
-0
cloudooo/handler/wkhtmltopdf/handler.py
cloudooo/handler/wkhtmltopdf/handler.py
+442
-0
cloudooo/handler/wkhtmltopdf/tests/__init__.py
cloudooo/handler/wkhtmltopdf/tests/__init__.py
+0
-0
cloudooo/handler/wkhtmltopdf/tests/data/test_toc.xsl
cloudooo/handler/wkhtmltopdf/tests/data/test_toc.xsl
+82
-0
cloudooo/handler/wkhtmltopdf/tests/data/test_with_opacity_style.html
...ndler/wkhtmltopdf/tests/data/test_with_opacity_style.html
+10
-0
cloudooo/handler/wkhtmltopdf/tests/data/test_with_png_dataurl.html
...handler/wkhtmltopdf/tests/data/test_with_png_dataurl.html
+11
-0
cloudooo/handler/wkhtmltopdf/tests/data/test_with_script.html
...dooo/handler/wkhtmltopdf/tests/data/test_with_script.html
+15
-0
cloudooo/handler/wkhtmltopdf/tests/data/test_with_toc.html
cloudooo/handler/wkhtmltopdf/tests/data/test_with_toc.html
+15
-0
cloudooo/handler/wkhtmltopdf/tests/testWkhtmltopdfHandler.py
cloudooo/handler/wkhtmltopdf/tests/testWkhtmltopdfHandler.py
+82
-0
cloudooo/handler/wkhtmltopdf/tests/testWkhtmltopdfServer.py
cloudooo/handler/wkhtmltopdf/tests/testWkhtmltopdfServer.py
+53
-0
cloudooo/handler/x2t/handler.py
cloudooo/handler/x2t/handler.py
+79
-52
cloudooo/handler/x2t/tests/data/test.xlsy
cloudooo/handler/x2t/tests/data/test.xlsy
+0
-0
cloudooo/handler/x2t/tests/data/test_with_image.docx
cloudooo/handler/x2t/tests/data/test_with_image.docx
+0
-0
cloudooo/handler/x2t/tests/data/test_with_image.docy
cloudooo/handler/x2t/tests/data/test_with_image.docy
+0
-0
cloudooo/handler/x2t/tests/testX2tHandler.py
cloudooo/handler/x2t/tests/testX2tHandler.py
+96
-0
cloudooo/handler/x2t/tests/testX2tServer.py
cloudooo/handler/x2t/tests/testX2tServer.py
+57
-0
cloudooo/manager.py
cloudooo/manager.py
+2
-2
cloudooo/mime.types
cloudooo/mime.types
+3
-0
cloudooo/util.py
cloudooo/util.py
+35
-0
setup.py
setup.py
+1
-1
No files found.
CHANGE
S.tx
t
→
CHANGE
LOG.rs
t
View file @
7f44ed79
File moved
MANIFEST.in
View file @
7f44ed79
include README.
tx
t
include CHANGE
S.tx
t
include README.
rs
t
include CHANGE
LOG.rs
t
recursive-include cloudooo *
README.
tx
t
→
README.
rs
t
View file @
7f44ed79
File moved
cloudooo/handler/imagemagick/tests/testImagemagickHandler.py
View file @
7f44ed79
...
...
@@ -53,7 +53,7 @@ class TestHandler(HandlerTestCase):
metadata
=
handler
.
getMetadata
()
self
.
assertEquals
(
metadata
.
get
(
"Compression"
),
"Zip"
)
self
.
assertEquals
(
metadata
.
get
(
"Colorspace"
),
"sRGB"
)
self
.
assertEquals
(
metadata
.
get
(
"
Matte
color"
),
"grey74"
)
self
.
assertEquals
(
metadata
.
get
(
"
Alpha
color"
),
"grey74"
)
def
testsetMetadata
(
self
):
""" Test if metadata are inserted correclty """
...
...
cloudooo/handler/ooo/helper/unoconverter.py
View file @
7f44ed79
...
...
@@ -108,7 +108,12 @@ class UnoConverter(object):
elif
filter_name
==
"impress_pdf_Export"
:
property
=
PropertyValue
(
'FilterData'
,
0
,
uno
.
Any
(
'[]com.sun.star.beans.PropertyValue'
,
(
PropertyValue
(
'ExportNotesPages'
,
0
,
True
,
0
),),),
0
)
(
PropertyValue
(
'ExportNotesPages'
,
0
,
True
,
0
),
PropertyValue
(
'SelectPdfVersion'
,
0
,
1
,
0
),),),
0
)
elif
"pdf_Export"
in
filter_name
:
property
=
PropertyValue
(
'FilterData'
,
0
,
uno
.
Any
(
'[]com.sun.star.beans.PropertyValue'
,
(
PropertyValue
(
'SelectPdfVersion'
,
0
,
1
,
0
),),),
0
)
elif
filter_name
in
(
"draw_html_Export"
,
"HTML (StarCalc)"
):
property
=
PropertyValue
(
'FilterData'
,
0
,
uno
.
Any
(
'[]com.sun.star.beans.PropertyValue'
,
...
...
cloudooo/handler/ooo/helper/unomimemapper.py
View file @
7f44ed79
...
...
@@ -35,11 +35,17 @@ except ImportError:
import
helper_util
from
getopt
import
getopt
,
GetoptError
# python3 support
try
:
basestring
except
NameError
:
basestring
=
str
try
:
long
except
NameError
:
long
=
int
__doc__
=
"""
usage: unomimemapper [options]
...
...
@@ -76,7 +82,7 @@ class UnoMimemapper(object):
for
obj
in
iter
(
element_list
):
if
obj
.
Name
in
ignore_name_list
:
continue
if
not
isinstance
(
obj
.
Value
,
(
bool
,
int
,
basestring
,
tuple
)):
if
not
isinstance
(
obj
.
Value
,
(
bool
,
int
,
long
,
basestring
,
tuple
)):
continue
element_dict
[
obj
.
Name
]
=
obj
.
Value
service_dict
[
name
]
=
element_dict
...
...
cloudooo/handler/ooo/mimemapper.py
View file @
7f44ed79
...
...
@@ -136,10 +136,10 @@ class MimeMapper(object):
filter_dict
,
type_dict
=
json
.
loads
(
stdout
)
ooo_disable_filter_list
=
kw
.
get
(
"ooo_disable_filter_list"
)
or
[]
+
[
'writer_jpg_Export'
,
# Seems not working from cloudooo in Libre Office 4.3.3.2
'writer_png_Export'
,
# Seems not working from cloudooo in Libre Office 4.3.3.2
'draw_eps_Export'
,
# Seems not working from cloudooo in Libre Office 5.0.0.5
'impress_eps_Export'
,
# Seems not working from cloudooo in Libre Office 5.0.0.5
#
'writer_jpg_Export', # Seems not working from cloudooo in Libre Office 4.3.3.2
#
'writer_png_Export', # Seems not working from cloudooo in Libre Office 4.3.3.2
#
'draw_eps_Export', # Seems not working from cloudooo in Libre Office 5.0.0.5
#
'impress_eps_Export', # Seems not working from cloudooo in Libre Office 5.0.0.5
]
ooo_disable_filter_name_list
=
kw
.
get
(
"ooo_disable_filter_name_list"
)
or
[]
+
[
'Text'
,
# Use 'Text - Choose Encoding' instead
...
...
cloudooo/handler/ooo/tests/testOooMimemapper.py
View file @
7f44ed79
...
...
@@ -36,10 +36,10 @@ text_expected_tuple = (
(
'docx'
,
'Office Open XML Text'
),
(
'fodt'
,
'Flat XML ODF Text Document'
),
(
'html'
,
'HTML Document (Writer)'
),
#
('jpg', 'JPEG - Joint Photographic Experts Group'),
(
'jpg'
,
'JPEG - Joint Photographic Experts Group'
),
(
'odt'
,
'ODF Text Document'
),
(
'pdf'
,
'PDF - Portable Document Format'
),
#
('png', 'PNG - Portable Network Graphic'),
(
'png'
,
'PNG - Portable Network Graphic'
),
(
'rtf'
,
'Rich Text'
),
(
'txt'
,
'Text - Choose Encoding'
),
(
'docy'
,
'Docy'
),
...
...
@@ -51,7 +51,7 @@ global_expected_tuple = (
drawing_expected_tuple
=
(
(
'bmp'
,
'BMP - Windows Bitmap'
),
(
'emf'
,
'EMF - Enhanced Metafile'
),
#
('eps', 'EPS - Encapsulated PostScript'),
(
'eps'
,
'EPS - Encapsulated PostScript'
),
(
'fodg'
,
'Flat XML ODF Drawing'
),
(
'gif'
,
'GIF - Graphics Interchange Format'
),
(
'html'
,
'HTML Document (Draw)'
),
...
...
@@ -84,7 +84,7 @@ web_expected_tuple = (
presentation_expected_tuple
=
(
(
'bmp'
,
'BMP - Windows Bitmap'
),
(
'emf'
,
'EMF - Enhanced Metafile'
),
#
('eps', 'EPS - Encapsulated PostScript'),
(
'eps'
,
'EPS - Encapsulated PostScript'
),
(
'fodp'
,
'Flat XML ODF Presentation'
),
(
'gif'
,
'GIF - Graphics Interchange Format'
),
(
'html'
,
'HTML Document (Impress)'
),
...
...
@@ -119,8 +119,10 @@ spreadsheet_expected_tuple = (
(
'html'
,
'HTML Document (Calc)'
),
(
'ods'
,
'ODF Spreadsheet'
),
(
'pdf'
,
'PDF - Portable Document Format'
),
(
'png'
,
'PNG - Portable Network Graphic'
),
(
'slk'
,
'SYLK'
),
(
'xls'
,
'Microsoft Excel 97-2003'
),
(
'xlsm'
,
'Microsoft Excel 2007-2016 XML (macro enabled)'
),
(
'ms.xlsx'
,
'Microsoft Excel 2007-2013 XML'
),
(
'xlsx'
,
'Office Open XML Spreadsheet'
),
(
'xlsy'
,
'Xlsy'
),
...
...
cloudooo/handler/ooo/tests/testOooServer.py
View file @
7f44ed79
...
...
@@ -480,24 +480,22 @@ class TestServer(TestCase):
"""Test if getImageItemList can get the list of images items from odt file"""
data
=
encodestring
(
open
(
"./data/granulate_test.odt"
).
read
())
image_list
=
self
.
proxy
.
getImageItemList
(
data
,
"odt"
)
self
.
assertEquals
([[
'10000000000000C80000009C76245A92.jpg'
,
''
],
[
'10000201000000C80000004EE2BCEED0.png'
,
'TioLive Logo'
],
[
'10000201000000C80000004EE2BCEED0.png'
,
''
],
[
'2000004F00004233000013707E7DE37A.svm'
,
'Python Logo'
],
[
'10000201000000C80000004EE2BCEED0.png'
,
'Again TioLive Logo'
]],
self
.
assertEquals
([[
'10000000000000C80000009CBF079A6E41EE290C.jpg'
,
''
],
[
'10000201000000C80000004EF26C99A54A61B987.png'
,
'TioLive Logo'
],
[
'10000201000000C80000004EF26C99A54A61B987.png'
,
''
],
[
'2000004F0000423300001370ADF6545B2997B448.svm'
,
'Python Logo'
],
[
'10000201000000C80000004EF26C99A54A61B987.png'
,
'Again TioLive Logo'
]],
image_list
)
def
testGetImageItemListFromDoc
(
self
):
"""Test if getImageItemList can get the list of images items from doc file"""
data
=
encodestring
(
open
(
"./data/granulate_test.doc"
).
read
())
image_list
=
self
.
proxy
.
getImageItemList
(
data
,
"doc"
)
self
.
assertEquals
([[
'10000000000000C80000009C76245A92.jpg'
,
''
],
[
'10000201000000C80000004EE2BCEED0.png'
,
'TioLive Logo'
],
[
'10000201000000C80000004EE2BCEED0.png'
,
''
],
[
'2000031600004233000013706A5EA1C8.wmf'
,
'Python Logo'
],
[
'10000201000000C80000004EE2BCEED0.png'
,
'Again TioLive Logo'
]],
self
.
assertEquals
([[
'10000000000000C80000009CBF079A6E41EE290C.jpg'
,
''
],
[
'10000201000000C80000004EF26C99A54A61B987.png'
,
'TioLive Logo'
],
[
'10000201000000C80000004EF26C99A54A61B987.png'
,
''
],
[
'2000031600004233000013702113A0E70B910778.wmf'
,
'Python Logo'
],
[
'10000201000000C80000004EF26C99A54A61B987.png'
,
'Again TioLive Logo'
]],
image_list
)
def
testGetImageFromOdt
(
self
):
...
...
@@ -516,7 +514,7 @@ class TestServer(TestCase):
#so compare with the server return.
data_odt
=
self
.
proxy
.
convertFile
(
data
,
'doc'
,
'odt'
,
False
)
zip
=
ZipFile
(
StringIO
(
decodestring
(
data_odt
)))
image_id
=
'10000000000000C80000009C
76245A92
.jpg'
image_id
=
'10000000000000C80000009C
BF079A6E41EE290C
.jpg'
original_image
=
zip
.
read
(
'Pictures/%s'
%
image_id
)
geted_image
=
decodestring
(
self
.
proxy
.
getImage
(
data
,
image_id
,
"doc"
))
self
.
assertEquals
(
original_image
,
geted_image
)
...
...
cloudooo/handler/wkhtmltopdf/__init__.py
0 → 100644
View file @
7f44ed79
cloudooo/handler/wkhtmltopdf/handler.py
0 → 100644
View file @
7f44ed79
This diff is collapsed.
Click to expand it.
cloudooo/handler/wkhtmltopdf/tests/__init__.py
0 → 100644
View file @
7f44ed79
cloudooo/handler/wkhtmltopdf/tests/data/test_toc.xsl
0 → 100644
View file @
7f44ed79
<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet
version=
"2.0"
xmlns:xsl=
"http://www.w3.org/1999/XSL/Transform"
xmlns:outline=
"http://wkhtmltopdf.org/outline"
xmlns=
"http://www.w3.org/1999/xhtml"
>
<xsl:output
method=
"html"
encoding=
"utf-8"
indent=
"yes"
doctype-system=
"about:legacy-compat"
/>
<xsl:template
match=
"outline:outline"
>
<xsl:param
name=
"count"
select=
"0"
/>
<html>
<head>
<title>
Table of Contents
</title>
<meta
http-equiv=
"Content-Type"
content=
"text/html; charset=utf-8"
/>
<style>
html, body {
overflow-x: initial !important;
}
</style>
</head>
<body>
<p
class=
"ci-document-faux-h1"
>
Table of Contents
</p>
<div
class=
"ci-document-table-of-content"
>
<p
class=
"ci-document-helper"
></p>
<ol>
<xsl:apply-templates
select=
"outline:item/outline:item"
>
<xsl:with-param
name=
"count"
select=
"$count"
/>
</xsl:apply-templates>
</ol>
</div>
</body>
</html>
</xsl:template>
<xsl:template
match=
"outline:item"
>
<xsl:param
name=
"count"
/>
<xsl:choose>
<xsl:when
test=
"number($count)=0"
>
<li
class=
"ci-document-table-of-content-lead-item"
>
<xsl:if
test=
"@title!=''"
>
<div>
<a>
<xsl:if
test=
"@link"
>
<xsl:attribute
name=
"href"
><xsl:value-of
select=
"@link"
/></xsl:attribute>
</xsl:if>
<xsl:if
test=
"@backLink"
>
<xsl:attribute
name=
"name"
><xsl:value-of
select=
"@backLink"
/></xsl:attribute>
</xsl:if>
<xsl:value-of
select=
"@title"
/>
</a>
<span><xsl:value-of
select=
"@page"
/>
</span>
</div>
</xsl:if>
<ol>
<xsl:comment>
added to prevent self-closing tags in QtXmlPatterns
</xsl:comment>
<xsl:apply-templates
select=
"outline:item"
></xsl:apply-templates>
</ol>
</li>
</xsl:when>
<xsl:otherwise>
<li>
<xsl:if
test=
"@title!=''"
>
<div>
<a>
<xsl:if
test=
"@link"
>
<xsl:attribute
name=
"href"
><xsl:value-of
select=
"@link"
/></xsl:attribute>
</xsl:if>
<xsl:if
test=
"@backLink"
>
<xsl:attribute
name=
"name"
><xsl:value-of
select=
"@backLink"
/></xsl:attribute>
</xsl:if>
<xsl:value-of
select=
"@title"
/>
</a>
<span><xsl:value-of
select=
"@page"
/>
</span>
</div>
</xsl:if>
<ol>
<xsl:comment>
added to prevent self-closing tags in QtXmlPatterns
</xsl:comment>
<xsl:apply-templates
select=
"outline:item"
></xsl:apply-templates>
</ol>
</li>
</xsl:otherwise>
</xsl:choose>
</xsl:template>
</xsl:stylesheet>
cloudooo/handler/wkhtmltopdf/tests/data/test_with_opacity_style.html
0 → 100644
View file @
7f44ed79
<!DOCTYPE html>
<html>
<head>
<meta
charset=
"utf-8"
/>
<title>
Test Title With Opacity Style
</title>
</head>
<body>
<p
style=
"opacity:0.5;"
>
Hello
</p>
</body>
</html>
cloudooo/handler/wkhtmltopdf/tests/data/test_with_png_dataurl.html
0 → 100644
View file @
7f44ed79
<!DOCTYPE html>
<html>
<head>
<meta
charset=
"utf-8"
/>
<title>
Test Title With PNG Data URL
</title>
</head>
<body>
<p>
Hello
</p>
<img
src=
"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABYAAAAWCAYAAADEtGw7AAAAAXNSR0IArs4c6QAAAAZiS0dEAP8A/wD/oL2nkwAAAAlwSFlzAAALEwAACxMBAJqcGAAAAAd0SU1FB9oKGhI2GfiwdBgAAASJSURBVDjLnVVdbFRFGD0zc+/+sOy22y20SqkPSGkRWkDUtBEjJMSkiQmQmGA0fdJHNRITEt99FR9MIIZoYkzECAkmUC0hQQsi2JaCbWptu92W0u2W7t+93bt378/M5wNQmoYCepLJTCYzJ/N93znfAE+Bnp6eR+7btr3qHYb/gBMnTrwlhJjq6uqylFKt4XD4lG3bCIfDTyZ2HVuAiQCAAIAggM2e5+3N5/NHI5HI2kgkAqUUAEAplYhEIvnHvubIkSOsaJgfukb2nOt6A67rzjmOQ7ZtU7lcJtu2ybZtWS6XlWVZ0rIsKhaL76/Gxx8sWlpaYJrmLuXLTl/6O6WUdUopYowR55w45ySlZFJK+L7PpJTQNO3QasQaAJw/f76pubn5S9Mw9tRVbwAHAYyDiJaHDcbY0lBKke/7e55UPL2vr88lItq5Ywcp12aS6yCih6Hxe8FJKeE4DugepOC8rSaR+Hslsbg/q87OzmhNTU1HOBSCxhiYpoMxtkRIRFBSouIy3C5kMZUtskyhhGvjKWNDR2Oyv7vXWEnMAISklDPt7e1dnufptfFqQGhgjMH3fRARiAi5RQtf/XkMY1Y3Jo1rmCoOsvnF0VdnC+PvRVueWzN7PXmpev9HqExeh7gvqYaxsTHt4MGDzbqub1pfWwMFDiklOOfgjOP2wiQ+PfMNRCSL6toAFDSU3QymF1JsdCoVEEy8LmvfCOd+OX7xgSocAJ7v+7GTJ092A2CO4xARQYh7mSqaBXze8xnCVf9gfZ2JYDiHQGwIRqUAu+KAMc4YVyQ9cTSw59jby+WWBiBOnz49Oj09PW1XXM6kJCklPM/DzfFBzOTTcGwTTsVCapYweKsd0g0AMgSNheD5Dghc6Tr7oPHdH/hS8QCUAGwbHR2dfvPAgb1RoSC1IJSU6P3rJobmBkHwIJ0o+kcOYyy1H55tYn6uEbn5F7CG57CQeRahSEQR9O/4skLmASSHhoYqAwMD4yAFITSUyxYKZhRlS8C2BMYmEkinG+CV5jAxuRuzs8/DKCYwldwKEQgwPaDpmh4UfIX8bhDRncu9l5NKBEg6ZYBx1MfjIE+Hb0cxPtEBNzsBJ3sHlWwGjmnCsUpYG0sjWmVQcE2pFK+/WFlJLAGc6+39bcwVAWKeQ6FQCJueSUCQjpxpICTGYZsF2Okk7EwKjrkAv2zBMFpJsR28vnHm1vAXXxv8EW5cHBkZuZjL5STAGOMcTY0JvNhwCFaJYzFvolLIwDEW4Bl3QWYOIV1HbB3jdU3fu7GNvZ8sd95KGK3bWw9t39qckMQQCAZp364mduFXyZJpHYKDtKpqFozFEa5ZR5GaWla3MV+JJrIvX/r4j/GlJvQIzF+40PPzax2vbDZKFrvy+9X02bM//Xj1Su9UaPs7BzZs27u5bl28SgghfMXszHxmPnWu/7g50T3c1X8Y3+4+tfoPEo/H17e1tbWGw+Etw8PDZ2ZmZu4CiIFrL8W37Guoqt8UY4zplcW8n5/sSzm55CCA249t+g8c9xhwADqA0P2W8P+gadpTnnyYgH8B/3BW4MdlF5MAAAAASUVORK5CYII="
/>
</body>
</html>
cloudooo/handler/wkhtmltopdf/tests/data/test_with_script.html
0 → 100644
View file @
7f44ed79
<!DOCTYPE html>
<html>
<head>
<meta
charset=
"utf-8"
/>
<title>
Test Title With Script
</title>
<script>
window
.
addEventListener
(
"
load
"
,
function
()
{
document
.
querySelector
(
"
p
"
).
textContent
=
atob
(
"
V29ybGQ=
"
);
});
</script>
</head>
<body>
<p>
Hello
</p>
</body>
</html>
cloudooo/handler/wkhtmltopdf/tests/data/test_with_toc.html
0 → 100644
View file @
7f44ed79
<!DOCTYPE html>
<html>
<head>
<meta
charset=
"utf-8"
/>
<title>
Test Title With Table of Content
</title>
</head>
<body>
<h1>
Title
</h1>
<p>
Description paragraph
</p>
<h2>
Sub Title
</h2>
<p>
Subject paragraph
</p>
<h2>
Sub Title number 2
</h2>
<p>
Again subject paragraph
</p>
</body>
</html>
cloudooo/handler/wkhtmltopdf/tests/testWkhtmltopdfHandler.py
0 → 100644
View file @
7f44ed79
##############################################################################
#
# Copyright (c) 2016 Nexedi SA and Contributors. All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from
base64
import
b64encode
import
magic
from
cloudooo.handler.wkhtmltopdf.handler
import
Handler
from
cloudooo.tests.handlerTestCase
import
HandlerTestCase
,
make_suite
class
TestHandler
(
HandlerTestCase
):
def
afterSetUp
(
self
):
self
.
kw
=
dict
(
env
=
dict
(
PATH
=
self
.
env_path
))
def
_testBase
(
self
,
html_path
,
**
conversion_kw
):
html_file
=
open
(
html_path
).
read
()
handler
=
Handler
(
self
.
tmp_url
,
html_file
,
"html"
,
**
self
.
kw
)
pdf_file
=
handler
.
convert
(
"pdf"
,
**
conversion_kw
)
mime
=
magic
.
Magic
(
mime
=
True
)
pdf_mimetype
=
mime
.
from_buffer
(
pdf_file
)
self
.
assertEquals
(
"application/pdf"
,
pdf_mimetype
)
def
testConvertHtmlWithPngDataUrlToPdf
(
self
):
"""Test conversion of html with png data url to pdf"""
self
.
_testBase
(
"data/test_with_png_dataurl.html"
)
def
testConvertHtmlWithScriptToPdf
(
self
):
"""Test conversion of html with script to pdf"""
self
.
_testBase
(
"data/test_with_script.html"
)
def
testConvertHtmlWithOpacityStyleToPdf
(
self
):
"""Test conversion of html with opacity style to pdf
Opacity style in a web pages causes Segmentation Fault only if wkhtmltopdf
is not connected to a graphical service like Xorg.
"""
self
.
_testBase
(
"data/test_with_opacity_style.html"
)
# TODO: def testConvertHtmlWithHeaderAndFooter(self):
def
testConvertHtmlWithTableOfContent
(
self
):
"""Test conversion of html with an additional table of content"""
self
.
_testBase
(
"data/test_with_toc.html"
,
toc
=
True
,
xsl_style_sheet_data
=
b64encode
(
open
(
"data/test_toc.xsl"
).
read
()),
)
# XXX how to check for table of content presence ?
def
testsetMetadata
(
self
):
""" Test if metadata are inserted correclty """
handler
=
Handler
(
self
.
tmp_url
,
""
,
"png"
,
**
self
.
kw
)
self
.
assertRaises
(
NotImplementedError
,
handler
.
setMetadata
)
def
test_suite
():
return
make_suite
(
TestHandler
)
cloudooo/handler/wkhtmltopdf/tests/testWkhtmltopdfServer.py
0 → 100644
View file @
7f44ed79
##############################################################################
#
# Copyright (c) 2016 Nexedi SA and Contributors. All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from
os.path
import
join
from
cloudooo.tests.cloudoooTestCase
import
TestCase
,
make_suite
class
TestServer
(
TestCase
):
"""Test XmlRpc Server. Needs cloudooo server started"""
def
ConversionScenarioList
(
self
):
return
[
(
join
(
'data'
,
'test_with_png_dataurl.html'
),
"html"
,
"pdf"
,
"application/pdf"
),
(
join
(
'data'
,
'test_with_script.html'
),
"html"
,
"pdf"
,
"application/pdf"
),
]
def
testConvertHtmltoPdf
(
self
):
"""Converts html to pdf"""
self
.
runConversionList
(
self
.
ConversionScenarioList
())
def
FaultConversionScenarioList
(
self
):
return
[
# Test to verify if server fail when a empty string is sent
(
''
,
''
,
''
),
# Try convert one html for a invalid format
(
open
(
join
(
'data'
,
'test_with_png_dataurl.html'
)).
read
(),
'html'
,
'xyz'
),
]
def
test_suite
():
return
make_suite
(
TestServer
)
cloudooo/handler/x2t/handler.py
View file @
7f44ed79
...
...
@@ -26,16 +26,16 @@
#
##############################################################################
from
xml.etree
import
ElementTree
from
os.path
import
join
,
dirname
,
realpath
from
subprocess
import
Popen
,
PIPE
from
tempfile
import
NamedTemporaryFile
from
tempfile
import
NamedTemporaryFile
,
mktemp
import
sys
import
os
from
zope.interface
import
implements
from
cloudooo.interfaces.handler
import
IHandler
from
cloudooo.file
import
File
from
cloudooo.util
import
logger
from
cloudooo.util
import
logger
,
zipTree
,
unzip
AVS_OFFICESTUDIO_FILE_UNKNOWN
=
"0"
AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCX
=
"65"
...
...
@@ -52,7 +52,7 @@ AVS_OFFICESTUDIO_FILE_CANVAS_PRESENTATION = "8195"
AVS_OFFICESTUDIO_FILE_OTHER_HTMLZIP
=
"2051"
AVS_OFFICESTUDIO_FILE_OTHER_ZIP
=
"2057"
Ext2Formats
=
{
format_code_map
=
{
"docy"
:
AVS_OFFICESTUDIO_FILE_CANVAS_WORD
,
"docx"
:
AVS_OFFICESTUDIO_FILE_DOCUMENT_DOCX
,
"xlsy"
:
AVS_OFFICESTUDIO_FILE_CANVAS_SPREADSHEET
,
...
...
@@ -61,11 +61,6 @@ Ext2Formats = {
"pptx"
:
AVS_OFFICESTUDIO_FILE_PRESENTATION_PPTX
,
}
dir_name
=
dirname
(
realpath
(
sys
.
argv
[
0
]))
#dir_name = join(dirname(realpath(__file__)), 'bin')
converter_bin
=
join
(
dir_name
,
'x2t'
)
converter_lib_dirname
=
join
(
dir_name
,
'lib'
)
yformat_map
=
{
'docy'
:
'docx'
,
'xlsy'
:
'xlsx'
,
...
...
@@ -78,9 +73,13 @@ yformat_service_map = {
'ppty'
:
'com.sun.star.presentation.PresentationDocument'
,
}
yformat_tuple
=
(
"docy"
,
"xlsy"
,
"ppty"
)
class
Handler
(
object
):
"""ImageMagic Handler is used to handler images."""
"""
X2T Handler is used to convert Microsoft Office 2007 documents to OnlyOffice
documents.
"""
implements
(
IHandler
)
...
...
@@ -91,24 +90,46 @@ class Handler(object):
data(string)
The opened and readed file into a string
source_format(string)
The source format of the inputed file"""
The source format of the inputed file
"""
self
.
base_folder_url
=
base_folder_url
self
.
file
=
File
(
base_folder_url
,
data
,
source_format
)
self
.
environment
=
kw
.
get
(
"env"
,
{})
self
.
environment
[
'LD_LIBRARY_PATH'
]
=
converter_lib_dirname
def
convert
(
self
,
destination_format
=
None
,
**
kw
):
""" Convert the inputed file to output as format that were informed """
logger
.
debug
(
"yformat convert x2t: %s > %s"
%
(
self
.
file
.
source_format
,
destination_format
))
in_format
=
Ext2Formats
.
get
(
self
.
file
.
source_format
)
out_format
=
Ext2Formats
.
get
(
destination_format
)
source_format
=
self
.
file
.
source_format
logger
.
debug
(
"x2t convert: %s > %s"
%
(
source_format
,
destination_format
))
# init vars and xml configuration file
in_format
=
format_code_map
[
source_format
]
out_format
=
format_code_map
[
destination_format
]
root_dir
=
self
.
file
.
directory_name
input_dir
=
os
.
path
.
join
(
root_dir
,
"input"
);
output_dir
=
os
.
path
.
join
(
root_dir
,
"output"
);
final_file_name
=
os
.
path
.
join
(
root_dir
,
"document.%s"
%
destination_format
)
input_file_name
=
self
.
file
.
getUrl
()
output_file_name
=
final_file_name
config_file_name
=
os
.
path
.
join
(
root_dir
,
"config.xml"
)
if
source_format
in
yformat_tuple
:
os
.
mkdir
(
input_dir
)
unzip
(
self
.
file
.
getUrl
(),
input_dir
)
for
_
,
_
,
files
in
os
.
walk
(
input_dir
):
input_file_name
,
=
files
break
input_file_name
=
os
.
path
.
join
(
input_dir
,
input_file_name
)
if
destination_format
in
yformat_tuple
:
os
.
mkdir
(
output_dir
)
output_file_name
=
os
.
path
.
join
(
output_dir
,
"body.txt"
)
config_file
=
open
(
config_file_name
,
"w"
)
with
NamedTemporaryFile
(
suffix
=
'.%s'
%
destination_format
,
dir
=
self
.
base_folder_url
)
as
output_file
:
config
=
{
# 'm_sKey': 'from',
'm_sFileFrom'
:
self
.
file
.
getUrl
()
,
'm_sFileFrom'
:
input_file_name
,
'm_nFormatFrom'
:
in_format
,
'm_sFileTo'
:
output_file
.
name
,
'm_sFileTo'
:
output_file_
name
,
'm_nFormatTo'
:
out_format
,
# 'm_bPaid': 'true',
# 'm_bEmbeddedFonts': 'false',
...
...
@@ -116,30 +137,36 @@ class Handler(object):
# 'm_sFontDir': '/usr/share/fonts',
# 'm_sThemeDir': '/var/www/onlyoffice/documentserver/FileConverterService/presentationthemes',
}
with
NamedTemporaryFile
(
suffix
=
".xml"
,
dir
=
self
.
base_folder_url
)
as
temp_xml
:
root
=
ElementTree
.
Element
(
'root'
)
for
key
,
value
in
config
.
items
():
ElementTree
.
SubElement
(
root
,
key
).
text
=
value
ElementTree
.
ElementTree
(
root
).
write
(
temp_xml
,
encoding
=
'utf-8'
,
xml_declaration
=
True
,
default_namespace
=
None
,
method
=
"xml"
)
temp_xml
.
flush
()
p
=
Popen
([
converter_bin
,
temp_xml
.
name
],
env
=
self
.
environment
,
ElementTree
.
ElementTree
(
root
).
write
(
config_file
,
encoding
=
'utf-8'
,
xml_declaration
=
True
,
default_namespace
=
None
,
method
=
"xml"
)
config_file
.
close
()
# run convertion binary
p
=
Popen
(
[
"x2t"
,
config_file
.
name
],
stdout
=
PIPE
,
stderr
=
PIPE
,
close_fds
=
True
,
env
=
self
.
environment
,
)
stdout
,
stderr
=
p
.
communicate
()
with
open
(
output_file
.
name
)
as
output_file1
:
file_content
=
output_file1
.
read
()
return_code_msg
=
"yformat convert x2t return:{}"
.
format
(
p
.
returncode
)
if
p
.
returncode
!=
0
or
not
file_content
:
raise
Exception
(
return_code_msg
+
'
\
n
'
+
stderr
)
logger
.
debug
(
stdout
)
logger
.
debug
(
stderr
)
logger
.
debug
(
"yformat convert x2t return:{}"
.
format
(
p
.
returncode
))
if
p
.
returncode
!=
0
:
raise
RuntimeError
(
"x2t: exit code %d != 0
\
n
+ %s
\
n
> stdout: %s
\
n
> stderr: %s@ x2t xml:
\
n
%s"
%
(
p
.
returncode
,
" "
.
join
([
"x2t"
,
config_file
.
name
]),
stdout
,
stderr
,
" "
+
open
(
config_file
.
name
).
read
().
replace
(
"
\
n
"
,
"
\
n
"
)))
if
destination_format
in
yformat_tuple
:
zipTree
(
final_file_name
,
(
output_file_name
,
""
),
(
os
.
path
.
join
(
os
.
path
.
dirname
(
output_file_name
),
"media"
),
""
),
)
self
.
file
.
reload
(
final_file_name
)
try
:
return
self
.
file
.
getContent
()
finally
:
self
.
file
.
trash
()
return
file_content
def
getMetadata
(
self
,
base_document
=
False
):
"""Returns a dictionary with all metadata of document.
...
...
cloudooo/handler/x2t/tests/data/test.xlsy
View file @
7f44ed79
No preview for this file type
cloudooo/handler/x2t/tests/data/test_with_image.docx
0 → 100644
View file @
7f44ed79
File added
cloudooo/handler/x2t/tests/data/test_with_image.docy
0 → 100644
View file @
7f44ed79
File added
cloudooo/handler/x2t/tests/testX2tHandler.py
0 → 100644
View file @
7f44ed79
##############################################################################
#
# Copyright (c) 2009-2010 Nexedi SA and Contributors. All Rights Reserved.
# Gabriel M. Monnerat <gabriel@tiolive.com>
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
import
magic
import
os.path
from
zipfile
import
ZipFile
from
cStringIO
import
StringIO
from
cloudooo.handler.x2t.handler
import
Handler
from
cloudooo.tests.handlerTestCase
import
HandlerTestCase
,
make_suite
class
TestHandler
(
HandlerTestCase
):
def
afterSetUp
(
self
):
self
.
kw
=
dict
(
env
=
dict
(
PATH
=
self
.
env_path
))
def
testConvertXlsx
(
self
):
"""Test conversion of xlsx to xlsy and back"""
y_data
=
Handler
(
self
.
tmp_url
,
open
(
"data/test.xlsx"
).
read
(),
"xlsx"
,
**
self
.
kw
).
convert
(
"xlsy"
)
y_body_data
=
ZipFile
(
StringIO
(
y_data
)).
open
(
"body.txt"
).
read
()
self
.
assertTrue
(
y_body_data
.
startswith
(
"XLSY;v2;5883;"
),
"%r... does not start with 'XLSY;v2;5883;'"
%
(
y_body_data
[:
20
],))
x_data
=
Handler
(
self
.
tmp_url
,
y_data
,
"xlsy"
,
**
self
.
kw
).
convert
(
"xlsx"
)
# magic inspired by https://github.com/minad/mimemagic/pull/19/files
self
.
assertIn
(
"xl/"
,
x_data
[:
2000
])
def
testConvertXlsy
(
self
):
"""Test conversion of xlsy to xlsx and back"""
x_data
=
Handler
(
self
.
tmp_url
,
open
(
"data/test.xlsy"
).
read
(),
"xlsy"
,
**
self
.
kw
).
convert
(
"xlsx"
)
self
.
assertIn
(
"xl/"
,
x_data
[:
2000
])
y_data
=
Handler
(
self
.
tmp_url
,
x_data
,
"xlsx"
,
**
self
.
kw
).
convert
(
"xlsy"
)
y_body_data
=
ZipFile
(
StringIO
(
y_data
)).
open
(
"body.txt"
).
read
()
self
.
assertTrue
(
y_body_data
.
startswith
(
"XLSY;v2;10579;"
),
"%r... does not start with 'XLSY;v2;10579;'"
%
(
y_body_data
[:
20
],))
def
testConvertDocx
(
self
):
"""Test conversion of docx to docy and back"""
y_data
=
Handler
(
self
.
tmp_url
,
open
(
"data/test_with_image.docx"
).
read
(),
"docx"
,
**
self
.
kw
).
convert
(
"docy"
)
y_zip
=
ZipFile
(
StringIO
(
y_data
))
y_body_data
=
y_zip
.
open
(
"body.txt"
).
read
()
self
.
assertTrue
(
y_body_data
.
startswith
(
"DOCY;v5;2795;"
),
"%r... does not start with 'DOCY;v5;2795;'"
%
(
y_body_data
[:
20
],))
y_zip
.
open
(
"media/image1.png"
)
x_data
=
Handler
(
self
.
tmp_url
,
y_data
,
"docy"
,
**
self
.
kw
).
convert
(
"docx"
)
# magic inspired by https://github.com/minad/mimemagic/pull/19/files
self
.
assertIn
(
"word/"
,
x_data
[:
2000
])
def
testConvertDocy
(
self
):
"""Test conversion of docy to docx and back"""
x_data
=
Handler
(
self
.
tmp_url
,
open
(
"data/test_with_image.docy"
).
read
(),
"docy"
,
**
self
.
kw
).
convert
(
"docx"
)
self
.
assertIn
(
"word/"
,
x_data
[:
2000
])
y_data
=
Handler
(
self
.
tmp_url
,
x_data
,
"docx"
,
**
self
.
kw
).
convert
(
"docy"
)
y_zip
=
ZipFile
(
StringIO
(
y_data
))
y_body_data
=
y_zip
.
open
(
"body.txt"
).
read
()
self
.
assertTrue
(
y_body_data
.
startswith
(
"DOCY;v5;7519;"
),
"%r... does not start with 'DOCY;v5;7519;'"
%
(
y_body_data
[:
20
],))
y_zip
.
open
(
"media/image1.png"
)
def
testgetMetadataFromImage
(
self
):
"""Test getMetadata not implemented form yformats"""
handler
=
Handler
(
self
.
tmp_url
,
""
,
"xlsy"
,
**
self
.
kw
)
self
.
assertRaises
(
NotImplementedError
,
handler
.
getMetadata
)
def
testsetMetadata
(
self
):
"""Test setMetadata not implemented for yformats"""
handler
=
Handler
(
self
.
tmp_url
,
""
,
"xlsy"
,
**
self
.
kw
)
self
.
assertRaises
(
NotImplementedError
,
handler
.
setMetadata
)
def
test_suite
():
return
make_suite
(
TestHandler
)
cloudooo/handler/x2t/tests/testX2tServer.py
0 → 100644
View file @
7f44ed79
##############################################################################
#
# Copyright (c) 2016 Nexedi SA and Contributors. All Rights Reserved.
#
# WARNING: This program as such is intended to be used by professional
# programmers who take the whole responsibility of assessing all potential
# consequences resulting from its eventual inadequacies and bugs
# End users who are looking for a ready-to-use solution with commercial
# guarantees and support are strongly adviced to contract a Free Software
# Service Company
#
# This program is Free Software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
##############################################################################
from
os.path
import
join
from
cloudooo.tests.cloudoooTestCase
import
TestCase
,
make_suite
class
TestServer
(
TestCase
):
"""Test XmlRpc Server. Needs cloudooo server started"""
def
ConversionScenarioList
(
self
):
return
[
(
join
(
'data'
,
'test.xlsx'
),
"xlsx"
,
"xlsy"
,
"application/zip"
),
(
join
(
'data'
,
'test.xlsy'
),
"xlsy"
,
"xlsx"
,
"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
),
(
join
(
'data'
,
'test_with_image.docx'
),
"docx"
,
"docy"
,
"application/zip"
),
# Here, the content type should be application/vnd.openxmlformats-officedocument.wordprocessingml.document
# but "magic" seems to not detect it correctly. However, the document can be read correctly by LibreOffice.
(
join
(
'data'
,
'test_with_image.docy'
),
"docy"
,
"docx"
,
"application/octet-stream"
),
]
def
testConvertHtmltoPdf
(
self
):
"""Converts xlsx,docx to their y format and y to x"""
self
.
runConversionList
(
self
.
ConversionScenarioList
())
def
FaultConversionScenarioList
(
self
):
return
[
# Test to verify if server fail when a empty string is sent
(
''
,
''
,
''
),
# Try convert one xlsx for a invalid format
(
open
(
join
(
'data'
,
'test.xlsx'
)).
read
(),
'xlsx'
,
'xyz'
),
]
def
test_suite
():
return
make_suite
(
TestServer
)
cloudooo/manager.py
View file @
7f44ed79
...
...
@@ -73,7 +73,7 @@ class Manager(object):
self
.
handler_dict
=
self
.
kw
.
pop
(
"handler_dict"
)
def
convertFile
(
self
,
file
,
source_format
,
destination_format
,
zip
=
False
,
refresh
=
False
):
refresh
=
False
,
conversion_kw
=
{}
):
"""Returns the converted file in the given format.
Keywords arguments:
file -- File as string in base64
...
...
@@ -92,7 +92,7 @@ class Manager(object):
decodestring
(
file
),
source_format
,
**
self
.
kw
)
decode_data
=
handler
.
convert
(
destination_format
)
decode_data
=
handler
.
convert
(
destination_format
,
**
conversion_kw
)
return
encodestring
(
decode_data
)
def
updateFileMetadata
(
self
,
file
,
source_format
,
metadata_dict
):
...
...
cloudooo/mime.types
View file @
7f44ed79
...
...
@@ -56,6 +56,7 @@ application/vnd.oasis.opendocument.database
application/vnd.oasis.opendocument.image odi
application/vnd.ms-word.document.macroEnabled.12 docm
application/vnd.openxmlformats-officedocument.wordprocessingml.document docx
application/x-asc-text docy
application/vnd.openxmlformats-officedocument.wordprocessingml.template dotx
application/vnd.ms-powerpoint.template.macroEnabled.12 potm
application/vnd.openxmlformats-officedocument.presentationml.template potx
...
...
@@ -64,10 +65,12 @@ application/vnd.ms-powerpoint.slideshow.macroEnabled.12
application/vnd.openxmlformats-officedocument.presentationml.slideshow ppsx
application/vnd.ms-powerpoint.presentation.macroEnabled.12 pptm
application/vnd.openxmlformats-officedocument.presentationml.presentation pptx
application/x-asc-presentation ppty
application/vnd.ms-excel.addin.macroEnabled.12 xlam
application/vnd.ms-excel.sheet.binary.macroEnabled.12 xlsb
application/vnd.ms-excel.sheet.macroEnabled.12 xlsm
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet xlsx
application/x-asc-spreadsheet xlsy
application/vnd.ms-excel.template.macroEnabled.12 xltm
application/vnd.openxmlformats-officedocument.spreadsheetml.template xltx
application/x-msmetafile wmf
...
...
cloudooo/util.py
View file @
7f44ed79
...
...
@@ -29,6 +29,8 @@
import
logging
import
mimetypes
import
pkg_resources
import
os
from
zipfile
import
ZipFile
,
ZIP_DEFLATED
logger
=
logging
.
getLogger
(
'Cloudooo'
)
...
...
@@ -98,3 +100,36 @@ def convertStringToBool(string):
return
False
else
:
return
None
def
zipTree
(
destination
,
*
tree_path_list
):
"""
destination may be a path or a StringIO
tree_path_list is a list that may contain a path or a couple(path, archive_root)
"""
def
archive
(
arg
,
archive_root
):
archive_name
=
os
.
path
.
join
(
archive_root
,
os
.
path
.
basename
(
arg
))
if
os
.
path
.
islink
(
arg
):
pass
# XXX logger.warn("zipTree: symlink %r ignored\n" % arg)
elif
os
.
path
.
isdir
(
arg
):
for
r
,
_
,
ff
in
os
.
walk
(
arg
):
zfile
.
write
(
r
,
archive_name
)
for
f
in
ff
:
archive
(
os
.
path
.
join
(
r
,
f
),
archive_name
)
elif
os
.
path
.
isfile
(
arg
):
zfile
.
write
(
arg
,
archive_name
)
else
:
pass
# XXX logger.warn("zipTree: unknown %r ignored\n" % arg)
zfile
=
ZipFile
(
destination
,
"w"
,
ZIP_DEFLATED
)
for
tree_path
in
tree_path_list
:
if
isinstance
(
tree_path
,
tuple
):
archive
(
*
tree_path
)
else
:
archive
(
tree_path
,
os
.
path
.
dirname
(
tree_path
))
zfile
.
close
()
return
destination
def
unzip
(
source
,
destination
):
zipfile
=
ZipFile
(
source
)
zipfile
.
extractall
(
destination
)
zipfile
.
close
()
setup.py
View file @
7f44ed79
...
...
@@ -6,7 +6,7 @@ version = '1.2.5-dev'
def
read
(
name
):
return
open
(
name
).
read
()
long_description
=
(
read
(
'README.
txt'
)
+
'
\
n
'
+
read
(
'CHANGES.tx
t'
))
long_description
=
(
read
(
'README.
rst'
)
+
'
\
n
'
+
read
(
'CHANGELOG.rs
t'
))
install_requires
=
[
# -*- Extra requirements: -*-
...
...
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