def test_get_uno_instance_socket(self): """ Test that when the UNO connection type is other than "pipe" the resolver is given the "socket" URI """ # GIVEN: A mock resolver object and UNO_CONNECTION_TYPE is "socket" mock_resolver = MagicMock() # WHEN: get_uno_instance() is called get_uno_instance(mock_resolver, 'socket') # THEN: the resolve method is called with the correct argument mock_resolver.resolve.assert_called_with('uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext')
def test_get_uno_instance_pipe(self): """ Test that when the UNO connection type is "pipe" the resolver is given the "pipe" URI """ # GIVEN: A mock resolver object and UNO_CONNECTION_TYPE is "pipe" mock_resolver = MagicMock() # WHEN: get_uno_instance() is called get_uno_instance(mock_resolver) # THEN: the resolve method is called with the correct argument mock_resolver.resolve.assert_called_with('uno:pipe,name=openlp_pipe;urp;StarOffice.ComponentContext')
def test_get_uno_instance_socket(self): """ Test that when the UNO connection type is other than "pipe" the resolver is given the "socket" URI """ # GIVEN: A mock resolver object and UNO_CONNECTION_TYPE is "socket" mock_resolver = MagicMock() # WHEN: get_uno_instance() is called get_uno_instance(mock_resolver, 'socket') # THEN: the resolve method is called with the correct argument mock_resolver.resolve.assert_called_with('uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext')
def test_get_uno_instance_pipe(self): """ Test that when the UNO connection type is "pipe" the resolver is given the "pipe" URI """ # GIVEN: A mock resolver object and UNO_CONNECTION_TYPE is "pipe" mock_resolver = MagicMock() # WHEN: get_uno_instance() is called get_uno_instance(mock_resolver) # THEN: the resolve method is called with the correct argument mock_resolver.resolve.assert_called_with('uno:pipe,name=openlp_pipe;urp;StarOffice.ComponentContext')
def get_uno_desktop(self): """ On non-Windows platforms, use Uno. Get the OpenOffice desktop which will be used to manage impress. """ log.debug('get UNO Desktop Openoffice') uno_instance = None loop = 0 log.debug('get UNO Desktop Openoffice - getComponentContext') context = uno.getComponentContext() log.debug('get UNO Desktop Openoffice - createInstaneWithContext - UnoUrlResolver') resolver = context.ServiceManager.createInstanceWithContext('com.sun.star.bridge.UnoUrlResolver', context) while uno_instance is None and loop < 3: try: uno_instance = get_uno_instance(resolver) except: log.warning('Unable to find running instance ') self.start_process() loop += 1 try: self.manager = uno_instance.ServiceManager log.debug('get UNO Desktop Openoffice - createInstanceWithContext - Desktop') desktop = self.manager.createInstanceWithContext("com.sun.star.frame.Desktop", uno_instance) return desktop except: log.warning('Failed to get UNO desktop') return None
def start_ooo(self): """ Start OpenOffice.org process TODO: The presentation/Impress plugin may already have it running """ if is_win(): self.start_ooo_process() self.desktop = self.ooo_manager.createInstance('com.sun.star.frame.Desktop') else: context = uno.getComponentContext() resolver = context.ServiceManager.createInstanceWithContext('com.sun.star.bridge.UnoUrlResolver', context) uno_instance = None loop = 0 while uno_instance is None and loop < 5: try: uno_instance = get_uno_instance(resolver) except NoConnectException: time.sleep(0.1) log.exception("Failed to resolve uno connection") self.start_ooo_process() loop += 1 else: manager = uno_instance.ServiceManager self.desktop = manager.createInstanceWithContext("com.sun.star.frame.Desktop", uno_instance) return raise Exception('Unable to start LibreOffice')
def get_uno_desktop(self): """ On non-Windows platforms, use Uno. Get the OpenOffice desktop which will be used to manage impress. """ log.debug('get UNO Desktop Openoffice') uno_instance = None loop = 0 log.debug('get UNO Desktop Openoffice - getComponentContext') context = uno.getComponentContext() log.debug('get UNO Desktop Openoffice - createInstaneWithContext - UnoUrlResolver') resolver = context.ServiceManager.createInstanceWithContext('com.sun.star.bridge.UnoUrlResolver', context) while uno_instance is None and loop < 3: try: uno_instance = get_uno_instance(resolver) except: log.warning('Unable to find running instance ') self.start_process() loop += 1 try: self.manager = uno_instance.ServiceManager log.debug('get UNO Desktop Openoffice - createInstanceWithContext - Desktop') desktop = self.manager.createInstanceWithContext("com.sun.star.frame.Desktop", uno_instance) return desktop except: log.warning('Failed to get UNO desktop') return None
def start_ooo(self): """ Start OpenOffice.org process TODO: The presentation/Impress plugin may already have it running """ if is_win(): self.start_ooo_process() self.desktop = self.ooo_manager.createInstance( 'com.sun.star.frame.Desktop') else: context = uno.getComponentContext() resolver = context.ServiceManager.createInstanceWithContext( 'com.sun.star.bridge.UnoUrlResolver', context) uno_instance = None loop = 0 while uno_instance is None and loop < 5: try: uno_instance = get_uno_instance(resolver) except NoConnectException: time.sleep(0.1) log.exception("Failed to resolve uno connection") self.start_ooo_process() loop += 1 else: manager = uno_instance.ServiceManager self.desktop = manager.createInstanceWithContext( "com.sun.star.frame.Desktop", uno_instance) return raise Exception('Unable to start LibreOffice')