Exemplo n.º 1
0
    def check_installed(self):
        """
        Check the viewer is installed.

        :return: True if program to open PDF-files was found, otherwise False.
        """
        log.debug('check_installed Pdf')
        self.mudrawbin = None
        self.mutoolbin = None
        self.gsbin = None
        self.also_supports = []
        # Use the user defined program if given
        if Settings().value('presentations/enable_pdf_program'):
            program_path = Settings().value('presentations/pdf_program')
            program_type = self.process_check_binary(program_path)
            if program_type == 'gs':
                self.gsbin = program_path
            elif program_type == 'mudraw':
                self.mudrawbin = program_path
            elif program_type == 'mutool':
                self.mutoolbin = program_path
        else:
            # Fallback to autodetection
            application_path = AppLocation.get_directory(AppLocation.AppDir)
            if is_win():
                # for windows we only accept mudraw.exe or mutool.exe in the base folder
                if (application_path / 'mudraw.exe').is_file():
                    self.mudrawbin = application_path / 'mudraw.exe'
                elif (application_path / 'mutool.exe').is_file():
                    self.mutoolbin = application_path / 'mutool.exe'
            else:
                # First try to find mudraw
                self.mudrawbin = which('mudraw')
                # if mudraw isn't installed, try mutool
                if not self.mudrawbin:
                    self.mutoolbin = which('mutool')
                    # Check we got a working mutool
                    if not self.mutoolbin or self.process_check_binary(
                            self.mutoolbin) != 'mutool':
                        self.gsbin = which('gs')
                # Last option: check if mudraw or mutool is placed in OpenLP base folder
                if not self.mudrawbin and not self.mutoolbin and not self.gsbin:
                    application_path = AppLocation.get_directory(
                        AppLocation.AppDir)
                    if (application_path / 'mudraw').is_file():
                        self.mudrawbin = application_path / 'mudraw'
                    elif (application_path / 'mutool').is_file():
                        self.mutoolbin = application_path / 'mutool'
        if self.mudrawbin or self.mutoolbin:
            self.also_supports = ['xps', 'oxps']
            return True
        elif self.gsbin:
            return True
        else:
            return False
Exemplo n.º 2
0
    def test_which_no_command(self):
        """
        Test :func:`openlp.core.common.path.which` when the command is not found.
        """
        # GIVEN: A mocked :func:`shutil.which` when the command is not found.
        with patch('openlp.core.common.path.shutil.which',
                   return_value=None) as mocked_shutil_which:

            # WHEN: Calling :func:`openlp.core.common.path.which` with a command that does not exist.
            result = which('no_command')

            # THEN: :func:`shutil.which` should have been called with the command, and :func:`which` should return None.
            mocked_shutil_which.assert_called_once_with('no_command')
        assert result is None
Exemplo n.º 3
0
    def test_which_command(self):
        """
        Test :func:`openlp.core.common.path.which` when a command has been found.
        """
        # GIVEN: A mocked :func:`shutil.which` when the command is found.
        with patch('openlp.core.common.path.shutil.which',
                   return_value=os.path.join(
                       'path', 'to', 'command')) as mocked_shutil_which:

            # WHEN: Calling :func:`openlp.core.common.path.which` with a command that exists.
            result = which('command')

            # THEN: :func:`shutil.which` should have been called with the command, and :func:`which` should return a
            #       Path object equivalent of the command path.
            mocked_shutil_which.assert_called_once_with('command')
            assert result == Path('path', 'to', 'command')