Commit 3ce4ed9b authored by Gabriel Monnerat's avatar Gabriel Monnerat

move openoffice_tester.py and add helper_utils.py to remove code duplicated

git-svn-id: https://svn.erp5.org/repos/public/erp5/trunk/utils@38571 20353a03-c40f-0410-a6d1-a30d3c3de9de
parent ae2759f3
def getServiceManager(host, port):
"""Get the ServiceManager from the running OpenOffice.org."""
import uno
# Get the uno component context from the PyUNO runtime
uno_context = uno.getComponentContext()
# Create the UnoUrlResolver on the Python side.
url_resolver = "com.sun.star.bridge.UnoUrlResolver"
resolver = uno_context.ServiceManager.createInstanceWithContext(url_resolver,
uno_context)
# Connect to the running OpenOffice.org and get its
# context.
uno_connection = resolver.resolve("uno:socket,host=%s,port=%s;urp;StarOffice.ComponentContext" % (host, port))
# Get the ServiceManager object
return uno_connection.ServiceManager
#!/usr/bin/env python
import sys
import helper_utils
from getopt import getopt, GetoptError
from cloudooo.utils import usage
from cloudooo import ooolib
from os import environ
def test_openoffice(hostname, port):
try:
ooolib.getServiceManager(hostname, port)
helper_utils.getServiceManager(hostname, port)
return True
except Exception, err:
print err
......
......@@ -29,6 +29,7 @@
import sys
import jsonpickle
import helper_utils
from types import UnicodeType, InstanceType
from os import environ, putenv
from os.path import dirname, exists
......@@ -108,21 +109,6 @@ class UnoConverter(object):
property.Value = value
return property
def _getServiceManager(self, host, port):
"""Get the ServiceManager from the running OpenOffice.org."""
import uno
# Get the uno component context from the PyUNO runtime
uno_context = uno.getComponentContext()
# Create the UnoUrlResolver on the Python side.
url_resolver = "com.sun.star.bridge.UnoUrlResolver"
resolver = uno_context.ServiceManager.createInstanceWithContext(url_resolver,
uno_context)
# Connect to the running OpenOffice.org and get its
# context.
uno_connection = resolver.resolve("uno:socket,host=%s,port=%s;urp;StarOffice.ComponentContext" % (host, port))
# Get the ServiceManager object
return uno_connection.ServiceManager
def _createSpecificProperty(self, filter_name):
"""Creates a property according to the filter"""
import uno
......@@ -173,7 +159,7 @@ class UnoConverter(object):
def _load(self):
"""Create one document with basic properties"""
service_manager = self._getServiceManager(self.hostname, self.port)
service_manager = helper_utils.getServiceManager(self.hostname, self.port)
desktop = service_manager.createInstance("com.sun.star.frame.Desktop")
uno_url = self.systemPathToFileUrl(self.document_url)
uno_document = desktop.loadComponentFromURL(uno_url, "_blank", 0, ())
......@@ -225,7 +211,7 @@ class UnoConverter(object):
if field_value_str:
fieldname = document_info.getUserFieldName(number)
metadata[fieldname] = field_value_str
service_manager = self._getServiceManager(self.hostname, self.port)
service_manager = helper_utils.getServiceManager(self.hostname, self.port)
uno_file_access = service_manager.createInstance("com.sun.star.ucb.SimpleFileAccess")
doc = uno_file_access.openFileRead(self.systemPathToFileUrl(self.document_url))
property_list = []
......
......@@ -28,6 +28,7 @@
##############################################################################
import sys
import helper_utils
from os import environ, path, putenv
from getopt import getopt, GetoptError
from types import InstanceType
......@@ -55,7 +56,7 @@ class UnoMimemapper(object):
""" 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 = self._getServiceManager(hostname, port)
self.service_manager = helper_utils.getServiceManager(hostname, port)
def _getElementNameByService(self, uno_service, ignore_name_list=[]):
"""Returns an dict with elements."""
......@@ -95,21 +96,6 @@ class UnoMimemapper(object):
not environ.has_key('URE_BOOTSTRAP'):
putenv('URE_BOOTSTRAP','vnd.sun.star.pathname:%s' % fundamentalrc_file)
def _getServiceManager(self, host, port):
"""Get the ServiceManager from the running OpenOffice.org."""
import uno
# Get the uno component context from the PyUNO runtime
uno_context = uno.getComponentContext()
# Create the UnoUrlResolver on the Python side.
url_resolver = "com.sun.star.bridge.UnoUrlResolver"
resolver = uno_context.ServiceManager.createInstanceWithContext(url_resolver,
uno_context)
# Connect to the running OpenOffice.org and get its
# context.
uno_connection = resolver.resolve("uno:socket,host=%s,port=%s;urp;StarOffice.ComponentContext" % (host, port))
# Get the ServiceManager object
return uno_connection.ServiceManager
def getFilterDict(self):
"""Return all filters and your properties"""
filter_service = self.service_manager.createInstance("com.sun.star.document.FilterFactory")
......
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