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
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
Roque
cloudooo
Commits
115e6f1b
Commit
115e6f1b
authored
Oct 25, 2011
by
Nicolas Delaby
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
factorise _setUpUnoEnvironment function
parent
5e41f4c1
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
40 additions
and
62 deletions
+40
-62
cloudooo/handler/ooo/helper/helper_util.py
cloudooo/handler/ooo/helper/helper_util.py
+13
-2
cloudooo/handler/ooo/helper/openoffice_tester.py
cloudooo/handler/ooo/helper/openoffice_tester.py
+7
-3
cloudooo/handler/ooo/helper/unoconverter.py
cloudooo/handler/ooo/helper/unoconverter.py
+12
-28
cloudooo/handler/ooo/helper/unomimemapper.py
cloudooo/handler/ooo/helper/unomimemapper.py
+8
-29
No files found.
cloudooo/handler/ooo/helper/helper_util.py
View file @
115e6f1b
def
getServiceManager
(
host
,
port
):
"""Get the ServiceManager from the running OpenOffice.org."""
import
sys
import
os
def
getServiceManager
(
host
,
port
,
uno_path
,
office_binary_path
):
"""Get the ServiceManager from the running OpenOffice.org.
"""
# Add in sys.path the path of pyuno
if
uno_path
not
in
sys
.
path
:
sys
.
path
.
append
(
uno_path
)
fundamentalrc_file
=
'%s/fundamentalrc'
%
office_binary_path
if
os
.
path
.
exists
(
fundamentalrc_file
)
and
\
'URE_BOOTSTRAP'
not
in
os
.
environ
:
os
.
putenv
(
'URE_BOOTSTRAP'
,
'vnd.sun.star.pathname:%s'
%
fundamentalrc_file
)
import
uno
# Get the uno component context from the PyUNO runtime
uno_context
=
uno
.
getComponentContext
()
...
...
cloudooo/handler/ooo/helper/openoffice_tester.py
View file @
115e6f1b
...
...
@@ -17,20 +17,24 @@ def test_openoffice(hostname, port):
def
main
():
try
:
opt_list
,
arg_list
=
getopt
(
sys
.
argv
[
1
:],
""
,
[
"port="
,
"hostname="
,
"uno_path="
])
[
"port="
,
"hostname="
,
"uno_path="
,
"office_binary_path="
])
except
GetoptError
,
e
:
print
>>
sys
.
stderr
,
"%s
\
n
Use --port and --hostname"
%
e
sys
.
exit
(
2
)
port
=
hostname
=
uno_path
=
office_binary_path
=
None
for
opt
,
arg
in
opt_list
:
if
opt
==
"--port"
:
port
=
arg
elif
opt
==
"--hostname"
:
hostname
=
arg
elif
opt
==
"--uno_path"
:
environ
[
"uno_path"
]
=
arg
uno_path
=
arg
elif
opt
==
"--office_binary_path"
:
office_binary_path
=
arg
print
test_openoffice
(
hostname
,
port
)
print
test_openoffice
(
hostname
,
port
,
uno_path
,
office_binary_path
)
if
__name__
==
"__main__"
:
...
...
cloudooo/handler/ooo/helper/unoconverter.py
View file @
115e6f1b
...
...
@@ -70,39 +70,19 @@ Options:
class
UnoConverter
(
object
):
"""A module to easily work with OpenOffice.org."""
def
__init__
(
self
,
hostname
,
port
,
document_url
,
**
kw
):
def
__init__
(
self
,
hostname
,
port
,
document_url
,
source_format
,
uno_path
,
office_binary_path
,
refresh
=
None
,):
""" """
self
.
hostname
=
hostname
self
.
port
=
port
self
.
document_url
=
document_url
self
.
document_dir_path
=
dirname
(
document_url
)
self
.
source_format
=
kw
.
get
(
'source_format'
)
self
.
refresh
=
kw
.
get
(
'refresh'
)
self
.
_setUpUnoEnvironment
(
kw
.
get
(
"uno_path"
),
kw
.
get
(
"office_binary_path"
))
self
.
source_format
=
source_format
self
.
refresh
=
refresh
self
.
uno_path
=
uno_path
self
.
office_binary_path
=
office_binary_path
self
.
_load
()
def
_setUpUnoEnvironment
(
self
,
uno_path
=
None
,
office_binary_path
=
None
):
"""Set up the environment to use the uno library and connect with the
openoffice by socket"""
if
uno_path
is
not
None
:
environ
[
'uno_path'
]
=
uno_path
else
:
uno_path
=
environ
.
get
(
'uno_path'
)
if
office_binary_path
is
not
None
:
environ
[
'office_binary_path'
]
=
office_binary_path
else
:
office_binary_path
=
environ
.
get
(
'office_binary_path'
)
# Add in sys.path the path of pyuno
if
uno_path
not
in
sys
.
path
:
sys
.
path
.
append
(
uno_path
)
fundamentalrc_file
=
'%s/fundamentalrc'
%
office_binary_path
if
exists
(
fundamentalrc_file
)
and
\
'URE_BOOTSTRAP'
not
in
environ
:
putenv
(
'URE_BOOTSTRAP'
,
'vnd.sun.star.pathname:%s'
%
fundamentalrc_file
)
def
_createProperty
(
self
,
name
,
value
):
"""Create property"""
from
com.sun.star.beans
import
PropertyValue
...
...
@@ -159,7 +139,9 @@ class UnoConverter(object):
refresh argument tells to uno environment to
replace dynamic properties of document before conversion
"""
service_manager
=
helper_util
.
getServiceManager
(
self
.
hostname
,
self
.
port
)
service_manager
=
helper_util
.
getServiceManager
(
self
.
hostname
,
self
.
port
,
self
.
uno_path
,
self
.
office_binary_path
)
desktop
=
service_manager
.
createInstance
(
"com.sun.star.frame.Desktop"
)
uno_url
=
self
.
systemPathToFileUrl
(
self
.
document_url
)
uno_document
=
desktop
.
loadComponentFromURL
(
uno_url
,
"_blank"
,
0
,
())
...
...
@@ -219,7 +201,9 @@ class UnoConverter(object):
if
field_value_str
:
fieldname
=
document_info
.
getUserFieldName
(
number
)
metadata
[
fieldname
]
=
field_value_str
service_manager
=
helper_util
.
getServiceManager
(
self
.
hostname
,
self
.
port
)
service_manager
=
helper_util
.
getServiceManager
(
self
.
hostname
,
self
.
port
,
self
.
uno_path
,
self
.
office_binary_path
)
type_detection
=
service_manager
.
createInstance
(
"com.sun.star.document.TypeDetection"
)
uno_file_access
=
service_manager
.
createInstance
(
"com.sun.star.ucb.SimpleFileAccess"
)
doc
=
uno_file_access
.
openFileRead
(
self
.
systemPathToFileUrl
(
self
.
document_url
))
...
...
cloudooo/handler/ooo/helper/unomimemapper.py
View file @
115e6f1b
...
...
@@ -33,7 +33,6 @@ try:
except
ImportError
:
import
simplejson
as
json
import
helper_util
from
os
import
environ
,
path
,
putenv
from
getopt
import
getopt
,
GetoptError
from
types
import
InstanceType
...
...
@@ -57,11 +56,11 @@ Options:
class
UnoMimemapper
(
object
):
""" """
def
__init__
(
self
,
hostname
,
port
,
**
kw
):
def
__init__
(
self
,
hostname
,
port
,
uno_path
=
None
,
office_binary_path
=
None
):
""" Receives hostname and port from openoffice and create a service manager"""
self
.
_setUpUnoEnvironment
(
kw
.
get
(
"uno_path"
)
,
kw
.
get
(
"office_binary_path"
))
self
.
service_manager
=
helper_util
.
getServiceManager
(
hostname
,
port
)
self
.
service_manager
=
helper_util
.
getServiceManager
(
hostname
,
port
,
uno_path
,
office_binary_path
)
def
_getElementNameByService
(
self
,
uno_service
,
ignore_name_list
=
[]):
"""Returns an dict with elements."""
...
...
@@ -80,27 +79,6 @@ class UnoMimemapper(object):
return
service_dict
def
_setUpUnoEnvironment
(
self
,
uno_path
=
None
,
office_binary_path
=
None
):
"""Set up the environment to use the uno library and connect with the
openoffice by socket"""
if
uno_path
is
not
None
:
environ
[
'uno_path'
]
=
uno_path
else
:
uno_path
=
environ
.
get
(
'uno_path'
)
if
office_binary_path
is
not
None
:
environ
[
'office_binary_path'
]
=
office_binary_path
else
:
office_binary_path
=
environ
.
get
(
'office_binary_path'
)
# Add in sys.path the path of pyuno
if
uno_path
not
in
sys
.
path
:
sys
.
path
.
append
(
uno_path
)
fundamentalrc_file
=
'%s/fundamentalrc'
%
office_binary_path
if
path
.
exists
(
fundamentalrc_file
)
and
\
'URE_BOOTSTRAP'
not
in
environ
:
putenv
(
'URE_BOOTSTRAP'
,
'vnd.sun.star.pathname:%s'
%
fundamentalrc_file
)
def
getFilterDict
(
self
):
"""Return all filters and your properties"""
filter_service
=
self
.
service_manager
.
createInstance
(
"com.sun.star.document.FilterFactory"
)
...
...
@@ -132,19 +110,20 @@ def main():
if
not
opt_list
:
help
()
port
=
hostname
=
uno_path
=
office_binary_path
=
None
for
opt
,
arg
in
opt_list
:
if
opt
in
(
"-h"
,
"--help"
):
help
()
if
opt
==
"--uno_path"
:
environ
[
'uno_path'
]
=
arg
uno_path
=
arg
elif
opt
==
"--office_binary_path"
:
environ
[
'office_binary_path'
]
=
arg
office_binary_path
=
arg
elif
opt
==
'--hostname'
:
hostname
=
arg
elif
opt
==
"--port"
:
port
=
arg
mimemapper
=
UnoMimemapper
(
hostname
,
port
,
**
dict
(
environ
)
)
mimemapper
=
UnoMimemapper
(
hostname
,
port
,
uno_path
,
office_binary_path
)
filter_dict
=
mimemapper
.
getFilterDict
()
type_dict
=
mimemapper
.
getTypeDict
()
...
...
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