uno commands

This commit is contained in:
Tim Bentley 2016-04-04 21:14:04 +01:00
parent 98a021b89f
commit 85587ce2f3
6 changed files with 38 additions and 37 deletions

View File

@ -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')

View File

@ -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']

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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