Ejemplo n.º 1
0
 def activatePlugin(self, pluginInfo, save_state=True, checkDependencies=True):
     from lunchinator.utilities import handleMissingDependencies
     from lunchinator import get_server
     
     if checkDependencies:
         missing = self.checkActivation([pluginInfo])
         result = handleMissingDependencies(missing)
         if result == INSTALL_FAIL:
             # maybe there were dependencies installed, better re-check
             missing = self.checkActivation([pluginInfo])
             if missing:
                 self._logCannotLoad(pluginInfo, missing)
                 get_notification_center().emitPluginDeactivated(pluginInfo.name, pluginInfo.category)
                 return
         elif result == INSTALL_CANCEL:
             # user chose not to install -> deactivate
             get_notification_center().emitPluginDeactivated(pluginInfo.name, pluginInfo.category)
             self._deactivateMissing(missing)
             return
         elif result in (INSTALL_SUCCESS, INSTALL_IGNORE):
             missing = {}
         elif result == INSTALL_RESTART:
             # store that the plugin is activated now
             self.__addPluginToConfig(pluginInfo.category, pluginInfo.name)
             return
     
     getCoreLogger().info("Activating plugin '%s' of type '%s'", pluginInfo.name, pluginInfo.category)
     try:
         pluginInfo.plugin_object.setPluginName(pluginInfo.name)
         result = ConfigurablePluginManager.activatePluginByName(self, pluginInfo.name, category_name=pluginInfo.category, save_state=save_state)
         if self._emitSignals and result != None:
             get_notification_center().emitPluginActivated(pluginInfo.name, pluginInfo.category)
     except:
         getCoreLogger().exception("Error activating plugin '%s' of type '%s'", pluginInfo.name, pluginInfo.category)
Ejemplo n.º 2
0
def installCoreDependencies():
    requirements = getCoreDependencies()
    missing = checkRequirements(requirements, u"Lunchinator", u"Lunchinator")
    result = handleMissingDependencies(missing, optionalCallback=lambda req: not "yapsy" in req.lower())
    if result == INSTALL_CANCEL:
        return False

    try:
        import yapsy

        if lunchinator_has_gui():
            from PyQt4.QtGui import QMessageBox

            if result == INSTALL_SUCCESS:
                QMessageBox.information(
                    None,
                    "Success",
                    "Dependencies were installed successfully.",
                    buttons=QMessageBox.Ok,
                    defaultButton=QMessageBox.Ok,
                )
            elif result == INSTALL_FAIL:
                QMessageBox.warning(
                    None,
                    "Errors during installation",
                    "There were errors during installation, but Lunchinator might work anyways. If you experience problems with some plugins, try to install the required libraries manually using pip.",
                )
            return True
        getCoreLogger().info("yapsy is working after dependency installation")
        # without gui there are enough messages on the screen already
    except:
        if lunchinator_has_gui():
            try:
                from PyQt4.QtGui import QMessageBox

                QMessageBox.critical(
                    None,
                    "Error installing dependencies",
                    "There was an error, the dependencies could not be installed. Continuing without plugins.",
                )
            except:
                getCoreLogger().error(
                    "There was an error, the dependencies could not be installed. Continuing without plugins."
                )
        getCoreLogger().error(
            "Lunchinator is running without plugins because of missing dependencies. \
                Try executing 'lunchinator --install-dependencies' to install them automatically."
        )
        return False
Ejemplo n.º 3
0
    def loadPlugins(self, callback=None):
        from lunchinator.utilities import handleMissingDependencies
        self._emitSignals = False
        
        self._component.loadPlugins(callback)
        
        pluginsToLoad = set()
        # now load the plugins according to the recorded configuration
        if self.config_parser.has_section(self.CONFIG_SECTION_NAME):
            # browse all the categories
            for category_name in self._component.category_mapping.keys():
                # get the list of plugins to be activated for this
                # category
                option_name = "%s_plugins_to_load"%category_name
                if self.config_parser.has_option(self.CONFIG_SECTION_NAME,
                                                 option_name):
                    plugin_list_str = self.config_parser.get(self.CONFIG_SECTION_NAME,
                                                             option_name)
                    plugin_list = self.__getCategoryPluginsListFromConfig(plugin_list_str)
                    # activate all the plugins that should be
                    # activated
                    for plugin_name in plugin_list:
                        if plugin_name:
                            pluginsToLoad.add(plugin_name)
            
        # first, load db plugins
        # second, load remaining force activated plugins
        # last, unload regular plugins (no database, no force activation)
        loadFirst = []
        loadSecond = []
        loadThird = []            
        for pluginInfo in self.getAllPlugins():
            if pluginInfo is None or pluginInfo.plugin_object.is_activated:
                continue
            if pluginInfo.category == "db" and pluginInfo.plugin_object.force_activation:
                loadFirst.append(pluginInfo)
            elif pluginInfo.plugin_object.force_activation:
                loadSecond.append(pluginInfo)
            elif pluginInfo.name in pluginsToLoad:
                loadThird.append(pluginInfo)

        missing = {}
        for piList in (loadFirst, loadSecond, loadThird):
            newMissing = self.checkActivation(piList)
            missing.update(newMissing)
            
        from lunchinator import get_server
        result = handleMissingDependencies(missing)
        if result == INSTALL_FAIL:
            # maybe there were dependencies installed, better re-check
            missing = {}
            for piList in (loadFirst, loadSecond, loadThird):
                newMissing = self.checkActivation(piList)
                missing.update(newMissing)
            self._deactivateMissing(missing)
        elif result == INSTALL_CANCEL:
            # user chose not to install -> deactivate
            self._deactivateMissing(missing)
        elif result in (INSTALL_SUCCESS, INSTALL_IGNORE):
            missing = {}
        elif result == INSTALL_RESTART:
            return
                    
        for piList in (loadFirst, loadSecond, loadThird):
            for pluginInfo in piList:
                if (pluginInfo.name, pluginInfo.category) in missing:
                    self._logCannotLoad(pluginInfo, missing)
                    continue
                self.activatePlugin(pluginInfo=pluginInfo, save_state=False, checkDependencies=False)
        
        self._emitSignals = True