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
467b6b86
Commit
467b6b86
authored
May 23, 2019
by
Boris Kocherov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use connection string as configure interlink between libreoffice and uno client
parent
a073ec45
Changes
14
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
71 additions
and
142 deletions
+71
-142
cloudooo/handler/ooo/application/application.py
cloudooo/handler/ooo/application/application.py
+2
-12
cloudooo/handler/ooo/application/openoffice.py
cloudooo/handler/ooo/application/openoffice.py
+26
-34
cloudooo/handler/ooo/handler.py
cloudooo/handler/ooo/handler.py
+2
-6
cloudooo/handler/ooo/helper/helper_util.py
cloudooo/handler/ooo/helper/helper_util.py
+2
-2
cloudooo/handler/ooo/helper/openoffice_tester.py
cloudooo/handler/ooo/helper/openoffice_tester.py
+8
-10
cloudooo/handler/ooo/helper/unoconverter.py
cloudooo/handler/ooo/helper/unoconverter.py
+5
-7
cloudooo/handler/ooo/helper/unomimemapper.py
cloudooo/handler/ooo/helper/unomimemapper.py
+7
-9
cloudooo/handler/ooo/mimemapper.py
cloudooo/handler/ooo/mimemapper.py
+2
-3
cloudooo/handler/ooo/tests/testOooMimemapper.py
cloudooo/handler/ooo/tests/testOooMimemapper.py
+1
-3
cloudooo/handler/ooo/tests/testOooMonitorMemory.py
cloudooo/handler/ooo/tests/testOooMonitorMemory.py
+0
-1
cloudooo/handler/ooo/tests/testOooUnoConverter.py
cloudooo/handler/ooo/tests/testOooUnoConverter.py
+2
-3
cloudooo/handler/ooo/tests/testOooUnoMimemapper.py
cloudooo/handler/ooo/tests/testOooUnoMimemapper.py
+4
-29
cloudooo/handler/ooo/util.py
cloudooo/handler/ooo/util.py
+0
-15
cloudooo/tests/handlerTestCase.py
cloudooo/tests/handlerTestCase.py
+10
-8
No files found.
cloudooo/handler/ooo/application/application.py
View file @
467b6b86
...
@@ -29,7 +29,7 @@
...
@@ -29,7 +29,7 @@
from
zope.interface
import
implements
from
zope.interface
import
implements
from
cloudooo.interfaces.application
import
IApplication
from
cloudooo.interfaces.application
import
IApplication
from
cloudooo.util
import
logger
from
cloudooo.util
import
logger
from
psutil
import
pid_exists
,
Process
,
AccessDenied
,
TimeoutExpired
,
NoSuchProcess
from
psutil
import
pid_exists
,
Process
,
TimeoutExpired
,
NoSuchProcess
class
Application
(
object
):
class
Application
(
object
):
...
@@ -100,17 +100,7 @@ class Application(object):
...
@@ -100,17 +100,7 @@ class Application(object):
pid
=
self
.
pid
()
pid
=
self
.
pid
()
if
pid
is
None
or
not
pid_exists
(
pid
):
if
pid
is
None
or
not
pid_exists
(
pid
):
return
False
return
False
process
=
Process
(
pid
)
try
:
for
connection
in
process
.
connections
():
if
connection
.
status
==
'LISTEN'
and
\
connection
.
laddr
[
1
]
==
self
.
port
:
return
True
return
True
except
AccessDenied
:
return
False
return
False
def
getAddress
(
self
):
def
getAddress
(
self
):
"""Return port and hostname of OOo Instance."""
"""Return port and hostname of OOo Instance."""
...
...
cloudooo/handler/ooo/application/openoffice.py
View file @
467b6b86
...
@@ -25,10 +25,8 @@
...
@@ -25,10 +25,8 @@
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
#
##############################################################################
##############################################################################
import
uuid
import
pkg_resources
import
pkg_resources
import
psutil
from
psutil
import
AccessDenied
from
os.path
import
exists
,
join
from
os.path
import
exists
,
join
from
subprocess
import
Popen
,
PIPE
from
subprocess
import
Popen
,
PIPE
from
threading
import
Lock
from
threading
import
Lock
...
@@ -37,12 +35,12 @@ from application import Application
...
@@ -37,12 +35,12 @@ from application import Application
from
cloudooo.interfaces.lockable
import
ILockable
from
cloudooo.interfaces.lockable
import
ILockable
from
cloudooo.util
import
logger
from
cloudooo.util
import
logger
from
cloudooo.handler.ooo.util
import
waitStartDaemon
,
\
from
cloudooo.handler.ooo.util
import
waitStartDaemon
,
\
removeDirectory
,
\
removeDirectory
socketStatus
try
:
try
:
import
json
import
json
except
ImportError
:
except
ImportError
:
import
simplejson
as
json
import
simplejson
as
json
from
time
import
sleep
class
OpenOffice
(
Application
):
class
OpenOffice
(
Application
):
...
@@ -62,17 +60,16 @@ class OpenOffice(Application):
...
@@ -62,17 +60,16 @@ class OpenOffice(Application):
self
.
last_test_error
=
None
self
.
last_test_error
=
None
self
.
_cleanRequest
()
self
.
_cleanRequest
()
def
_testOpenOffice
(
self
,
host
,
port
):
def
_testOpenOffice
(
self
):
"""Test if OpenOffice was started correctly"""
"""Test if OpenOffice was started correctly"""
logger
.
debug
(
"Test OpenOffice %s - Pid %s"
%
(
self
.
get
Address
()[
-
1
]
,
logger
.
debug
(
"Test OpenOffice %s - Pid %s"
%
(
self
.
get
Connection
()
,
self
.
pid
()))
self
.
pid
()))
python
=
join
(
self
.
office_binary_path
,
"python"
)
python
=
join
(
self
.
office_binary_path
,
"python"
)
args
=
[
exists
(
python
)
and
python
or
"python"
,
args
=
[
exists
(
python
)
and
python
or
"python"
,
pkg_resources
.
resource_filename
(
"cloudooo"
,
pkg_resources
.
resource_filename
(
"cloudooo"
,
join
(
'handler'
,
'ooo'
,
join
(
'handler'
,
'ooo'
,
"helper"
,
"openoffice_tester.py"
)),
"helper"
,
"openoffice_tester.py"
)),
"--hostname=%s"
%
host
,
"--connection=%s"
%
self
.
getConnection
(),
"--port=%s"
%
port
,
"--uno_path=%s"
%
self
.
uno_path
,
"--uno_path=%s"
%
self
.
uno_path
,
"--office_binary_path=%s"
%
self
.
office_binary_path
]
"--office_binary_path=%s"
%
self
.
office_binary_path
]
stdout
,
stderr
=
Popen
(
args
,
stdout
=
PIPE
,
stdout
,
stderr
=
Popen
(
args
,
stdout
=
PIPE
,
...
@@ -85,7 +82,7 @@ class OpenOffice(Application):
...
@@ -85,7 +82,7 @@ class OpenOffice(Application):
stdout
=
json
.
loads
(
stdout
)
stdout
=
json
.
loads
(
stdout
)
self
.
last_test_error
=
stderr
self
.
last_test_error
=
stderr
if
stdout
==
True
:
if
stdout
==
True
:
logger
.
debug
(
"Instance %s works"
%
port
)
logger
.
debug
(
"Instance %s works"
%
self
.
getConnection
()
)
return
stdout
return
stdout
def
_cleanRequest
(
self
):
def
_cleanRequest
(
self
):
...
@@ -108,6 +105,17 @@ class OpenOffice(Application):
...
@@ -108,6 +105,17 @@ class OpenOffice(Application):
self
.
uno_path
=
uno_path
self
.
uno_path
=
uno_path
self
.
default_language
=
default_language
self
.
default_language
=
default_language
self
.
environment_dict
=
environment_dict
self
.
environment_dict
=
environment_dict
self
.
connection
=
"socket,host=%s,port=%d"
%
(
self
.
hostname
,
self
.
port
)
self
.
connection
=
"pipe,name=cloudooo_libreoffice_%s"
%
str
(
uuid
.
uuid1
())
def
status
(
self
):
if
Application
.
status
(
self
)
and
\
self
.
_testOpenOffice
():
# repeat for check if uno client do not terminate
# libreoffice
if
Application
.
status
(
self
):
return
True
return
False
def
_startProcess
(
self
,
command
,
env
):
def
_startProcess
(
self
,
command
,
env
):
"""Start OpenOffice.org process"""
"""Start OpenOffice.org process"""
...
@@ -116,29 +124,15 @@ class OpenOffice(Application):
...
@@ -116,29 +124,15 @@ class OpenOffice(Application):
self
.
process
=
Popen
(
command
,
self
.
process
=
Popen
(
command
,
close_fds
=
True
,
close_fds
=
True
,
env
=
env
)
env
=
env
)
if
not
waitStartDaemon
(
self
,
self
.
timeout
):
sleep
(
1
)
continue
if
waitStartDaemon
(
self
,
self
.
timeout
-
1
):
if
self
.
_testOpenOffice
(
self
.
hostname
,
self
.
port
):
if
self
.
last_test_error
:
return
logger
.
debug
(
self
.
last_test_error
)
def
_releaseOpenOfficePort
(
self
):
for
process
in
psutil
.
process_iter
():
try
:
if
process
.
exe
()
==
join
(
self
.
office_binary_path
,
self
.
_bin_soffice
):
for
connection
in
process
.
connections
():
if
connection
.
status
==
"LISTEN"
and
\
connection
.
laddr
[
1
]
==
self
.
port
:
self
.
stopProcess
(
process
.
pid
)
break
except
AccessDenied
,
e
:
pass
except
TypeError
,
e
:
# exception to prevent one psutil issue with zombie processes
logger
.
error
(
e
)
except
NotImplementedError
,
e
:
logger
.
error
(
"lsof isn't installed on this machine: %s"
,
str
(
e
))
break
break
def
getConnection
(
self
):
return
self
.
connection
def
start
(
self
,
init
=
True
):
def
start
(
self
,
init
=
True
):
"""Start Instance."""
"""Start Instance."""
self
.
path_user_installation
=
join
(
self
.
path_run_dir
,
\
self
.
path_user_installation
=
join
(
self
.
path_run_dir
,
\
...
@@ -154,7 +148,7 @@ class OpenOffice(Application):
...
@@ -154,7 +148,7 @@ class OpenOffice(Application):
'--nodefault'
,
'--nodefault'
,
'--norestore'
,
'--norestore'
,
'--nofirststartwizard'
,
'--nofirststartwizard'
,
'--accept=
socket,host=%s,port=%d;urp;'
%
(
self
.
hostname
,
self
.
port
),
'--accept=
%s;urp;'
%
self
.
getConnection
(
),
'-env:UserInstallation=file://%s'
%
self
.
path_user_installation
,
'-env:UserInstallation=file://%s'
%
self
.
path_user_installation
,
'--language=%s'
%
self
.
default_language
,
'--language=%s'
%
self
.
default_language
,
]
]
...
@@ -172,8 +166,6 @@ class OpenOffice(Application):
...
@@ -172,8 +166,6 @@ class OpenOffice(Application):
"""Stop the instance by pid. By the default
"""Stop the instance by pid. By the default
the signal is 15."""
the signal is 15."""
Application
.
stop
(
self
)
Application
.
stop
(
self
)
if
socketStatus
(
self
.
hostname
,
self
.
port
):
self
.
_releaseOpenOfficePort
()
self
.
_cleanRequest
()
self
.
_cleanRequest
()
def
isLocked
(
self
):
def
isLocked
(
self
):
...
...
cloudooo/handler/ooo/handler.py
View file @
467b6b86
...
@@ -83,13 +83,11 @@ class Handler(object):
...
@@ -83,13 +83,11 @@ class Handler(object):
def
_getCommand
(
self
,
*
args
,
**
kw
):
def
_getCommand
(
self
,
*
args
,
**
kw
):
"""Transforms all parameters passed in a command"""
"""Transforms all parameters passed in a command"""
hostname
,
port
=
openoffice
.
getAddress
()
kw
[
'hostname'
]
=
hostname
kw
[
'port'
]
=
port
python
=
path
.
join
(
self
.
office_binary_path
,
"python"
)
python
=
path
.
join
(
self
.
office_binary_path
,
"python"
)
command_list
=
[
path
.
exists
(
python
)
and
python
or
"python"
,
command_list
=
[
path
.
exists
(
python
)
and
python
or
"python"
,
pkg_resources
.
resource_filename
(
__name__
,
pkg_resources
.
resource_filename
(
__name__
,
path
.
join
(
"helper"
,
"unoconverter.py"
)),
path
.
join
(
"helper"
,
"unoconverter.py"
)),
"--connection=%s"
%
openoffice
.
getConnection
(),
"--uno_path=%s"
%
self
.
uno_path
,
"--uno_path=%s"
%
self
.
uno_path
,
"--office_binary_path=%s"
%
self
.
office_binary_path
,
"--office_binary_path=%s"
%
self
.
office_binary_path
,
'--document_url=%s'
%
self
.
document
.
getUrl
()]
'--document_url=%s'
%
self
.
document
.
getUrl
()]
...
@@ -146,7 +144,6 @@ class Handler(object):
...
@@ -146,7 +144,6 @@ class Handler(object):
logger
.
debug
(
"stop convert first"
)
logger
.
debug
(
"stop convert first"
)
if
not
stdout
and
stderr
:
if
not
stdout
and
stderr
:
first_error
=
stderr
first_error
=
stderr
logger
.
error
(
stderr
)
self
.
document
.
restoreOriginal
()
self
.
document
.
restoreOriginal
()
openoffice
.
restart
()
openoffice
.
restart
()
kw
[
'document_url'
]
=
self
.
document
.
getUrl
()
kw
[
'document_url'
]
=
self
.
document
.
getUrl
()
...
@@ -316,6 +313,5 @@ def bootstrapHandler(configuration_dict):
...
@@ -316,6 +313,5 @@ def bootstrapHandler(configuration_dict):
# Load all filters
# Load all filters
openoffice
.
acquire
()
openoffice
.
acquire
()
mimemapper
.
loadFilterList
(
application_hostname
,
mimemapper
.
loadFilterList
(
openoffice
.
getConnection
(),
**
kw
)
openoffice_port
,
**
kw
)
openoffice
.
release
()
openoffice
.
release
()
cloudooo/handler/ooo/helper/helper_util.py
View file @
467b6b86
...
@@ -2,7 +2,7 @@ import signal
...
@@ -2,7 +2,7 @@ import signal
import
sys
import
sys
import
os
import
os
def
getServiceManager
(
host
,
port
,
uno_path
,
office_binary_path
):
def
getServiceManager
(
connection
,
uno_path
,
office_binary_path
):
"""Get the ServiceManager from the running OpenOffice.org.
"""Get the ServiceManager from the running OpenOffice.org.
"""
"""
# Add in sys.path the path of pyuno
# Add in sys.path the path of pyuno
...
@@ -21,7 +21,7 @@ def getServiceManager(host, port, uno_path, office_binary_path):
...
@@ -21,7 +21,7 @@ def getServiceManager(host, port, uno_path, office_binary_path):
uno_context
)
uno_context
)
# Connect to the running OpenOffice.org and get its
# Connect to the running OpenOffice.org and get its
# context.
# context.
uno_connection
=
resolver
.
resolve
(
"uno:
socket,host=%s,port=%s,tcpNoDelay=1;urp;StarOffice.ComponentContext"
%
(
host
,
port
)
)
uno_connection
=
resolver
.
resolve
(
"uno:
%s;urp;StarOffice.ComponentContext"
%
connection
)
# Get the ServiceManager object
# Get the ServiceManager object
return
uno_connection
.
ServiceManager
return
uno_connection
.
ServiceManager
...
...
cloudooo/handler/ooo/helper/openoffice_tester.py
View file @
467b6b86
...
@@ -9,10 +9,10 @@ except ImportError:
...
@@ -9,10 +9,10 @@ except ImportError:
import
simplejson
as
json
import
simplejson
as
json
def
test_openoffice
(
hostname
,
port
,
uno_path
,
office_binary_path
):
def
test_openoffice
(
connection
,
uno_path
,
office_binary_path
):
import
pyuno
import
pyuno
try
:
try
:
helper_util
.
getServiceManager
(
hostname
,
port
,
uno_path
,
office_binary_path
)
helper_util
.
getServiceManager
(
connection
,
uno_path
,
office_binary_path
)
return
True
return
True
except
pyuno
.
getClass
(
"com.sun.star.connection.NoConnectException"
):
except
pyuno
.
getClass
(
"com.sun.star.connection.NoConnectException"
):
return
False
return
False
...
@@ -21,18 +21,16 @@ def test_openoffice(hostname, port, uno_path, office_binary_path):
...
@@ -21,18 +21,16 @@ def test_openoffice(hostname, port, uno_path, office_binary_path):
def
main
():
def
main
():
try
:
try
:
opt_list
,
arg_list
=
getopt
(
sys
.
argv
[
1
:],
""
,
opt_list
,
arg_list
=
getopt
(
sys
.
argv
[
1
:],
""
,
[
"
port="
,
"hostname
="
,
"uno_path="
,
[
"
connection
="
,
"uno_path="
,
"office_binary_path="
])
"office_binary_path="
])
except
GetoptError
as
e
:
except
GetoptError
as
e
:
sys
.
stderr
.
write
(
"%s
\
n
Use --
port and --hostname
"
%
e
)
sys
.
stderr
.
write
(
"%s
\
n
Use --
connection
"
%
e
)
sys
.
exit
(
2
)
sys
.
exit
(
2
)
port
=
hostname
=
uno_path
=
office_binary_path
=
None
connection
=
uno_path
=
office_binary_path
=
None
for
opt
,
arg
in
opt_list
:
for
opt
,
arg
in
opt_list
:
if
opt
==
"--port"
:
if
opt
==
"--connection"
:
port
=
arg
connection
=
arg
elif
opt
==
"--hostname"
:
hostname
=
arg
elif
opt
==
"--uno_path"
:
elif
opt
==
"--uno_path"
:
uno_path
=
arg
uno_path
=
arg
if
uno_path
not
in
sys
.
path
:
if
uno_path
not
in
sys
.
path
:
...
@@ -40,7 +38,7 @@ def main():
...
@@ -40,7 +38,7 @@ def main():
elif
opt
==
"--office_binary_path"
:
elif
opt
==
"--office_binary_path"
:
office_binary_path
=
arg
office_binary_path
=
arg
output
=
json
.
dumps
(
test_openoffice
(
hostname
,
port
,
output
=
json
.
dumps
(
test_openoffice
(
connection
,
uno_path
,
office_binary_path
))
uno_path
,
office_binary_path
))
sys
.
stdout
.
write
(
output
)
sys
.
stdout
.
write
(
output
)
...
...
cloudooo/handler/ooo/helper/unoconverter.py
View file @
467b6b86
...
@@ -298,7 +298,7 @@ def main():
...
@@ -298,7 +298,7 @@ def main():
opt_list
,
arg_list
=
getopt
(
sys
.
argv
[
1
:],
"h"
,
[
"help"
,
"test"
,
opt_list
,
arg_list
=
getopt
(
sys
.
argv
[
1
:],
"h"
,
[
"help"
,
"test"
,
"convert"
,
"getmetadata"
,
"setmetadata"
,
"convert"
,
"getmetadata"
,
"setmetadata"
,
"uno_path="
,
"office_binary_path="
,
"uno_path="
,
"office_binary_path="
,
"
hostname="
,
"port
="
,
"source_format="
,
"
connection
="
,
"source_format="
,
"document_url="
,
"destination_format="
,
"document_url="
,
"destination_format="
,
"mimemapper="
,
"metadata="
,
"refresh="
,
"mimemapper="
,
"metadata="
,
"refresh="
,
"unomimemapper_bin="
])
"unomimemapper_bin="
])
...
@@ -313,15 +313,13 @@ def main():
...
@@ -313,15 +313,13 @@ def main():
import
json
import
json
except
ImportError
:
except
ImportError
:
import
simplejson
as
json
import
simplejson
as
json
hostname
=
port
=
document_url
=
office_binary_path
=
uno_path
=
\
connection
=
document_url
=
office_binary_path
=
uno_path
=
\
destination_format
=
source_format
=
refresh
=
metadata
=
mimemapper
=
None
destination_format
=
source_format
=
refresh
=
metadata
=
mimemapper
=
None
for
opt
,
arg
in
iter
(
opt_list
):
for
opt
,
arg
in
iter
(
opt_list
):
if
opt
in
(
'-h'
,
'--help'
):
if
opt
in
(
'-h'
,
'--help'
):
help
()
help
()
elif
opt
==
'--hostname'
:
elif
opt
==
'--connection'
:
hostname
=
arg
connection
=
arg
elif
opt
==
'--port'
:
port
=
arg
elif
opt
==
'--document_url'
:
elif
opt
==
'--document_url'
:
document_url
=
arg
document_url
=
arg
elif
opt
==
'--office_binary_path'
:
elif
opt
==
'--office_binary_path'
:
...
@@ -340,7 +338,7 @@ def main():
...
@@ -340,7 +338,7 @@ def main():
elif
opt
==
'--mimemapper'
:
elif
opt
==
'--mimemapper'
:
mimemapper
=
json
.
loads
(
arg
)
mimemapper
=
json
.
loads
(
arg
)
service_manager
=
helper_util
.
getServiceManager
(
hostname
,
port
,
service_manager
=
helper_util
.
getServiceManager
(
connection
,
uno_path
,
office_binary_path
)
uno_path
,
office_binary_path
)
if
'--getmetadata'
in
param_list
and
'--convert'
in
param_list
:
if
'--getmetadata'
in
param_list
and
'--convert'
in
param_list
:
with
UnoConverter
(
service_manager
,
document_url
,
source_format
,
refresh
)
as
unoconverter
:
with
UnoConverter
(
service_manager
,
document_url
,
source_format
,
refresh
)
as
unoconverter
:
...
...
cloudooo/handler/ooo/helper/unomimemapper.py
View file @
467b6b86
...
@@ -66,9 +66,9 @@ Options:
...
@@ -66,9 +66,9 @@ Options:
class
UnoMimemapper
(
object
):
class
UnoMimemapper
(
object
):
""" """
""" """
def
__init__
(
self
,
hostname
,
port
,
uno_path
=
None
,
office_binary_path
=
None
):
def
__init__
(
self
,
connection
,
uno_path
=
None
,
office_binary_path
=
None
):
""" Receives hostname and port from openoffice and create a service manager"""
""" Receives hostname and port from openoffice and create a service manager"""
self
.
service_manager
=
helper_util
.
getServiceManager
(
hostname
,
port
,
self
.
service_manager
=
helper_util
.
getServiceManager
(
connection
,
uno_path
,
uno_path
,
office_binary_path
)
office_binary_path
)
...
@@ -111,7 +111,7 @@ def main():
...
@@ -111,7 +111,7 @@ def main():
try
:
try
:
opt_list
,
arg_list
=
getopt
(
sys
.
argv
[
1
:],
"h"
,
[
"help"
,
opt_list
,
arg_list
=
getopt
(
sys
.
argv
[
1
:],
"h"
,
[
"help"
,
"uno_path="
,
"office_binary_path="
,
"uno_path="
,
"office_binary_path="
,
"
hostname="
,
"port
="
])
"
connection
="
])
except
GetoptError
as
msg
:
except
GetoptError
as
msg
:
msg
=
msg
.
msg
+
"
\
n
Use --help or -h
\
n
"
msg
=
msg
.
msg
+
"
\
n
Use --help or -h
\
n
"
sys
.
stderr
.
write
(
msg
)
sys
.
stderr
.
write
(
msg
)
...
@@ -120,7 +120,7 @@ def main():
...
@@ -120,7 +120,7 @@ def main():
if
not
opt_list
:
if
not
opt_list
:
help
()
help
()
port
=
hostname
=
uno_path
=
office_binary_path
=
None
connection
=
uno_path
=
office_binary_path
=
None
for
opt
,
arg
in
opt_list
:
for
opt
,
arg
in
opt_list
:
if
opt
in
(
"-h"
,
"--help"
):
if
opt
in
(
"-h"
,
"--help"
):
help
()
help
()
...
@@ -128,12 +128,10 @@ def main():
...
@@ -128,12 +128,10 @@ def main():
uno_path
=
arg
uno_path
=
arg
elif
opt
==
"--office_binary_path"
:
elif
opt
==
"--office_binary_path"
:
office_binary_path
=
arg
office_binary_path
=
arg
elif
opt
==
'--hostname'
:
elif
opt
==
'--connection'
:
hostname
=
arg
connection
=
arg
elif
opt
==
"--port"
:
port
=
arg
mimemapper
=
UnoMimemapper
(
hostname
,
port
,
uno_path
,
office_binary_path
)
mimemapper
=
UnoMimemapper
(
connection
,
uno_path
,
office_binary_path
)
filter_dict
=
mimemapper
.
getFilterDict
()
filter_dict
=
mimemapper
.
getFilterDict
()
type_dict
=
mimemapper
.
getTypeDict
()
type_dict
=
mimemapper
.
getTypeDict
()
...
...
cloudooo/handler/ooo/mimemapper.py
View file @
467b6b86
...
@@ -88,7 +88,7 @@ class MimeMapper(object):
...
@@ -88,7 +88,7 @@ class MimeMapper(object):
"""Verify if filters were loaded"""
"""Verify if filters were loaded"""
return
self
.
_loaded
return
self
.
_loaded
def
loadFilterList
(
self
,
hostname
,
port
,
**
kw
):
def
loadFilterList
(
self
,
connection
,
**
kw
):
"""Load all filters of openoffice.
"""Load all filters of openoffice.
Keyword arguments:
Keyword arguments:
hostname -- host of OpenOffice
hostname -- host of OpenOffice
...
@@ -122,8 +122,7 @@ class MimeMapper(object):
...
@@ -122,8 +122,7 @@ class MimeMapper(object):
path
.
join
(
"helper"
,
"unomimemapper.py"
)),
path
.
join
(
"helper"
,
"unomimemapper.py"
)),
"--uno_path=%s"
%
uno_path
,
"--uno_path=%s"
%
uno_path
,
"--office_binary_path=%s"
%
office_binary_path
,
"--office_binary_path=%s"
%
office_binary_path
,
"--hostname=%s"
%
hostname
,
"--connection=%s"
%
connection
]
"--port=%s"
%
port
]
process
=
Popen
(
command
,
stdout
=
PIPE
,
stderr
=
PIPE
,
close_fds
=
True
)
process
=
Popen
(
command
,
stdout
=
PIPE
,
stderr
=
PIPE
,
close_fds
=
True
)
stdout
,
stderr
=
process
.
communicate
()
stdout
,
stderr
=
process
.
communicate
()
...
...
cloudooo/handler/ooo/tests/testOooMimemapper.py
View file @
467b6b86
...
@@ -150,9 +150,7 @@ class TestMimeMapper(HandlerTestCase):
...
@@ -150,9 +150,7 @@ class TestMimeMapper(HandlerTestCase):
"""Mimemapper is created and load uno path."""
"""Mimemapper is created and load uno path."""
self
.
mimemapper
=
MimeMapper
()
self
.
mimemapper
=
MimeMapper
()
openoffice
.
acquire
()
openoffice
.
acquire
()
hostname
,
port
=
openoffice
.
getAddress
()
self
.
mimemapper
.
loadFilterList
(
openoffice
.
getConnection
(),
self
.
mimemapper
.
loadFilterList
(
hostname
,
port
,
python_path
=
self
.
python_path
)
python_path
=
self
.
python_path
)
openoffice
.
release
()
openoffice
.
release
()
...
...
cloudooo/handler/ooo/tests/testOooMonitorMemory.py
View file @
467b6b86
...
@@ -32,7 +32,6 @@ from cloudooo.handler.ooo.application.openoffice import openoffice
...
@@ -32,7 +32,6 @@ from cloudooo.handler.ooo.application.openoffice import openoffice
from
cloudooo.handler.ooo.monitor.memory
import
MonitorMemory
from
cloudooo.handler.ooo.monitor.memory
import
MonitorMemory
from
psutil
import
Process
from
psutil
import
Process
from
types
import
IntType
from
types
import
IntType
from
cloudooo.tests.handlerTestCase
import
make_suite
OPENOFFICE
=
True
OPENOFFICE
=
True
...
...
cloudooo/handler/ooo/tests/testOooUnoConverter.py
View file @
467b6b86
...
@@ -47,7 +47,7 @@ class TestUnoConverter(HandlerTestCase):
...
@@ -47,7 +47,7 @@ class TestUnoConverter(HandlerTestCase):
def
afterSetUp
(
self
):
def
afterSetUp
(
self
):
""" """
""" """
openoffice
.
acquire
()
openoffice
.
acquire
()
self
.
hostname
,
self
.
port
=
openoffice
.
getAddress
()
self
.
connection
=
openoffice
.
getConnection
()
data
=
open
(
"data/test.odt"
,
'r'
).
read
()
data
=
open
(
"data/test.odt"
,
'r'
).
read
()
self
.
document
=
FileSystemDocument
(
self
.
tmp_url
,
data
,
'odt'
)
self
.
document
=
FileSystemDocument
(
self
.
tmp_url
,
data
,
'odt'
)
...
@@ -69,8 +69,7 @@ class TestUnoConverter(HandlerTestCase):
...
@@ -69,8 +69,7 @@ class TestUnoConverter(HandlerTestCase):
"--convert"
,
"--convert"
,
"--uno_path=%s"
%
self
.
uno_path
,
"--uno_path=%s"
%
self
.
uno_path
,
"--office_binary_path=%s"
%
self
.
office_binary_path
,
"--office_binary_path=%s"
%
self
.
office_binary_path
,
"--hostname=%s"
%
self
.
hostname
,
"--connection=%s"
%
self
.
connection
,
"--port=%s"
%
self
.
port
,
"--document_url=%s"
%
self
.
document
.
getUrl
(),
"--document_url=%s"
%
self
.
document
.
getUrl
(),
"--destination_format=%s"
%
"doc"
,
"--destination_format=%s"
%
"doc"
,
"--source_format=%s"
%
"odt"
,
"--source_format=%s"
%
"odt"
,
...
...
cloudooo/handler/ooo/tests/testOooUnoMimemapper.py
View file @
467b6b86
...
@@ -54,36 +54,13 @@ class TestUnoMimeMapper(HandlerTestCase):
...
@@ -54,36 +54,13 @@ class TestUnoMimeMapper(HandlerTestCase):
def
testCreateLocalAttributes
(
self
):
def
testCreateLocalAttributes
(
self
):
"""Test if filters returns correctly the filters and types in dict"""
"""Test if filters returns correctly the filters and types in dict"""
hostname
,
host
=
openoffice
.
getAddress
()
python
=
path
.
join
(
self
.
office_binary_path
,
"python"
)
python
=
path
.
join
(
self
.
office_binary_path
,
"python"
)
command
=
[
path
.
exists
(
python
)
and
python
or
"python"
,
command
=
[
path
.
exists
(
python
)
and
python
or
"python"
,
pkg_resources
.
resource_filename
(
self
.
package_namespace
,
pkg_resources
.
resource_filename
(
self
.
package_namespace
,
"/helper/unomimemapper.py"
),
"/helper/unomimemapper.py"
),
"--uno_path=%s"
%
self
.
uno_path
,
"--uno_path=%s"
%
self
.
uno_path
,
"--office_binary_path=%s"
%
self
.
office_binary_path
,
"--office_binary_path=%s"
%
self
.
office_binary_path
,
"--hostname=%s"
%
self
.
hostname
,
"--connection=%s"
%
openoffice
.
getConnection
()]
"--port=%s"
%
self
.
openoffice_port
]
process
=
Popen
(
command
,
stdout
=
PIPE
,
stderr
=
PIPE
)
stdout
,
stderr
=
process
.
communicate
()
self
.
assertEquals
(
process
.
returncode
,
-
15
)
self
.
assertEquals
(
stderr
,
''
)
filter_dict
,
type_dict
=
json
.
loads
(
stdout
)
self
.
assertTrue
(
'filter_dict'
in
locals
())
self
.
assertTrue
(
'type_dict'
in
locals
())
self
.
assertNotEquals
(
filter_dict
.
get
(
'writer8'
),
None
)
self
.
assertEquals
(
type_dict
.
get
(
'writer8'
).
get
(
'Name'
),
'writer8'
)
self
.
assertNotEquals
(
filter_dict
.
get
(
'writer8'
),
None
)
self
.
assertEquals
(
type_dict
.
get
(
'writer8'
).
get
(
'PreferredFilter'
),
'writer8'
)
self
.
assertEquals
(
stderr
,
''
)
def
testCallUnoMimemapperOnlyHostNameAndPort
(
self
):
""" Test call unomimemapper without uno_path and office_binary_path"""
hostname
,
host
=
openoffice
.
getAddress
()
command
=
[
path
.
join
(
self
.
office_binary_path
,
"python"
),
pkg_resources
.
resource_filename
(
self
.
package_namespace
,
"/helper/unomimemapper.py"
),
"--hostname=%s"
%
self
.
hostname
,
"--port=%s"
%
self
.
openoffice_port
]
process
=
Popen
(
command
,
stdout
=
PIPE
,
stderr
=
PIPE
)
process
=
Popen
(
command
,
stdout
=
PIPE
,
stderr
=
PIPE
)
stdout
,
stderr
=
process
.
communicate
()
stdout
,
stderr
=
process
.
communicate
()
self
.
assertEquals
(
process
.
returncode
,
-
3
)
self
.
assertEquals
(
process
.
returncode
,
-
3
)
...
@@ -99,8 +76,7 @@ class TestUnoMimeMapper(HandlerTestCase):
...
@@ -99,8 +76,7 @@ class TestUnoMimeMapper(HandlerTestCase):
def
testWithoutOpenOffice
(
self
):
def
testWithoutOpenOffice
(
self
):
"""Test when the openoffice is stopped"""
"""Test when the openoffice is stopped"""
error_msg
=
"couldn
\
'
t connect to socket (Success)
\
n
"
error_msg
=
"helper_util.com.sun.star.connection.NoConnectException: Connector : couldn't connect to "
hostname
,
host
=
openoffice
.
getAddress
()
openoffice
.
stop
()
openoffice
.
stop
()
python
=
path
.
join
(
self
.
office_binary_path
,
"python"
)
python
=
path
.
join
(
self
.
office_binary_path
,
"python"
)
command
=
[
path
.
exists
(
python
)
and
python
or
"python"
,
command
=
[
path
.
exists
(
python
)
and
python
or
"python"
,
...
@@ -108,13 +84,12 @@ class TestUnoMimeMapper(HandlerTestCase):
...
@@ -108,13 +84,12 @@ class TestUnoMimeMapper(HandlerTestCase):
"/helper/unomimemapper.py"
),
"/helper/unomimemapper.py"
),
"--uno_path=%s"
%
self
.
uno_path
,
"--uno_path=%s"
%
self
.
uno_path
,
"--office_binary_path=%s"
%
self
.
office_binary_path
,
"--office_binary_path=%s"
%
self
.
office_binary_path
,
"--hostname=%s"
%
self
.
hostname
,
"--connection=%s"
%
openoffice
.
getConnection
()]
"--port=%s"
%
self
.
openoffice_port
]
process
=
Popen
(
command
,
stdout
=
PIPE
,
stderr
=
PIPE
)
process
=
Popen
(
command
,
stdout
=
PIPE
,
stderr
=
PIPE
)
stdout
,
stderr
=
process
.
communicate
()
stdout
,
stderr
=
process
.
communicate
()
self
.
assertEquals
(
process
.
returncode
,
-
3
)
self
.
assertEquals
(
process
.
returncode
,
-
3
)
self
.
assertEquals
(
stdout
,
''
)
self
.
assertEquals
(
stdout
,
''
)
self
.
assertTrue
(
stderr
.
endswith
(
error_msg
)
,
stderr
)
self
.
assertTrue
(
error_msg
in
stderr
,
stderr
)
openoffice
.
start
()
openoffice
.
start
()
cloudooo/handler/ooo/util.py
View file @
467b6b86
...
@@ -26,8 +26,6 @@
...
@@ -26,8 +26,6 @@
#
#
##############################################################################
##############################################################################
from
socket
import
socket
,
error
from
errno
import
EADDRINUSE
from
time
import
sleep
from
time
import
sleep
from
os
import
remove
from
os
import
remove
from
shutil
import
rmtree
from
shutil
import
rmtree
...
@@ -41,19 +39,6 @@ def removeDirectory(path):
...
@@ -41,19 +39,6 @@ def removeDirectory(path):
except
OSError
,
msg
:
except
OSError
,
msg
:
logger
.
error
(
msg
)
logger
.
error
(
msg
)
def
socketStatus
(
hostname
,
port
):
"""Verify if the address is busy."""
try
:
socket
().
bind
((
hostname
,
port
),)
# False if the is free
return
False
except
error
,
(
num
,
err
):
if
num
==
EADDRINUSE
:
# True if the isn't free
return
True
def
waitStartDaemon
(
daemon
,
attempts
):
def
waitStartDaemon
(
daemon
,
attempts
):
"""Wait a certain time to start the daemon."""
"""Wait a certain time to start the daemon."""
for
num
in
range
(
attempts
):
for
num
in
range
(
attempts
):
...
...
cloudooo/tests/handlerTestCase.py
View file @
467b6b86
...
@@ -58,7 +58,7 @@ def startFakeEnvironment(start_openoffice=True, conf_path=None):
...
@@ -58,7 +58,7 @@ def startFakeEnvironment(start_openoffice=True, conf_path=None):
uno_path
=
config
.
get
(
"app:main"
,
"uno_path"
)
uno_path
=
config
.
get
(
"app:main"
,
"uno_path"
)
working_path
=
config
.
get
(
"app:main"
,
"working_path"
)
working_path
=
config
.
get
(
"app:main"
,
"working_path"
)
hostname
=
config
.
get
(
"server:main"
,
"host"
)
hostname
=
config
.
get
(
"server:main"
,
"host"
)
openoffice_port
=
int
(
config
.
get
(
"app:main"
,
"openoffice_port"
))
openoffice_port
=
int
(
config
.
get
(
"app:main"
,
"openoffice_port"
))
+
1
office_binary_path
=
config
.
get
(
"app:main"
,
"office_binary_path"
)
office_binary_path
=
config
.
get
(
"app:main"
,
"office_binary_path"
)
environment_dict
=
{}
environment_dict
=
{}
for
item
in
config
.
options
(
"app:main"
):
for
item
in
config
.
options
(
"app:main"
):
...
@@ -93,11 +93,10 @@ def startFakeEnvironment(start_openoffice=True, conf_path=None):
...
@@ -93,11 +93,10 @@ def startFakeEnvironment(start_openoffice=True, conf_path=None):
environment_dict
)
environment_dict
)
openoffice
.
start
()
openoffice
.
start
()
openoffice
.
acquire
()
openoffice
.
acquire
()
hostname
,
port
=
openoffice
.
getAddress
()
kw
=
dict
(
uno_path
=
config
.
get
(
"app:main"
,
"uno_path"
),
kw
=
dict
(
uno_path
=
config
.
get
(
"app:main"
,
"uno_path"
),
office_binary_path
=
config
.
get
(
"app:main"
,
"office_binary_path"
))
office_binary_path
=
config
.
get
(
"app:main"
,
"office_binary_path"
))
if
not
mimemapper
.
isLoaded
():
if
not
mimemapper
.
isLoaded
():
mimemapper
.
loadFilterList
(
hostname
,
port
,
**
kw
)
mimemapper
.
loadFilterList
(
openoffice
.
getConnection
()
,
**
kw
)
openoffice
.
release
()
openoffice
.
release
()
return
openoffice
return
openoffice
...
@@ -110,8 +109,9 @@ def stopFakeEnvironment(stop_openoffice=True):
...
@@ -110,8 +109,9 @@ def stopFakeEnvironment(stop_openoffice=True):
if
1
:
if
1
:
from
cloudooo.handler.ooo.application.openoffice
import
OpenOffice
from
cloudooo.handler.ooo.application.openoffice
import
OpenOffice
from
cloudooo.handler.ooo.util
import
waitStartDaemon
,
waitStopDaemon
from
cloudooo.handler.ooo.util
import
waitStartDaemon
from
subprocess
import
Popen
,
PIPE
from
subprocess
import
Popen
,
PIPE
from
time
import
sleep
# patch OpenOffice._startProcess not to put bogus output to stderr,
# patch OpenOffice._startProcess not to put bogus output to stderr,
# that prevents detecting the end of unit test.
# that prevents detecting the end of unit test.
...
@@ -119,14 +119,16 @@ if 1:
...
@@ -119,14 +119,16 @@ if 1:
"""Start OpenOffice.org process"""
"""Start OpenOffice.org process"""
for
i
in
range
(
5
):
for
i
in
range
(
5
):
self
.
stop
()
self
.
stop
()
waitStopDaemon
(
self
,
self
.
timeout
)
self
.
process
=
Popen
(
command
,
stderr
=
PIPE
,
self
.
process
=
Popen
(
command
,
stderr
=
PIPE
,
close_fds
=
True
,
close_fds
=
True
,
env
=
env
)
env
=
env
)
if
not
waitStartDaemon
(
self
,
self
.
timeout
):
sleep
(
1
)
if
self
.
process
.
poll
()
is
not
None
:
# process already terminated so
# rerun
continue
continue
if
self
.
_testOpenOffice
(
self
.
hostname
,
self
.
port
):
if
waitStartDaemon
(
self
,
self
.
timeout
-
1
):
return
break
OpenOffice
.
_startProcess
=
_startProcess
OpenOffice
.
_startProcess
=
_startProcess
...
...
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