fix plugin loading

This commit is contained in:
Tim Bentley 2018-10-26 19:30:59 +01:00
parent 9546c1d9bf
commit 20dc4f81ed
12 changed files with 73 additions and 67 deletions

View File

@ -129,6 +129,9 @@ class MediaManagerItem(QtWidgets.QWidget, RegistryProperties):
self.has_file_icon = False self.has_file_icon = False
self.has_delete_icon = True self.has_delete_icon = True
self.add_to_service_item = False self.add_to_service_item = False
self.can_preview = True
self.can_make_live = True
self.can_add_to_service = True
def retranslateUi(self): def retranslateUi(self):
""" """
@ -210,27 +213,30 @@ class MediaManagerItem(QtWidgets.QWidget, RegistryProperties):
icon=UiIcons().edit, icon=UiIcons().edit,
triggers=self.on_edit_click) triggers=self.on_edit_click)
create_widget_action(self.list_view, separator=True) create_widget_action(self.list_view, separator=True)
create_widget_action(self.list_view, if self.can_preview:
'listView{plugin}{preview}Item'.format(plugin=self.plugin.name.title(), create_widget_action(self.list_view,
preview=StringContent.Preview.title()), 'listView{plugin}{preview}Item'.format(plugin=self.plugin.name.title(),
text=self.plugin.get_string(StringContent.Preview)['title'], preview=StringContent.Preview.title()),
icon=UiIcons().preview, text=self.plugin.get_string(StringContent.Preview)['title'],
can_shortcuts=True, icon=UiIcons().preview,
triggers=self.on_preview_click) can_shortcuts=True,
create_widget_action(self.list_view, triggers=self.on_preview_click)
'listView{plugin}{live}Item'.format(plugin=self.plugin.name.title(), if self.can_make_live:
live=StringContent.Live.title()), create_widget_action(self.list_view,
text=self.plugin.get_string(StringContent.Live)['title'], 'listView{plugin}{live}Item'.format(plugin=self.plugin.name.title(),
icon=UiIcons().live, live=StringContent.Live.title()),
can_shortcuts=True, text=self.plugin.get_string(StringContent.Live)['title'],
triggers=self.on_live_click) icon=UiIcons().live,
create_widget_action(self.list_view, can_shortcuts=True,
'listView{plugin}{service}Item'.format(plugin=self.plugin.name.title(), triggers=self.on_live_click)
service=StringContent.Service.title()), if self.can_add_to_service:
can_shortcuts=True, create_widget_action(self.list_view,
text=self.plugin.get_string(StringContent.Service)['title'], 'listView{plugin}{service}Item'.format(plugin=self.plugin.name.title(),
icon=UiIcons().add, service=StringContent.Service.title()),
triggers=self.on_add_click) can_shortcuts=True,
text=self.plugin.get_string(StringContent.Service)['title'],
icon=UiIcons().add,
triggers=self.on_add_click)
if self.has_delete_icon: if self.has_delete_icon:
create_widget_action(self.list_view, separator=True) create_widget_action(self.list_view, separator=True)
create_widget_action(self.list_view, create_widget_action(self.list_view,

View File

@ -103,6 +103,7 @@ class PluginManager(RegistryBase, LogMixin, RegistryProperties):
""" """
Create the plugins' media manager items. Create the plugins' media manager items.
""" """
aa = State().list_plugins()
for plugin in State().list_plugins(): for plugin in State().list_plugins():
if plugin.status is not PluginStatus.Disabled: if plugin.status is not PluginStatus.Disabled:
plugin.create_media_manager_item() plugin.create_media_manager_item()
@ -114,7 +115,7 @@ class PluginManager(RegistryBase, LogMixin, RegistryProperties):
Tabs are set for all plugins not just Active ones Tabs are set for all plugins not just Active ones
""" """
for plugin in self.plugins: for plugin in State().list_plugins():
if plugin.status is not PluginStatus.Disabled: if plugin.status is not PluginStatus.Disabled:
plugin.create_settings_tab(self.settings_form) plugin.create_settings_tab(self.settings_form)
@ -124,7 +125,7 @@ class PluginManager(RegistryBase, LogMixin, RegistryProperties):
item to the import menu. item to the import menu.
""" """
for plugin in self.plugins: for plugin in State().list_plugins():
if plugin.status is not PluginStatus.Disabled: if plugin.status is not PluginStatus.Disabled:
plugin.add_import_menu_item(self.main_window.file_import_menu) plugin.add_import_menu_item(self.main_window.file_import_menu)
@ -133,7 +134,7 @@ class PluginManager(RegistryBase, LogMixin, RegistryProperties):
Loop through all the plugins and give them an opportunity to add an Loop through all the plugins and give them an opportunity to add an
item to the export menu. item to the export menu.
""" """
for plugin in self.plugins: for plugin in State().list_plugins():
if plugin.status is not PluginStatus.Disabled: if plugin.status is not PluginStatus.Disabled:
plugin.add_export_menu_item(self.main_window.file_export_menu) plugin.add_export_menu_item(self.main_window.file_export_menu)
@ -142,7 +143,7 @@ class PluginManager(RegistryBase, LogMixin, RegistryProperties):
Loop through all the plugins and give them an opportunity to add an Loop through all the plugins and give them an opportunity to add an
item to the tools menu. item to the tools menu.
""" """
for plugin in self.plugins: for plugin in State().list_plugins():
if plugin.status is not PluginStatus.Disabled: if plugin.status is not PluginStatus.Disabled:
plugin.add_tools_menu_item(self.main_window.tools_menu) plugin.add_tools_menu_item(self.main_window.tools_menu)
@ -152,7 +153,7 @@ class PluginManager(RegistryBase, LogMixin, RegistryProperties):
:param settings: The Settings object containing the old settings. :param settings: The Settings object containing the old settings.
""" """
for plugin in self.plugins: for plugin in State().list_plugins():
if plugin.status is not PluginStatus.Disabled: if plugin.status is not PluginStatus.Disabled:
plugin.upgrade_settings(settings) plugin.upgrade_settings(settings)
@ -160,7 +161,7 @@ class PluginManager(RegistryBase, LogMixin, RegistryProperties):
""" """
Loop through all the plugins and give them an opportunity to initialise themselves. Loop through all the plugins and give them an opportunity to initialise themselves.
""" """
for plugin in self.plugins: for plugin in State().list_plugins():
self.log_info('initialising plugins {plugin} in a {state} state'.format(plugin=plugin.name, self.log_info('initialising plugins {plugin} in a {state} state'.format(plugin=plugin.name,
state=plugin.is_active())) state=plugin.is_active()))
if plugin.is_active(): if plugin.is_active():
@ -171,7 +172,7 @@ class PluginManager(RegistryBase, LogMixin, RegistryProperties):
""" """
Loop through all the plugins and give them an opportunity to clean themselves up Loop through all the plugins and give them an opportunity to clean themselves up
""" """
for plugin in self.plugins: for plugin in State().list_plugins():
if plugin.is_active(): if plugin.is_active():
plugin.finalise() plugin.finalise()
self.log_info('Finalisation Complete for {plugin}'.format(plugin=plugin.name)) self.log_info('Finalisation Complete for {plugin}'.format(plugin=plugin.name))
@ -180,7 +181,7 @@ class PluginManager(RegistryBase, LogMixin, RegistryProperties):
""" """
Return the plugin which has a name with value ``name``. Return the plugin which has a name with value ``name``.
""" """
for plugin in self.plugins: for plugin in State().list_plugins():
if plugin.name == name: if plugin.name == name:
return plugin return plugin
return None return None
@ -189,6 +190,6 @@ class PluginManager(RegistryBase, LogMixin, RegistryProperties):
""" """
Loop through all the plugins and give them an opportunity to handle a new service Loop through all the plugins and give them an opportunity to handle a new service
""" """
for plugin in self.plugins: for plugin in State().list_plugins():
if plugin.is_active(): if plugin.is_active():
plugin.new_service_created() plugin.new_service_created()

View File

@ -28,6 +28,7 @@ logging and a plugin framework are contained within the openlp.core module.
""" """
import logging import logging
from openlp.core.common.registry import Registry
from openlp.core.common.mixins import LogMixin from openlp.core.common.mixins import LogMixin
from openlp.core.lib.plugin import PluginStatus from openlp.core.lib.plugin import PluginStatus
@ -42,7 +43,7 @@ class StateModule(LogMixin):
super(StateModule, self).__init__() super(StateModule, self).__init__()
self.name = None self.name = None
self.order = 0 self.order = 0
self.isPlugin = None self.is_plugin = None
self.status = PluginStatus.Inactive self.status = PluginStatus.Inactive
self.pass_preconditions = True self.pass_preconditions = True
self.requires = None self.requires = None
@ -67,12 +68,12 @@ class State(LogMixin):
def save_settings(self): def save_settings(self):
pass pass
def add_service(self, name, order, isPlugin=False, status=PluginStatus.Active, requires=None): def add_service(self, name, order, is_plugin=False, status=PluginStatus.Active, requires=None):
""" """
Add a module to the array and lod dependancies. There will only be one item per module Add a module to the array and lod dependancies. There will only be one item per module
:param name: Module name :param name: Module name
:param order: Order fo display :param order: Order to display
:param isPlugin: Am I a plugin :param is_plugin: Am I a plugin
:param status: The active status :param status: The active status
:param requires: Module name this requires :param requires: Module name this requires
:return: :return:
@ -81,7 +82,7 @@ class State(LogMixin):
state = StateModule() state = StateModule()
state.name = name state.name = name
state.order = order state.order = order
state.plugin = isPlugin state.is_plugin = is_plugin
state.status = status state.status = status
state.requires = requires state.requires = requires
state.required_by = [] state.required_by = []
@ -99,6 +100,13 @@ class State(LogMixin):
:return: :return:
""" """
self.modules[name].pass_preconditions = status self.modules[name].pass_preconditions = status
if self.modules[name].is_plugin:
plugin = Registry().get('{mod}_plugin'.format(mod=name))
if status:
self.log_debug('Plugin {plugin} active'.format(plugin=str(plugin.name)))
plugin.set_status()
else:
plugin.status = PluginStatus.Disabled
def flush_preconditions(self): def flush_preconditions(self):
""" """
@ -109,7 +117,11 @@ class State(LogMixin):
for mods in self.modules: for mods in self.modules:
for req in self.modules[mods].required_by: for req in self.modules[mods].required_by:
self.modules[req].pass_preconditions = self.modules[mods].pass_preconditions self.modules[req].pass_preconditions = self.modules[mods].pass_preconditions
# plugins_list = sorted(plugin_objects, key=lambda plugin: plugin.weight) plugins_list = sorted(self.modules, key=lambda state: self.modules[state].order)
mdl = {}
for pl in plugins_list:
mdl[pl] = self.modules[pl]
self.modules = mdl
def is_module_active(self, name): def is_module_active(self, name):
return self.modules[name].status == PluginStatus.Active return self.modules[name].status == PluginStatus.Active
@ -130,6 +142,6 @@ class State(LogMixin):
def list_plugins(self): def list_plugins(self):
plugins = [] plugins = []
for mod in self.modules: for mod in self.modules:
if mod.isPlugin: if self.modules[mod].is_plugin:
plugins.append(mod.name) plugins.append(Registry().get('{mod}_plugin'.format(mod=mod)))
return plugins return plugins

View File

@ -147,7 +147,7 @@ class AlertsPlugin(Plugin):
self.alert_form = AlertForm(self) self.alert_form = AlertForm(self)
register_endpoint(alerts_endpoint) register_endpoint(alerts_endpoint)
register_endpoint(api_alerts_endpoint) register_endpoint(api_alerts_endpoint)
State().add_service(self.name, self.weight, isPlugin=True) State().add_service(self.name, self.weight, is_plugin=True)
State().update_pre_conditions(self.name, self.check_pre_conditions()) State().update_pre_conditions(self.name, self.check_pre_conditions())
def add_tools_menu_item(self, tools_menu): def add_tools_menu_item(self, tools_menu):

View File

@ -77,8 +77,8 @@ class BiblePlugin(Plugin):
self.manager = BibleManager(self) self.manager = BibleManager(self)
register_endpoint(bibles_endpoint) register_endpoint(bibles_endpoint)
register_endpoint(api_bibles_endpoint) register_endpoint(api_bibles_endpoint)
State().add_service(self.name, self.weight, isPlugin=True) State().add_service('bible', self.weight, is_plugin=True)
State().update_pre_conditions(self.name, self.check_pre_conditions()) State().update_pre_conditions('bible', self.check_pre_conditions())
def initialise(self): def initialise(self):
""" """

View File

@ -69,7 +69,7 @@ class CustomPlugin(Plugin):
self.icon = build_icon(self.icon_path) self.icon = build_icon(self.icon_path)
register_endpoint(custom_endpoint) register_endpoint(custom_endpoint)
register_endpoint(api_custom_endpoint) register_endpoint(api_custom_endpoint)
State().add_service(self.name, self.weight, isPlugin=True) State().add_service(self.name, self.weight, is_plugin=True)
State().update_pre_conditions(self.name, self.check_pre_conditions()) State().update_pre_conditions(self.name, self.check_pre_conditions())
@staticmethod @staticmethod

View File

@ -60,8 +60,8 @@ class ImagePlugin(Plugin):
self.icon = build_icon(self.icon_path) self.icon = build_icon(self.icon_path)
register_endpoint(images_endpoint) register_endpoint(images_endpoint)
register_endpoint(api_images_endpoint) register_endpoint(api_images_endpoint)
State().add_service(self.name, self.weight, isPlugin=True) State().add_service('image', self.weight, is_plugin=True)
State().update_pre_conditions(self.name, self.check_pre_conditions()) State().update_pre_conditions('image', self.check_pre_conditions())
@staticmethod @staticmethod
def about(): def about():

View File

@ -112,6 +112,10 @@ class MediaMediaItem(MediaManagerItem, RegistryProperties):
self.has_file_icon = True self.has_file_icon = True
self.has_new_icon = False self.has_new_icon = False
self.has_edit_icon = False self.has_edit_icon = False
if not State().check_preconditions('media'):
self.can_preview = False
self.can_make_live = False
self.can_add_to_service = False
def add_list_view_to_toolbar(self): def add_list_view_to_toolbar(self):
""" """

View File

@ -65,7 +65,7 @@ class MediaPlugin(Plugin):
self.dnd_id = 'Media' self.dnd_id = 'Media'
register_endpoint(media_endpoint) register_endpoint(media_endpoint)
register_endpoint(api_media_endpoint) register_endpoint(api_media_endpoint)
State().add_service(self.name, self.weight, requires='mediacontroller') State().add_service(self.name, self.weight, requires='mediacontroller', is_plugin=True)
State().update_pre_conditions(self.name, self.check_pre_conditions()) State().update_pre_conditions(self.name, self.check_pre_conditions())
def initialise(self): def initialise(self):
@ -149,20 +149,3 @@ class MediaPlugin(Plugin):
# Add html code to htmlbuilder. # Add html code to htmlbuilder.
# """ # """
# return self.media_controller.get_media_display_html() # return self.media_controller.get_media_display_html()
def process_check_binary(program_path):
"""
Function that checks whether a binary MediaInfo is present
:param openlp.core.common.path.Path program_path:The full path to the binary to check.
:return: If exists or not
:rtype: bool
"""
runlog = check_binary_exists(program_path)
# Analyse the output to see it the program is mediainfo
for line in runlog.splitlines():
decoded_line = line.decode()
if re.search('MediaInfo Command line', decoded_line, re.IGNORECASE):
return True
return False

View File

@ -75,8 +75,8 @@ class PresentationPlugin(Plugin):
self.icon = build_icon(self.icon_path) self.icon = build_icon(self.icon_path)
register_endpoint(presentations_endpoint) register_endpoint(presentations_endpoint)
register_endpoint(api_presentations_endpoint) register_endpoint(api_presentations_endpoint)
State().add_service(self.name, self.weight, isPlugin=True) State().add_service('presentation', self.weight, is_plugin=True)
State().update_pre_conditions(self.name, self.check_pre_conditions()) State().update_pre_conditions('presentation', self.check_pre_conditions())
def create_settings_tab(self, parent): def create_settings_tab(self, parent):
""" """

View File

@ -100,7 +100,7 @@ class SongsPlugin(Plugin):
self.songselect_form = None self.songselect_form = None
register_endpoint(songs_endpoint) register_endpoint(songs_endpoint)
register_endpoint(api_songs_endpoint) register_endpoint(api_songs_endpoint)
State().add_service(self.name, self.weight, isPlugin=True) State().add_service(self.name, self.weight, is_plugin=True)
State().update_pre_conditions(self.name, self.check_pre_conditions()) State().update_pre_conditions(self.name, self.check_pre_conditions())
def check_pre_conditions(self): def check_pre_conditions(self):

View File

@ -67,8 +67,8 @@ class SongUsagePlugin(Plugin):
self.weight = -4 self.weight = -4
self.icon = UiIcons().song_usage self.icon = UiIcons().song_usage
self.song_usage_active = False self.song_usage_active = False
State().add_service(self.name, self.weight, isPlugin=True) State().add_service('song_usage', self.weight, is_plugin=True)
State().update_pre_conditions(self.name, self.check_pre_conditions()) State().update_pre_conditions('song_usage', self.check_pre_conditions())
def check_pre_conditions(self): def check_pre_conditions(self):
""" """