forked from openlp/openlp
Get Pyro working again
This commit is contained in:
parent
64251747fb
commit
62b0eedfc6
|
@ -134,8 +134,8 @@ def extension_loader(glob_pattern, excluded_files=[]):
|
|||
importlib.import_module(module_name)
|
||||
except (ImportError, OSError):
|
||||
# On some platforms importing vlc.py might cause OSError exceptions. (e.g. Mac OS X)
|
||||
log.warning('Failed to import {module_name} on path {extension_path}'
|
||||
.format(module_name=module_name, extension_path=extension_path))
|
||||
log.exception('Failed to import {module_name} on path {extension_path}'
|
||||
.format(module_name=module_name, extension_path=extension_path))
|
||||
|
||||
|
||||
def path_to_module(path):
|
||||
|
|
|
@ -170,6 +170,8 @@ class MediaController(RegistryBase, LogMixin, RegistryProperties):
|
|||
if get_vlc() and pymediainfo_available:
|
||||
State().update_pre_conditions("mediacontroller", True)
|
||||
else:
|
||||
if hasattr(self.main_window, 'splash') and self.main_window.splash.isVisible():
|
||||
self.main_window.splash.hide()
|
||||
State().missing_text("mediacontroller", translate('OpenLP.SlideController',
|
||||
"VLC or pymediainfo are missing, so you are unable to play any media"))
|
||||
self._generate_extensions_lists()
|
||||
|
|
|
@ -159,6 +159,8 @@ class VlcPlayer(MediaPlayer):
|
|||
:return:
|
||||
"""
|
||||
vlc = get_vlc()
|
||||
if not vlc:
|
||||
return
|
||||
display.vlc_widget = QtWidgets.QFrame(display)
|
||||
display.vlc_widget.setFrameStyle(QtWidgets.QFrame.NoFrame)
|
||||
# creating a basic vlc instance
|
||||
|
|
|
@ -28,9 +28,19 @@ import os
|
|||
import logging
|
||||
import time
|
||||
|
||||
|
||||
if sys.platform.startswith('darwin'):
|
||||
print('Setting up log file')
|
||||
# Only make the log file on OS X when running as a server
|
||||
logfile = os.path.join(str(os.getenv('HOME')), 'Library', 'Application Support', 'openlp', 'libreofficeserver.log')
|
||||
logging.basicConfig(filename=logfile, level=logging.INFO)
|
||||
|
||||
|
||||
# Add the vendor directory to sys.path so that we can load Pyro4
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__)))
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__), 'vendor'))
|
||||
|
||||
from serializers import register_classes
|
||||
from Pyro4 import Daemon, expose
|
||||
|
||||
try:
|
||||
|
@ -38,18 +48,15 @@ try:
|
|||
import uno
|
||||
from com.sun.star.beans import PropertyValue
|
||||
from com.sun.star.task import ErrorCodeIOException
|
||||
except:
|
||||
except ImportError as e:
|
||||
# But they need to be defined for mocking
|
||||
print(e)
|
||||
uno = None
|
||||
PropertyValue = None
|
||||
ErrorCodeIOException = Exception
|
||||
|
||||
if sys.platform.startswith('darwin') and uno is not None:
|
||||
# Only make the log file on OS X when running as a server
|
||||
logfile = os.path.join(str(os.getenv('HOME')), 'Library', 'Application Support', 'openlp', 'libreofficeserver.log')
|
||||
logging.basicConfig(filename=logfile, level=logging.INFO)
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
register_classes()
|
||||
|
||||
|
||||
class TextType(object):
|
||||
|
@ -77,6 +84,7 @@ class LibreOfficeServer(object):
|
|||
"""
|
||||
Set up the server
|
||||
"""
|
||||
self._desktop = None
|
||||
self._control = None
|
||||
self._document = None
|
||||
self._presentation = None
|
||||
|
@ -128,7 +136,7 @@ class LibreOfficeServer(object):
|
|||
'--minimized',
|
||||
'--nodefault',
|
||||
'--nofirststartwizard',
|
||||
'--accept=socket,host=localhost,port=2002;urp;StarOffice.ServiceManager'
|
||||
'--accept=pipe,name=openlp_maclo;urp;StarOffice.ServiceManager'
|
||||
]
|
||||
self._process = Popen(uno_command)
|
||||
|
||||
|
@ -137,15 +145,17 @@ class LibreOfficeServer(object):
|
|||
"""
|
||||
Set up an UNO desktop instance
|
||||
"""
|
||||
if self._desktop is not None:
|
||||
return self._desktop
|
||||
uno_instance = None
|
||||
context = uno.getComponentContext()
|
||||
resolver = context.ServiceManager.createInstanceWithContext('com.sun.star.bridge.UnoUrlResolver', context)
|
||||
loop = 0
|
||||
while uno_instance is None and loop < 3:
|
||||
try:
|
||||
uno_instance = resolver.resolve('uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext')
|
||||
except Exception as e:
|
||||
log.warning('Unable to find running instance ')
|
||||
uno_instance = resolver.resolve('uno:pipe,name=openlp_maclo;urp;StarOffice.ComponentContext')
|
||||
except Exception:
|
||||
log.exception('Unable to find running instance, retrying...')
|
||||
loop += 1
|
||||
try:
|
||||
manager = uno_instance.ServiceManager
|
||||
|
@ -153,9 +163,11 @@ class LibreOfficeServer(object):
|
|||
desktop = manager.createInstanceWithContext('com.sun.star.frame.Desktop', uno_instance)
|
||||
if not desktop:
|
||||
raise Exception('Failed to get UNO desktop')
|
||||
self._desktop = desktop
|
||||
return desktop
|
||||
except Exception as e:
|
||||
log.warning('Failed to get UNO desktop')
|
||||
except Exception:
|
||||
log.exception('Failed to get UNO desktop')
|
||||
return None
|
||||
|
||||
def shutdown(self):
|
||||
"""
|
||||
|
@ -180,8 +192,8 @@ class LibreOfficeServer(object):
|
|||
try:
|
||||
self.desktop.terminate()
|
||||
log.debug('LibreOffice killed')
|
||||
except:
|
||||
log.warning('Failed to terminate LibreOffice')
|
||||
except Exception:
|
||||
log.exception('Failed to terminate LibreOffice')
|
||||
if getattr(self, '_process') and can_kill:
|
||||
self._process.kill()
|
||||
|
||||
|
@ -189,15 +201,21 @@ class LibreOfficeServer(object):
|
|||
"""
|
||||
Load a presentation
|
||||
"""
|
||||
self._file_path = file_path
|
||||
url = uno.systemPathToFileUrl(file_path)
|
||||
properties = (self._create_property('Hidden', True),)
|
||||
retries = 0
|
||||
properties = [self._create_property('Hidden', True)]
|
||||
self._document = None
|
||||
try:
|
||||
self._document = self.desktop.loadComponentFromURL(url, '_blank', 0, properties)
|
||||
except:
|
||||
log.warning('Failed to load presentation {url}'.format(url=url))
|
||||
loop_count = 0
|
||||
while loop_count < 3:
|
||||
try:
|
||||
self._document = self.desktop.loadComponentFromURL(url, '_blank', 0, properties)
|
||||
except Exception:
|
||||
log.exception('Failed to load presentation {url}'.format(url=url))
|
||||
if self._document:
|
||||
break
|
||||
time.sleep(0.5)
|
||||
loop_count += 1
|
||||
if loop_count == 3:
|
||||
log.error('Looped too many times')
|
||||
return False
|
||||
self._presentation = self._document.getPresentation()
|
||||
self._presentation.Display = screen_number
|
||||
|
@ -226,7 +244,7 @@ class LibreOfficeServer(object):
|
|||
thumbnails.append(path)
|
||||
except ErrorCodeIOException as exception:
|
||||
log.exception('ERROR! ErrorCodeIOException {error:d}'.format(error=exception.ErrCode))
|
||||
except:
|
||||
except Exception:
|
||||
log.exception('{path} - Unable to store openoffice preview'.format(path=path))
|
||||
return thumbnails
|
||||
|
||||
|
@ -256,8 +274,8 @@ class LibreOfficeServer(object):
|
|||
self._presentation.end()
|
||||
self._presentation = None
|
||||
self._document.dispose()
|
||||
except:
|
||||
log.warning("Closing presentation failed")
|
||||
except Exception:
|
||||
log.exception("Closing presentation failed")
|
||||
self._document = None
|
||||
|
||||
def is_loaded(self):
|
||||
|
@ -272,8 +290,8 @@ class LibreOfficeServer(object):
|
|||
if self._document.getPresentation() is None:
|
||||
log.debug("getPresentation failed to find a presentation")
|
||||
return False
|
||||
except:
|
||||
log.warning("getPresentation failed to find a presentation")
|
||||
except Exception:
|
||||
log.exception("getPresentation failed to find a presentation")
|
||||
return False
|
||||
return True
|
||||
|
||||
|
|
|
@ -22,25 +22,26 @@
|
|||
|
||||
import logging
|
||||
import os
|
||||
import time
|
||||
from pathlib import Path
|
||||
from subprocess import Popen
|
||||
|
||||
from openlp.core.common import AppLocation, Registry, delete_file, is_macosx
|
||||
from Pyro4 import Proxy
|
||||
|
||||
from openlp.core.common import is_macosx, delete_file
|
||||
from openlp.core.common.applocation import AppLocation
|
||||
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.serializers import register_classes
|
||||
from openlp.plugins.presentations.lib.presentationcontroller import PresentationController, PresentationDocument
|
||||
|
||||
if is_macosx() and os.path.exists('/Applications/LibreOffice.app'):
|
||||
macuno_available = True
|
||||
else:
|
||||
macuno_available = False
|
||||
|
||||
from PyQt5 import QtCore
|
||||
from Pyro4 import Proxy
|
||||
|
||||
from openlp.core.lib import ScreenList
|
||||
from .presentationcontroller import PresentationController, PresentationDocument, TextType
|
||||
|
||||
|
||||
log = logging.getLogger(__name__)
|
||||
register_classes()
|
||||
|
||||
|
||||
class MacLOController(PresentationController):
|
||||
|
@ -125,7 +126,7 @@ class MacLODocument(PresentationDocument):
|
|||
Tell the LibreOfficeServer to start the presentation.
|
||||
"""
|
||||
log.debug('Load Presentation LibreOffice')
|
||||
if not self.client.load_presentation(self.file_path, ScreenList().current['number'] + 1):
|
||||
if not self.client.load_presentation(str(self.file_path), ScreenList().current['number'] + 1):
|
||||
return False
|
||||
self.create_thumbnails()
|
||||
self.create_titles_and_notes()
|
||||
|
@ -138,8 +139,9 @@ class MacLODocument(PresentationDocument):
|
|||
log.debug('create thumbnails LibreOffice')
|
||||
if self.check_thumbnails():
|
||||
return
|
||||
temp_thumbnails = self.client.extract_thumbnails(self.get_temp_folder())
|
||||
temp_thumbnails = self.client.extract_thumbnails(str(self.get_temp_folder()))
|
||||
for index, temp_thumb in enumerate(temp_thumbnails):
|
||||
temp_thumb = Path(temp_thumb)
|
||||
self.convert_thumbnail(temp_thumb, index + 1)
|
||||
delete_file(temp_thumb)
|
||||
|
||||
|
|
|
@ -0,0 +1,28 @@
|
|||
try:
|
||||
from openlp.core.common.path import Path
|
||||
except ImportError:
|
||||
from pathlib import Path
|
||||
|
||||
from Pyro4.util import SerializerBase
|
||||
|
||||
|
||||
def path_class_to_dict(obj):
|
||||
"""
|
||||
Serialize a Path object for Pyro4
|
||||
"""
|
||||
return {
|
||||
'__class__': 'Path',
|
||||
'parts': obj.parts
|
||||
}
|
||||
|
||||
|
||||
def path_dict_to_class(classname, d):
|
||||
return Path(d['parts'])
|
||||
|
||||
|
||||
def register_classes():
|
||||
"""
|
||||
Register the serializers
|
||||
"""
|
||||
SerializerBase.register_class_to_dict(Path, path_class_to_dict)
|
||||
SerializerBase.register_dict_to_class('Path', path_dict_to_class)
|
Loading…
Reference in New Issue