def load_plugins(app): app.pluggy.add_hookspecs(spec) try: with app.app_context(): plugins = PluginRegistry.query.all() except (OperationalError, ProgrammingError): return for plugin in plugins: if not plugin.enabled: app.pluggy.set_blocked(plugin.name) app.pluggy.load_setuptools_entrypoints('flaskbb_plugins') app.pluggy.hook.flaskbb_extensions(app=app) loaded_names = set([p[0] for p in app.pluggy.list_name_plugin()]) registered_names = set([p.name for p in plugins]) unregistered = [ PluginRegistry(name=name) for name in loaded_names - registered_names ] with app.app_context(): db.session.add_all(unregistered) db.session.commit() removed = 0 if app.config["REMOVE_DEAD_PLUGINS"]: removed = remove_zombie_plugins_from_db() app.logger.info("Removed Plugins: {}".format(removed))
def load_plugins(app): app.pluggy.add_hookspecs(spec) # have to find all the flaskbb modules that are loaded this way # otherwise sys.modules might change while we're iterating it # because of imports and that makes Python very unhappy # we are not interested in duplicated plugins or invalid ones # ('None' - appears on py2) and thus using a set flaskbb_modules = set( module for name, module in iteritems(sys.modules) if name.startswith('flaskbb') ) for module in flaskbb_modules: app.pluggy.register(module, internal=True) try: with app.app_context(): plugins = PluginRegistry.query.all() except (OperationalError, ProgrammingError) as exc: logger.debug("Database is not setup correctly or has not been " "setup yet.", exc_info=exc) return for plugin in plugins: if not plugin.enabled: app.pluggy.set_blocked(plugin.name) app.pluggy.load_setuptools_entrypoints('flaskbb_plugins') app.pluggy.hook.flaskbb_extensions(app=app) loaded_names = set([p[0] for p in app.pluggy.list_name_plugin()]) registered_names = set([p.name for p in plugins]) unregistered = [ PluginRegistry(name=name) for name in loaded_names - registered_names # ignore internal FlaskBB modules if not name.startswith('flaskbb.') and name != 'flaskbb' ] with app.app_context(): db.session.add_all(unregistered) db.session.commit() removed = 0 if app.config["REMOVE_DEAD_PLUGINS"]: removed = remove_zombie_plugins_from_db() logger.info("Removed Plugins: {}".format(removed)) # we need a copy of it because of # RuntimeError: dictionary changed size during iteration tasks = celery.tasks.copy() disabled_plugins = [ p.__package__ for p in app.pluggy.get_disabled_plugins() ] for task_name, task in iteritems(tasks): if task.__module__.split(".")[0] in disabled_plugins: logger.debug("Unregistering task: '{}'".format(task)) celery.tasks.unregister(task_name)