Commit a073ec45 authored by Boris Kocherov's avatar Boris Kocherov

rework @yusei patch a5157949

parent bbe27cf2
...@@ -35,10 +35,14 @@ from threading import Lock ...@@ -35,10 +35,14 @@ from threading import Lock
from zope.interface import implements from zope.interface import implements
from application import Application from application import Application
from cloudooo.interfaces.lockable import ILockable from cloudooo.interfaces.lockable import ILockable
from cloudooo.util import logger, convertStringToBool from cloudooo.util import logger
from cloudooo.handler.ooo.util import waitStartDaemon, \ from cloudooo.handler.ooo.util import waitStartDaemon, \
removeDirectory, \ removeDirectory, \
socketStatus socketStatus
try:
import json
except ImportError:
import simplejson as json
class OpenOffice(Application): class OpenOffice(Application):
...@@ -55,6 +59,7 @@ class OpenOffice(Application): ...@@ -55,6 +59,7 @@ class OpenOffice(Application):
""" """
self._bin_soffice = 'soffice.bin' self._bin_soffice = 'soffice.bin'
self._lock = Lock() self._lock = Lock()
self.last_test_error = None
self._cleanRequest() self._cleanRequest()
def _testOpenOffice(self, host, port): def _testOpenOffice(self, host, port):
...@@ -70,16 +75,18 @@ class OpenOffice(Application): ...@@ -70,16 +75,18 @@ class OpenOffice(Application):
"--port=%s" % port, "--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]
logger.debug("Testing Openoffice Instance %s" % port)
stdout, stderr = Popen(args, stdout=PIPE, stdout, stderr = Popen(args, stdout=PIPE,
stderr=PIPE, close_fds=True).communicate() stderr=PIPE, close_fds=True).communicate()
stdout_bool = convertStringToBool(stdout.replace("\n", "")) if stdout == "":
if stdout_bool and stderr != "": logger.error("openoffice_tester.py cmdline: %s", " ".join(args))
logger.debug("%s\n%s" % (stderr, stdout)) logger.error("openoffice_tester.py stdout: %s", stdout)
logger.error("openoffice_tester.py stderr: %s", stderr)
return False return False
else: stdout = json.loads(stdout)
self.last_test_error = stderr
if stdout == True:
logger.debug("Instance %s works" % port) logger.debug("Instance %s works" % port)
return True return stdout
def _cleanRequest(self): def _cleanRequest(self):
"""Define request attribute as 0""" """Define request attribute as 0"""
......
import signal import signal
import sys import sys
import os import os
import time
def getServiceManager(host, port, uno_path, office_binary_path): def getServiceManager(host, port, uno_path, office_binary_path):
"""Get the ServiceManager from the running OpenOffice.org. """Get the ServiceManager from the running OpenOffice.org.
...@@ -22,14 +21,7 @@ def getServiceManager(host, port, uno_path, office_binary_path): ...@@ -22,14 +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.
# Retry 10 times if needed. uno_connection = resolver.resolve("uno:socket,host=%s,port=%s,tcpNoDelay=1;urp;StarOffice.ComponentContext" % (host, port))
for i in range(10):
try:
uno_connection = resolver.resolve("uno:socket,host=%s,port=%s;urp;StarOffice.ComponentContext" % (host, port))
break
except:
# I don't know how to import com.sun.star.connection.NoConnectException
time.sleep(1)
# Get the ServiceManager object # Get the ServiceManager object
return uno_connection.ServiceManager return uno_connection.ServiceManager
......
...@@ -3,13 +3,18 @@ import sys ...@@ -3,13 +3,18 @@ import sys
import helper_util import helper_util
from getopt import getopt, GetoptError from getopt import getopt, GetoptError
try:
import json
except ImportError:
import simplejson as json
def test_openoffice(hostname, port, uno_path, office_binary_path): def test_openoffice(hostname, port, uno_path, office_binary_path):
import pyuno
try: try:
helper_util.getServiceManager(hostname, port, uno_path, office_binary_path) helper_util.getServiceManager(hostname, port, uno_path, office_binary_path)
return True return True
except Exception, err: except pyuno.getClass("com.sun.star.connection.NoConnectException"):
print err
return False return False
...@@ -30,12 +35,14 @@ def main(): ...@@ -30,12 +35,14 @@ def main():
hostname = arg hostname = arg
elif opt == "--uno_path": elif opt == "--uno_path":
uno_path = arg uno_path = arg
if uno_path not in sys.path:
sys.path.append(uno_path)
elif opt == "--office_binary_path": elif opt == "--office_binary_path":
office_binary_path = arg office_binary_path = arg
sys.stdout.write(str(test_openoffice(hostname, port, output = json.dumps(test_openoffice(hostname, port,
uno_path, office_binary_path))) uno_path, office_binary_path))
sys.stdout.write(output)
if __name__ == "__main__": if __name__ == "__main__":
helper_util.exitOverAbort(main) helper_util.exitOverAbort(main)
\ No newline at end of file
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment