Commit a073ec45 authored by Boris Kocherov's avatar Boris Kocherov

rework @yusei patch a5157949

parent bbe27cf2
......@@ -35,10 +35,14 @@ from threading import Lock
from zope.interface import implements
from application import Application
from cloudooo.interfaces.lockable import ILockable
from cloudooo.util import logger, convertStringToBool
from cloudooo.util import logger
from cloudooo.handler.ooo.util import waitStartDaemon, \
removeDirectory, \
socketStatus
try:
import json
except ImportError:
import simplejson as json
class OpenOffice(Application):
......@@ -55,6 +59,7 @@ class OpenOffice(Application):
"""
self._bin_soffice = 'soffice.bin'
self._lock = Lock()
self.last_test_error = None
self._cleanRequest()
def _testOpenOffice(self, host, port):
......@@ -70,16 +75,18 @@ class OpenOffice(Application):
"--port=%s" % port,
"--uno_path=%s" % self.uno_path,
"--office_binary_path=%s" % self.office_binary_path]
logger.debug("Testing Openoffice Instance %s" % port)
stdout, stderr = Popen(args, stdout=PIPE,
stderr=PIPE, close_fds=True).communicate()
stdout_bool = convertStringToBool(stdout.replace("\n", ""))
if stdout_bool and stderr != "":
logger.debug("%s\n%s" % (stderr, stdout))
if stdout == "":
logger.error("openoffice_tester.py cmdline: %s", " ".join(args))
logger.error("openoffice_tester.py stdout: %s", stdout)
logger.error("openoffice_tester.py stderr: %s", stderr)
return False
else:
stdout = json.loads(stdout)
self.last_test_error = stderr
if stdout == True:
logger.debug("Instance %s works" % port)
return True
return stdout
def _cleanRequest(self):
"""Define request attribute as 0"""
......
import signal
import sys
import os
import time
def getServiceManager(host, port, uno_path, office_binary_path):
"""Get the ServiceManager from the running OpenOffice.org.
......@@ -22,14 +21,7 @@ def getServiceManager(host, port, uno_path, office_binary_path):
uno_context)
# Connect to the running OpenOffice.org and get its
# context.
# Retry 10 times if needed.
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)
uno_connection = resolver.resolve("uno:socket,host=%s,port=%s,tcpNoDelay=1;urp;StarOffice.ComponentContext" % (host, port))
# Get the ServiceManager object
return uno_connection.ServiceManager
......
......@@ -3,13 +3,18 @@ import sys
import helper_util
from getopt import getopt, GetoptError
try:
import json
except ImportError:
import simplejson as json
def test_openoffice(hostname, port, uno_path, office_binary_path):
import pyuno
try:
helper_util.getServiceManager(hostname, port, uno_path, office_binary_path)
return True
except Exception, err:
print err
except pyuno.getClass("com.sun.star.connection.NoConnectException"):
return False
......@@ -30,12 +35,14 @@ def main():
hostname = arg
elif opt == "--uno_path":
uno_path = arg
if uno_path not in sys.path:
sys.path.append(uno_path)
elif opt == "--office_binary_path":
office_binary_path = arg
sys.stdout.write(str(test_openoffice(hostname, port,
uno_path, office_binary_path)))
output = json.dumps(test_openoffice(hostname, port,
uno_path, office_binary_path))
sys.stdout.write(output)
if __name__ == "__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