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
Show 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):
# stores the data in temporary file
with
open
(
file_path
,
'wb'
)
as
f
:
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_zipfile
(
file_path
):
zipfile
=
ZipFile
(
file_path
)
...
...
@@ -117,6 +118,7 @@ class File(object):
else
:
with
open
(
self
.
url
,
'rb'
)
as
f
:
content
=
f
.
read
()
print
(
'getContent'
,
content
)
return
content
def
getUrl
(
self
):
...
...
cloudooo/handler/ooo/application/openoffice.py
View file @
a0c98aa8
...
...
@@ -108,6 +108,7 @@ class OpenOffice(Application):
for
i
in
range
(
5
):
self
.
stop
()
waitStopDaemon
(
self
,
self
.
timeout
)
print
' '
.
join
(
command
)
self
.
process
=
Popen
(
command
,
close_fds
=
True
,
env
=
env
)
...
...
@@ -156,6 +157,11 @@ class OpenOffice(Application):
env
[
"HOME"
]
=
self
.
path_user_installation
env
[
"TMP"
]
=
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
.
_cleanRequest
()
Application
.
start
(
self
)
...
...
cloudooo/handler/ooo/helper/unoconverter.py
View file @
a0c98aa8
...
...
@@ -73,6 +73,13 @@ Options:
Dictionary with metadata
"""
import
logging
logging
.
basicConfig
(
level
=
logging
.
DEBUG
,
filename
=
'/tmp/cloudooo.log'
)
logger
=
logging
.
getLogger
()
class
UnoConverter
(
object
):
"""A module to easily work with OpenOffice.org."""
...
...
@@ -89,6 +96,8 @@ class UnoConverter(object):
self
.
uno_path
=
uno_path
self
.
office_binary_path
=
office_binary_path
self
.
_load
()
logger
.
info
(
"__init__ finished"
)
def
_createProperty
(
self
,
name
,
value
):
"""Create property"""
...
...
@@ -100,34 +109,46 @@ class UnoConverter(object):
def
_createSpecificProperty
(
self
,
filter_name
):
"""Creates a property according to the filter"""
logger
.
info
(
'_createSpecificProperty %s'
,
filter_name
)
import
uno
from
com.sun.star.beans
import
PropertyValue
if
filter_name
==
"impress_html_Export"
:
prop
erty
=
PropertyValue
(
'FilterData'
,
0
,
prop
=
PropertyValue
(
'FilterData'
,
0
,
uno
.
Any
(
'[]com.sun.star.beans.PropertyValue'
,
(
PropertyValue
(
'IsExportNotes'
,
0
,
True
,
0
),
PropertyValue
(
'PublishMode'
,
0
,
0
,
0
),
PropertyValue
(
'Width'
,
0
,
640
,
0
),
PropertyValue
(
'Format'
,
0
,
2
,
0
),),),
0
)
elif
filter_name
==
"impress_pdf_Export"
:
prop
erty
=
PropertyValue
(
'FilterData'
,
0
,
prop
=
PropertyValue
(
'FilterData'
,
0
,
uno
.
Any
(
'[]com.sun.star.beans.PropertyValue'
,
(
PropertyValue
(
'ExportNotesPages'
,
0
,
True
,
0
),
PropertyValue
(
'SelectPdfVersion'
,
0
,
1
,
0
),),),
0
)
elif
"pdf_Export"
in
filter_name
:
prop
erty
=
PropertyValue
(
'FilterData'
,
0
,
prop
=
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)"
):
prop
erty
=
PropertyValue
(
'FilterData'
,
0
,
prop
=
PropertyValue
(
'FilterData'
,
0
,
uno
.
Any
(
'[]com.sun.star.beans.PropertyValue'
,
(
PropertyValue
(
'Format'
,
0
,
2
,
0
),),),
0
)
elif
filter_name
==
"Text (encoded)"
:
property
=
PropertyValue
(
'FilterFlags'
,
0
,
'UTF8,LF'
,
0
)
elif
filter_name
in
(
"Text (encoded)"
,
"Text (encoded) (StarWriter/Web)"
):
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
:
return
[]
return
[
prop
erty
,
]
return
[
prop
,
]
def
_getFilterName
(
self
,
destination_format
,
type
):
for
filter_tuple
in
mimemapper
[
"filter_list"
]:
...
...
@@ -143,6 +164,7 @@ class UnoConverter(object):
self
.
_createProperty
(
"Overwrite"
,
True
),
self
.
_createProperty
(
"FilterName"
,
filter_name
),
]
+
self
.
_createSpecificProperty
(
filter_name
)
logger
.
debug
(
"ahaha _getPropertyToExport %s => %s"
,
destination_format
,
property_list
)
return
property_list
def
_getPropertyToImport
(
self
,
source_url
):
...
...
@@ -164,6 +186,12 @@ class UnoConverter(object):
self
.
_createProperty
(
"FilterOptions"
,
"{delimiter},34,UTF-8"
.
format
(
**
locals
())),
)
return
()
return
(
self
.
_createProperty
(
'Hidden'
,
True
),
self
.
_createProperty
(
'ReadOnly'
,
True
),
self
.
_createProperty
(
'UpdateDocMode'
,
0
),
)
return
()
def
_load
(
self
):
"""Create one document with basic properties
...
...
@@ -175,6 +203,7 @@ class UnoConverter(object):
self
.
office_binary_path
)
desktop
=
service_manager
.
createInstance
(
"com.sun.star.frame.Desktop"
)
uno_url
=
self
.
systemPathToFileUrl
(
self
.
document_url
)
logger
.
info
(
'load %s'
,
uno_url
)
uno_document
=
desktop
.
loadComponentFromURL
(
uno_url
,
"_blank"
,
...
...
@@ -182,6 +211,11 @@ class UnoConverter(object):
self
.
_getPropertyToImport
(
self
.
document_url
))
if
not
uno_document
:
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
:
# Before converting to expected format, refresh dynamic
# value inside document.
...
...
@@ -205,10 +239,13 @@ class UnoConverter(object):
destination_format
=
"impr.html"
else
:
destination_format
=
output_format
logger
.
info
(
'convert to format %s (%s)'
,
output_format
,
destination_format
)
output_url
=
mktemp
(
suffix
=
'.%s'
%
destination_format
,
dir
=
self
.
document_dir_path
)
logger
.
info
(
'output_url: %s'
,
output_url
)
property_list
=
self
.
_getPropertyToExport
(
output_format
)
logger
.
info
(
'property_list: %s'
,
property_list
)
try
:
self
.
document_loaded
.
storeToURL
(
self
.
systemPathToFileUrl
(
output_url
),
tuple
(
property_list
))
...
...
cloudooo/handler/ooo/mimemapper.py
View file @
a0c98aa8
...
...
@@ -125,12 +125,12 @@ class MimeMapper(object):
"--office_binary_path=%s"
%
office_binary_path
,
"--hostname=%s"
%
hostname
,
"--port=%s"
%
port
]
print
(
'executing'
,
command
,
kw
.
get
(
'env'
),
list
(
kw
.
keys
()))
filter_dict
,
type_dict
=
json
.
loads
(
subprocess
.
check_output
(
command
,
env
=
dict
(
os
.
environ
,
**
environment_dict
),
close_fds
=
True
))
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
...
...
@@ -147,6 +147,7 @@ class MimeMapper(object):
ui_name
=
value
.
get
(
'UIName'
)
filter_type
=
value
.
get
(
'Type'
)
filter_type_dict
=
type_dict
.
get
(
filter_type
)
#print(filter_type, filter_type_dict)
if
filter_type_dict
is
None
:
continue
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