Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
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
1
Merge Requests
1
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
Jérome Perrin
cloudooo
Commits
a0c98aa8
Commit
a0c98aa8
authored
Apr 30, 2021
by
Jérome Perrin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
debugging prints
parent
9956a05f
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
55 additions
and
9 deletions
+55
-9
cloudooo/file.py
cloudooo/file.py
+2
-0
cloudooo/handler/ooo/application/openoffice.py
cloudooo/handler/ooo/application/openoffice.py
+6
-0
cloudooo/handler/ooo/helper/unoconverter.py
cloudooo/handler/ooo/helper/unoconverter.py
+45
-8
cloudooo/handler/ooo/mimemapper.py
cloudooo/handler/ooo/mimemapper.py
+2
-1
No files found.
cloudooo/file.py
View file @
a0c98aa8
...
@@ -70,6 +70,7 @@ class File(object):
...
@@ -70,6 +70,7 @@ class File(object):
# stores the data in temporary file
# stores the data in temporary file
with
open
(
file_path
,
'wb'
)
as
f
:
with
open
(
file_path
,
'wb'
)
as
f
:
f
.
write
(
self
.
original_data
)
f
.
write
(
self
.
original_data
)
print
(
'wrote'
,
file_path
,
self
.
original_data
)
# If is a zipfile is need extract all files from whitin the compressed file
# If is a zipfile is need extract all files from whitin the compressed file
if
is_zipfile
(
file_path
):
if
is_zipfile
(
file_path
):
zipfile
=
ZipFile
(
file_path
)
zipfile
=
ZipFile
(
file_path
)
...
@@ -117,6 +118,7 @@ class File(object):
...
@@ -117,6 +118,7 @@ class File(object):
else
:
else
:
with
open
(
self
.
url
,
'rb'
)
as
f
:
with
open
(
self
.
url
,
'rb'
)
as
f
:
content
=
f
.
read
()
content
=
f
.
read
()
print
(
'getContent'
,
content
)
return
content
return
content
def
getUrl
(
self
):
def
getUrl
(
self
):
...
...
cloudooo/handler/ooo/application/openoffice.py
View file @
a0c98aa8
...
@@ -108,6 +108,7 @@ class OpenOffice(Application):
...
@@ -108,6 +108,7 @@ class OpenOffice(Application):
for
i
in
range
(
5
):
for
i
in
range
(
5
):
self
.
stop
()
self
.
stop
()
waitStopDaemon
(
self
,
self
.
timeout
)
waitStopDaemon
(
self
,
self
.
timeout
)
print
' '
.
join
(
command
)
self
.
process
=
Popen
(
command
,
self
.
process
=
Popen
(
command
,
close_fds
=
True
,
close_fds
=
True
,
env
=
env
)
env
=
env
)
...
@@ -156,6 +157,11 @@ class OpenOffice(Application):
...
@@ -156,6 +157,11 @@ class OpenOffice(Application):
env
[
"HOME"
]
=
self
.
path_user_installation
env
[
"HOME"
]
=
self
.
path_user_installation
env
[
"TMP"
]
=
self
.
path_user_installation
env
[
"TMP"
]
=
self
.
path_user_installation
env
[
"TMPDIR"
]
=
self
.
path_user_installation
env
[
"TMPDIR"
]
=
self
.
path_user_installation
from
pprint
import
pprint
pprint
((
'setting env'
,
env
))
import
subprocess
for
cmd
in
(
'locale'
,
'locale -a'
,
'locale charmap'
):
print
"output of"
,
cmd
,
'
\
n
'
,
subprocess
.
check_output
(
cmd
,
shell
=
True
,
env
=
env
)
self
.
_startProcess
(
self
.
command
,
env
)
self
.
_startProcess
(
self
.
command
,
env
)
self
.
_cleanRequest
()
self
.
_cleanRequest
()
Application
.
start
(
self
)
Application
.
start
(
self
)
...
...
cloudooo/handler/ooo/helper/unoconverter.py
View file @
a0c98aa8
...
@@ -73,6 +73,13 @@ Options:
...
@@ -73,6 +73,13 @@ Options:
Dictionary with metadata
Dictionary with metadata
"""
"""
import
logging
logging
.
basicConfig
(
level
=
logging
.
DEBUG
,
filename
=
'/tmp/cloudooo.log'
)
logger
=
logging
.
getLogger
()
class
UnoConverter
(
object
):
class
UnoConverter
(
object
):
"""A module to easily work with OpenOffice.org."""
"""A module to easily work with OpenOffice.org."""
...
@@ -89,6 +96,8 @@ class UnoConverter(object):
...
@@ -89,6 +96,8 @@ class UnoConverter(object):
self
.
uno_path
=
uno_path
self
.
uno_path
=
uno_path
self
.
office_binary_path
=
office_binary_path
self
.
office_binary_path
=
office_binary_path
self
.
_load
()
self
.
_load
()
logger
.
info
(
"__init__ finished"
)
def
_createProperty
(
self
,
name
,
value
):
def
_createProperty
(
self
,
name
,
value
):
"""Create property"""
"""Create property"""
...
@@ -100,34 +109,46 @@ class UnoConverter(object):
...
@@ -100,34 +109,46 @@ class UnoConverter(object):
def
_createSpecificProperty
(
self
,
filter_name
):
def
_createSpecificProperty
(
self
,
filter_name
):
"""Creates a property according to the filter"""
"""Creates a property according to the filter"""
logger
.
info
(
'_createSpecificProperty %s'
,
filter_name
)
import
uno
import
uno
from
com.sun.star.beans
import
PropertyValue
from
com.sun.star.beans
import
PropertyValue
if
filter_name
==
"impress_html_Export"
:
if
filter_name
==
"impress_html_Export"
:
prop
erty
=
PropertyValue
(
'FilterData'
,
0
,
prop
=
PropertyValue
(
'FilterData'
,
0
,
uno
.
Any
(
'[]com.sun.star.beans.PropertyValue'
,
uno
.
Any
(
'[]com.sun.star.beans.PropertyValue'
,
(
PropertyValue
(
'IsExportNotes'
,
0
,
True
,
0
),
(
PropertyValue
(
'IsExportNotes'
,
0
,
True
,
0
),
PropertyValue
(
'PublishMode'
,
0
,
0
,
0
),
PropertyValue
(
'PublishMode'
,
0
,
0
,
0
),
PropertyValue
(
'Width'
,
0
,
640
,
0
),
PropertyValue
(
'Width'
,
0
,
640
,
0
),
PropertyValue
(
'Format'
,
0
,
2
,
0
),),),
0
)
PropertyValue
(
'Format'
,
0
,
2
,
0
),),),
0
)
elif
filter_name
==
"impress_pdf_Export"
:
elif
filter_name
==
"impress_pdf_Export"
:
prop
erty
=
PropertyValue
(
'FilterData'
,
0
,
prop
=
PropertyValue
(
'FilterData'
,
0
,
uno
.
Any
(
'[]com.sun.star.beans.PropertyValue'
,
uno
.
Any
(
'[]com.sun.star.beans.PropertyValue'
,
(
PropertyValue
(
'ExportNotesPages'
,
0
,
True
,
0
),
(
PropertyValue
(
'ExportNotesPages'
,
0
,
True
,
0
),
PropertyValue
(
'SelectPdfVersion'
,
0
,
1
,
0
),),),
0
)
PropertyValue
(
'SelectPdfVersion'
,
0
,
1
,
0
),),),
0
)
elif
"pdf_Export"
in
filter_name
:
elif
"pdf_Export"
in
filter_name
:
prop
erty
=
PropertyValue
(
'FilterData'
,
0
,
prop
=
PropertyValue
(
'FilterData'
,
0
,
uno
.
Any
(
'[]com.sun.star.beans.PropertyValue'
,
uno
.
Any
(
'[]com.sun.star.beans.PropertyValue'
,
(
PropertyValue
(
'SelectPdfVersion'
,
0
,
1
,
0
),),),
0
)
(
PropertyValue
(
'SelectPdfVersion'
,
0
,
1
,
0
),),),
0
)
elif
filter_name
in
(
"draw_html_Export"
,
"HTML (StarCalc)"
):
elif
filter_name
in
(
"draw_html_Export"
,
"HTML (StarCalc)"
):
prop
erty
=
PropertyValue
(
'FilterData'
,
0
,
prop
=
PropertyValue
(
'FilterData'
,
0
,
uno
.
Any
(
'[]com.sun.star.beans.PropertyValue'
,
uno
.
Any
(
'[]com.sun.star.beans.PropertyValue'
,
(
PropertyValue
(
'Format'
,
0
,
2
,
0
),),),
0
)
(
PropertyValue
(
'Format'
,
0
,
2
,
0
),),),
0
)
elif
filter_name
==
"Text (encoded)"
:
elif
filter_name
in
(
"Text (encoded)"
,
"Text (encoded) (StarWriter/Web)"
):
property
=
PropertyValue
(
'FilterFlags'
,
0
,
'UTF8,LF'
,
0
)
return
[
self
.
_createProperty
(
'FilterOptions'
,
'UTF8,LF'
)]
return
[
PropertyValue
(
'FilterOptions'
,
0
,
'UTF8,LF,'
,
0
),
PropertyValue
(
'FilterData'
,
0
,
uno
.
Any
(
'[]com.sun.star.beans.PropertyValue'
,
(
PropertyValue
(
'crlf'
,
0
,
'lf'
,
0
),
PropertyValue
(
'language'
,
0
,
'en'
,
0
),
PropertyValue
(
'includebom'
,
0
,
False
,
0
),
),),
0
),
]
else
:
else
:
return
[]
return
[]
return
[
prop
erty
,
]
return
[
prop
,
]
def
_getFilterName
(
self
,
destination_format
,
type
):
def
_getFilterName
(
self
,
destination_format
,
type
):
for
filter_tuple
in
mimemapper
[
"filter_list"
]:
for
filter_tuple
in
mimemapper
[
"filter_list"
]:
...
@@ -143,6 +164,7 @@ class UnoConverter(object):
...
@@ -143,6 +164,7 @@ class UnoConverter(object):
self
.
_createProperty
(
"Overwrite"
,
True
),
self
.
_createProperty
(
"Overwrite"
,
True
),
self
.
_createProperty
(
"FilterName"
,
filter_name
),
self
.
_createProperty
(
"FilterName"
,
filter_name
),
]
+
self
.
_createSpecificProperty
(
filter_name
)
]
+
self
.
_createSpecificProperty
(
filter_name
)
logger
.
debug
(
"ahaha _getPropertyToExport %s => %s"
,
destination_format
,
property_list
)
return
property_list
return
property_list
def
_getPropertyToImport
(
self
,
source_url
):
def
_getPropertyToImport
(
self
,
source_url
):
...
@@ -162,7 +184,13 @@ class UnoConverter(object):
...
@@ -162,7 +184,13 @@ class UnoConverter(object):
return
(
return
(
self
.
_createProperty
(
"FilterName"
,
"Text - txt - csv (StarCalc)"
),
self
.
_createProperty
(
"FilterName"
,
"Text - txt - csv (StarCalc)"
),
self
.
_createProperty
(
"FilterOptions"
,
"{delimiter},34,UTF-8"
.
format
(
**
locals
())),
)
self
.
_createProperty
(
"FilterOptions"
,
"{delimiter},34,UTF-8"
.
format
(
**
locals
())),
)
return
()
return
(
self
.
_createProperty
(
'Hidden'
,
True
),
self
.
_createProperty
(
'ReadOnly'
,
True
),
self
.
_createProperty
(
'UpdateDocMode'
,
0
),
)
return
()
return
()
def
_load
(
self
):
def
_load
(
self
):
...
@@ -175,6 +203,7 @@ class UnoConverter(object):
...
@@ -175,6 +203,7 @@ class UnoConverter(object):
self
.
office_binary_path
)
self
.
office_binary_path
)
desktop
=
service_manager
.
createInstance
(
"com.sun.star.frame.Desktop"
)
desktop
=
service_manager
.
createInstance
(
"com.sun.star.frame.Desktop"
)
uno_url
=
self
.
systemPathToFileUrl
(
self
.
document_url
)
uno_url
=
self
.
systemPathToFileUrl
(
self
.
document_url
)
logger
.
info
(
'load %s'
,
uno_url
)
uno_document
=
desktop
.
loadComponentFromURL
(
uno_document
=
desktop
.
loadComponentFromURL
(
uno_url
,
uno_url
,
"_blank"
,
"_blank"
,
...
@@ -182,6 +211,11 @@ class UnoConverter(object):
...
@@ -182,6 +211,11 @@ class UnoConverter(object):
self
.
_getPropertyToImport
(
self
.
document_url
))
self
.
_getPropertyToImport
(
self
.
document_url
))
if
not
uno_document
:
if
not
uno_document
:
raise
AttributeError
(
"This document can not be loaded or is empty"
)
raise
AttributeError
(
"This document can not be loaded or is empty"
)
text
=
uno_document
.
Text
#logger.info('text %s', repr(text))
logger
.
info
(
'text getString %s'
,
text
.
getString
())
logger
.
info
(
'text getString type %s'
,
type
(
text
.
getString
()))
if
self
.
refresh
:
if
self
.
refresh
:
# Before converting to expected format, refresh dynamic
# Before converting to expected format, refresh dynamic
# value inside document.
# value inside document.
...
@@ -205,10 +239,13 @@ class UnoConverter(object):
...
@@ -205,10 +239,13 @@ class UnoConverter(object):
destination_format
=
"impr.html"
destination_format
=
"impr.html"
else
:
else
:
destination_format
=
output_format
destination_format
=
output_format
logger
.
info
(
'convert to format %s (%s)'
,
output_format
,
destination_format
)
output_url
=
mktemp
(
suffix
=
'.%s'
%
destination_format
,
output_url
=
mktemp
(
suffix
=
'.%s'
%
destination_format
,
dir
=
self
.
document_dir_path
)
dir
=
self
.
document_dir_path
)
logger
.
info
(
'output_url: %s'
,
output_url
)
property_list
=
self
.
_getPropertyToExport
(
output_format
)
property_list
=
self
.
_getPropertyToExport
(
output_format
)
logger
.
info
(
'property_list: %s'
,
property_list
)
try
:
try
:
self
.
document_loaded
.
storeToURL
(
self
.
systemPathToFileUrl
(
output_url
),
self
.
document_loaded
.
storeToURL
(
self
.
systemPathToFileUrl
(
output_url
),
tuple
(
property_list
))
tuple
(
property_list
))
...
...
cloudooo/handler/ooo/mimemapper.py
View file @
a0c98aa8
...
@@ -125,12 +125,12 @@ class MimeMapper(object):
...
@@ -125,12 +125,12 @@ class MimeMapper(object):
"--office_binary_path=%s"
%
office_binary_path
,
"--office_binary_path=%s"
%
office_binary_path
,
"--hostname=%s"
%
hostname
,
"--hostname=%s"
%
hostname
,
"--port=%s"
%
port
]
"--port=%s"
%
port
]
print
(
'executing'
,
command
,
kw
.
get
(
'env'
),
list
(
kw
.
keys
()))
filter_dict
,
type_dict
=
json
.
loads
(
filter_dict
,
type_dict
=
json
.
loads
(
subprocess
.
check_output
(
subprocess
.
check_output
(
command
,
command
,
env
=
dict
(
os
.
environ
,
**
environment_dict
),
env
=
dict
(
os
.
environ
,
**
environment_dict
),
close_fds
=
True
))
close_fds
=
True
))
ooo_disable_filter_list
=
kw
.
get
(
"ooo_disable_filter_list"
)
or
[]
+
[
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_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
# 'writer_png_Export', # Seems not working from cloudooo in Libre Office 4.3.3.2
...
@@ -147,6 +147,7 @@ class MimeMapper(object):
...
@@ -147,6 +147,7 @@ class MimeMapper(object):
ui_name
=
value
.
get
(
'UIName'
)
ui_name
=
value
.
get
(
'UIName'
)
filter_type
=
value
.
get
(
'Type'
)
filter_type
=
value
.
get
(
'Type'
)
filter_type_dict
=
type_dict
.
get
(
filter_type
)
filter_type_dict
=
type_dict
.
get
(
filter_type
)
#print(filter_type, filter_type_dict)
if
filter_type_dict
is
None
:
if
filter_type_dict
is
None
:
continue
continue
if
not
ui_name
:
if
not
ui_name
:
...
...
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