Exemplo n.º 1
0
def _get_os_dir_path(dir_type):
    """
    Return a path based on which OS and environment we are running in.

    :param dir_type: AppLocation Enum of the requested path type
    :return: The requested path
    :rtype: openlp.core.common.path.Path
    """
    # If running from source, return the language directory from the source directory
    if dir_type == AppLocation.LanguageDir:
        directory = Path(openlp.__file__, '..', '..').resolve() / 'resources'
        if directory.exists():
            return directory
    if is_win():
        openlp_folder_path = Path(os.getenv('APPDATA'), 'openlp')
        if dir_type == AppLocation.DataDir:
            return openlp_folder_path / 'data'
        elif dir_type == AppLocation.LanguageDir:
            return Path(openlp.__file__).parent
        return openlp_folder_path
    elif is_macosx():
        openlp_folder_path = Path(os.getenv('HOME'), 'Library',
                                  'Application Support', 'openlp')
        if dir_type == AppLocation.DataDir:
            return openlp_folder_path / 'Data'
        elif dir_type == AppLocation.LanguageDir:
            return Path(openlp.__file__).parent
        return openlp_folder_path
    else:
        if dir_type == AppLocation.LanguageDir:
            directory = Path('/usr', 'local', 'share', 'openlp')
            if directory.exists():
                return directory
            return Path('/usr', 'share', 'openlp')
        if XDG_BASE_AVAILABLE:
            if dir_type == AppLocation.DataDir:
                return Path(BaseDirectory.xdg_data_home, 'openlp')
            elif dir_type == AppLocation.CacheDir:
                return Path(BaseDirectory.xdg_cache_home, 'openlp')
        if dir_type == AppLocation.DataDir:
            return Path(os.getenv('HOME'), '.openlp', 'data')
        return Path(os.getenv('HOME'), '.openlp')
Exemplo n.º 2
0
 def _start_server(self):
     """
     Start a LibreOfficeServer
     """
     libreoffice_python = Path(
         '/Applications/LibreOffice.app/Contents/Resources/python')
     libreoffice_server = AppLocation.get_directory(
         AppLocation.PluginsDir).joinpath('presentations', 'lib',
                                          'libreofficeserver.py')
     if libreoffice_python.exists():
         self.server_process = Popen(
             [str(libreoffice_python),
              str(libreoffice_server)])
Exemplo n.º 3
0
    def export(self, dest_path):
        """
        Export the settings to file.

        :param openlp.core.common.path.Path dest_path: The file path to create the export file.
        :return: Success
        :rtype: bool
        """
        temp_path = Path(gettempdir(), 'openlp', 'exportConf.tmp')
        # Delete old files if found.
        if temp_path.exists():
            temp_path.unlink()
        if dest_path.exists():
            dest_path.unlink()
        self.remove('SettingsImport')
        # Get the settings.
        keys = self.allKeys()
        export_settings = QtCore.QSettings(str(temp_path), Settings.IniFormat)
        # Add a header section.
        # This is to insure it's our conf file for import.
        now = datetime.datetime.now()
        # Write INI format using QSettings.
        # Write our header.
        export_settings.beginGroup('SettingsImport')
        export_settings.setValue('Make_Changes', 'At_Own_RISK')
        export_settings.setValue('type', 'OpenLP_settings_export')
        export_settings.setValue('file_date_created', now.strftime("%Y-%m-%d %H:%M"))
        export_settings.endGroup()
        # Write all the sections and keys.
        for section_key in keys:
            # FIXME: We are conflicting with the standard "General" section.
            if 'eneral' in section_key:
                section_key = section_key.lower()
            key_value = super().value(section_key)
            if key_value is not None:
                export_settings.setValue(section_key, key_value)
        export_settings.sync()
        # Temp CONF file has been written.  Blanks in keys are now '%20'.
        # Read the  temp file and output the user's CONF file with blanks to
        # make it more readable.
        try:
            with dest_path.open('w') as export_conf_file, temp_path.open('r') as temp_conf:
                for file_record in temp_conf:
                    # Get rid of any invalid entries.
                    if file_record.find('@Invalid()') == -1:
                        file_record = file_record.replace('%20', ' ')
                        export_conf_file.write(file_record)
        finally:
            temp_path.unlink()
Exemplo n.º 4
0
from subprocess import Popen

from openlp.core.common import delete_file, is_macosx
from openlp.core.common.applocation import AppLocation
from openlp.core.common.mixins import LogMixin
from openlp.core.common.path import Path
from openlp.core.common.registry import Registry
from openlp.core.display.screens import ScreenList
from openlp.plugins.presentations.lib.presentationcontroller import PresentationController, PresentationDocument

LIBREOFFICE_PATH = Path('/Applications/LibreOffice.app')
LIBREOFFICE_PYTHON = LIBREOFFICE_PATH / 'Contents' / 'Resources' / 'python'

try:
    from Pyro4 import Proxy
    if is_macosx() and LIBREOFFICE_PATH.exists():
        macuno_available = True
    else:
        macuno_available = False
except ImportError:
    macuno_available = False

if macuno_available:
    # If this controller is good to go, register the serializer classes with Pyro4
    from openlp.plugins.presentations.lib.serializers import register_classes
    register_classes()

log = logging.getLogger(__name__)


class MacLOController(PresentationController, LogMixin):