From 85587ce2f3a1ad908988fc810ab71ee99bbb4936 Mon Sep 17 00:00:00 2001 From: Tim Bentley Date: Mon, 4 Apr 2016 21:14:04 +0100 Subject: [PATCH] uno commands --- openlp/core/common/__init__.py | 32 +++++++++++++++++ openlp/core/utils/__init__.py | 34 +------------------ .../presentations/lib/impresscontroller.py | 2 +- .../plugins/songs/lib/importers/openoffice.py | 2 +- .../functional/openlp_core_utils/test_init.py | 2 +- .../openlp_core_utils/test_utils.py | 3 +- 6 files changed, 38 insertions(+), 37 deletions(-) diff --git a/openlp/core/common/__init__.py b/openlp/core/common/__init__.py index b382a719f..b951ff038 100644 --- a/openlp/core/common/__init__.py +++ b/openlp/core/common/__init__.py @@ -30,6 +30,7 @@ import re import sys import traceback from ipaddress import IPv4Address, IPv6Address, AddressValueError +from shutil import which from PyQt5 import QtCore from PyQt5.QtCore import QCryptographicHash as QHash @@ -257,3 +258,34 @@ def add_actions(target, actions): target.addSeparator() else: target.addAction(action) + + +def get_uno_command(connection_type='pipe'): + """ + Returns the UNO command to launch an libreoffice.org instance. + """ + for command in ['libreoffice', 'soffice']: + if which(command): + break + else: + raise FileNotFoundError('Command not found') + + OPTIONS = '--nologo --norestore --minimized --nodefault --nofirststartwizard' + if connection_type == 'pipe': + CONNECTION = '"--accept=pipe,name=openlp_pipe;urp;"' + else: + CONNECTION = '"--accept=socket,host=localhost,port=2002;urp;"' + return '%s %s %s' % (command, OPTIONS, CONNECTION) + + +def get_uno_instance(resolver, connection_type='pipe'): + """ + Returns a running libreoffice.org instance. + + :param resolver: The UNO resolver to use to find a running instance. + """ + log.debug('get UNO Desktop Openoffice - resolve') + if connection_type == 'pipe': + return resolver.resolve('uno:pipe,name=openlp_pipe;urp;StarOffice.ComponentContext') + else: + return resolver.resolve('uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext') \ No newline at end of file diff --git a/openlp/core/utils/__init__.py b/openlp/core/utils/__init__.py index 2713973f2..81610c1ab 100644 --- a/openlp/core/utils/__init__.py +++ b/openlp/core/utils/__init__.py @@ -33,7 +33,6 @@ import urllib.parse import urllib.request from http.client import HTTPException from random import randint -from shutil import which from PyQt5 import QtGui @@ -279,36 +278,5 @@ def get_web_page(url, header=None, update_openlp=False): return page -def get_uno_command(connection_type='pipe'): - """ - Returns the UNO command to launch an libreoffice.org instance. - """ - for command in ['libreoffice', 'soffice']: - if which(command): - break - else: - raise FileNotFoundError('Command not found') - - OPTIONS = '--nologo --norestore --minimized --nodefault --nofirststartwizard' - if connection_type == 'pipe': - CONNECTION = '"--accept=pipe,name=openlp_pipe;urp;"' - else: - CONNECTION = '"--accept=socket,host=localhost,port=2002;urp;"' - return '%s %s %s' % (command, OPTIONS, CONNECTION) - - -def get_uno_instance(resolver, connection_type='pipe'): - """ - Returns a running libreoffice.org instance. - - :param resolver: The UNO resolver to use to find a running instance. - """ - log.debug('get UNO Desktop Openoffice - resolve') - if connection_type == 'pipe': - return resolver.resolve('uno:pipe,name=openlp_pipe;urp;StarOffice.ComponentContext') - else: - return resolver.resolve('uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext') - __all__ = ['get_application_version', 'check_latest_version', - 'get_filesystem_encoding', 'get_web_page', 'get_uno_command', 'get_uno_instance', - 'delete_file', 'clean_filename'] + 'get_filesystem_encoding', 'get_web_page', 'delete_file', 'clean_filename'] diff --git a/openlp/plugins/presentations/lib/impresscontroller.py b/openlp/plugins/presentations/lib/impresscontroller.py index 183a05ac5..25844f8b3 100644 --- a/openlp/plugins/presentations/lib/impresscontroller.py +++ b/openlp/plugins/presentations/lib/impresscontroller.py @@ -35,7 +35,7 @@ import logging import os import time -from openlp.core.common import is_win, Registry +from openlp.core.common import is_win, Registry, get_uno_command, get_uno_instance if is_win(): from win32com.client import Dispatch diff --git a/openlp/plugins/songs/lib/importers/openoffice.py b/openlp/plugins/songs/lib/importers/openoffice.py index 5f94d6e77..e8bd60439 100644 --- a/openlp/plugins/songs/lib/importers/openoffice.py +++ b/openlp/plugins/songs/lib/importers/openoffice.py @@ -25,7 +25,7 @@ import time from PyQt5 import QtCore -from openlp.core.common import is_win +from openlp.core.common import is_win, get_uno_command, get_uno_instance from openlp.core.utils import get_uno_command, get_uno_instance from openlp.core.lib import translate from .songimport import SongImport diff --git a/tests/functional/openlp_core_utils/test_init.py b/tests/functional/openlp_core_utils/test_init.py index d01c9f300..c2ff662b3 100644 --- a/tests/functional/openlp_core_utils/test_init.py +++ b/tests/functional/openlp_core_utils/test_init.py @@ -24,7 +24,7 @@ Package to test the openlp.core.utils.actions package. """ from unittest import TestCase -from openlp.core.utils import get_uno_command +from openlp.core.common import get_uno_command from tests.functional import patch from tests.helpers.testmixin import TestMixin diff --git a/tests/functional/openlp_core_utils/test_utils.py b/tests/functional/openlp_core_utils/test_utils.py index 28d890a22..05941431f 100644 --- a/tests/functional/openlp_core_utils/test_utils.py +++ b/tests/functional/openlp_core_utils/test_utils.py @@ -26,7 +26,8 @@ import os from unittest import TestCase from openlp.core.utils import clean_filename, delete_file, get_filesystem_encoding, \ - split_filename, _get_user_agent, get_web_page, get_uno_instance + split_filename, _get_user_agent, get_web_page +from openlp.core.common import get_uno_instance from tests.functional import MagicMock, patch