Commit 2ad06905 authored by Boris Kocherov's avatar Boris Kocherov

rework @yusei patch a5157949

parent cedd433c
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.
...@@ -21,13 +20,6 @@ def getServiceManager(host, port, uno_path, office_binary_path): ...@@ -21,13 +20,6 @@ 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
...@@ -2,14 +2,26 @@ ...@@ -2,14 +2,26 @@
import sys import sys
import helper_util import helper_util
from getopt import getopt, GetoptError from getopt import getopt, GetoptError
import time
import uno
NoConnectException = uno.getClass("com.sun.star.connection.NoConnectException")
def test_openoffice(hostname, port): def test_openoffice(hostname, port):
# increase count if NoConnectException raised
count = 10
try: try:
helper_util.getServiceManager(hostname, port) for i in range(count - 1):
try:
helper_util.getServiceManager(hostname, port)
break
except NoConnectException:
if i == count - 2:
helper_util.getServiceManager(hostname, port)
time.sleep(1)
return True return True
except Exception, err: except:
print err import traceback
sys.stderr.write(traceback.format_exc())
return False return False
......
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