예제 #1
0
def finalize_app(app):
    """Prepare application for running"""

    from datacat.db import db_info

    with app.app_context():
        app.plugins = load_plugins(app)

        previously_enabled_plugins = set(db_info.get('core.plugins_enabled', []))  # noqa
        previously_installed_plugins = set(db_info.get('core.plugins_installed', []))  # noqa
        enabled_plugins = set(app.config['PLUGINS'])

        # ------------------------------------------------------------
        # Run the ``install()`` method for all the plugins that
        # were not previously installed
        plugins_to_install = enabled_plugins - previously_installed_plugins

        # ------------------------------------------------------------
        # Run the ``enable()`` method for all the plugins that
        # were not previously enabled
        plugins_to_enable = enabled_plugins - previously_enabled_plugins

        # ------------------------------------------------------------
        # Run the ``disable()`` method for all the plugins that
        # were previously enabled (and aren't anymore)
        plugins_to_disable = previously_enabled_plugins - enabled_plugins

        # Nothing will be uninstalled implicitly!

        # ------------------------------------------------------------
        # Perform the operations from above
        # ------------------------------------------------------------

        for plugin in app.plugins:
            if plugin._import_name in plugins_to_install:
                plugin.install()

            if plugin._import_name in plugins_to_enable:
                plugin.enable()

            if plugin._import_name in plugins_to_disable:
                plugin.disable()

            if plugin._import_name in enabled_plugins:
                plugin.upgrade()

        # ------------------------------------------------------------
        # Register new information about plugins

        db_info['core.plugins_enabled'] = list(enabled_plugins)
        db_info['core.plugins_installed'] = list(
            previously_installed_plugins | enabled_plugins)
예제 #2
0
def finalize_app(app):
    """Prepare application for running"""

    from datacat.db import db_info

    with app.app_context():
        app.plugins = load_plugins(app)

        previously_enabled_plugins = set(db_info.get('core.plugins_enabled', []))  # noqa
        previously_installed_plugins = set(db_info.get('core.plugins_installed', []))  # noqa
        enabled_plugins = set(app.config['PLUGINS'])

        # ------------------------------------------------------------
        # Run the ``install()`` method for all the plugins that
        # were not previously installed
        plugins_to_install = enabled_plugins - previously_installed_plugins

        # ------------------------------------------------------------
        # Run the ``enable()`` method for all the plugins that
        # were not previously enabled
        plugins_to_enable = enabled_plugins - previously_enabled_plugins

        # ------------------------------------------------------------
        # Run the ``disable()`` method for all the plugins that
        # were previously enabled (and aren't anymore)
        plugins_to_disable = previously_enabled_plugins - enabled_plugins

        # Nothing will be uninstalled implicitly!

        # ------------------------------------------------------------
        # Perform the operations from above
        # ------------------------------------------------------------

        for plugin in app.plugins:
            if plugin._import_name in plugins_to_install:
                plugin.install()

            if plugin._import_name in plugins_to_enable:
                plugin.enable()

            if plugin._import_name in plugins_to_disable:
                plugin.disable()

            if plugin._import_name in enabled_plugins:
                plugin.upgrade()

        # ------------------------------------------------------------
        # Register new information about plugins

        db_info['core.plugins_enabled'] = list(enabled_plugins)
        db_info['core.plugins_installed'] = list(
            previously_installed_plugins | enabled_plugins)
예제 #3
0
    def upgrade(self):
        """
        Perform necessary database schema upgrades.
        """

        from datacat.db import db_info

        schema_version_key = 'plugin.{0}.schema_version'\
            .format(self.import_name)

        current_version = db_info.get(schema_version_key, -1)
        upgrade_methods = self._get_upgrade_methods()  # Must be sorted!
        for upgrade_id, method in upgrade_methods:
            if upgrade_id > current_version:
                method()
                db_info[schema_version_key] = upgrade_id