Exemple #1
0
    def test_signals_usage(self):
        """ Test signal handling. """
        from invenio.base.scripts.database import main as db_main
        from invenio.base.signals import pre_command, post_command
        from invenio.base.manage import main, version as im_version

        def pre_handler_version(sender, *args, **kwargs):
            print('>>> pre_handler_version')

        def post_handler_version(sender, *args, **kwargs):
            print('>>> post_handler_version')

        # Bind only `inveniomanage version` command to pre/post handler.
        pre_command.connect(pre_handler_version, sender=im_version)
        post_command.connect(post_handler_version, sender=im_version)

        def pre_handler_general_test(sender, *args, **kwargs):
            print('>>> pre_handler_general')

        def post_handler_general_test(sender, *args, **kwargs):
            print('>>> post_handler_general')

        # Bind all commands to pre/post general handler.
        pre_command.connect(pre_handler_general_test)
        pre_command.connect(post_handler_general_test)

        # Expect both version and general handlers.
        out, dummy_exit_code = run('inveniomanage version', main)

        lines = out.split('\n')
        expected = ['>>> pre_handler_version',
                    '>>> post_handler_version',
                    '>>> pre_handler_general',
                    '>>> post_handler_general']
        for line in expected:
            self.assertTrue(line in lines,
                            "%s was not found in output %s" % (line, lines))

        # Expect only general handlers.
        out, dummy_exit_code = run('database uri', db_main)

        lines = out.split('\n')
        expected = ['>>> pre_handler_general',
                    '>>> post_handler_general']
        for line in expected:
            self.assertTrue(line in lines,
                            "%s was not found in output %s" % (line, lines))

        notexpected = ['>>> pre_handler_version',
                       '>>> post_handler_version']
        for line in notexpected:
            self.assertFalse(line in lines,
                             "%s was not expected in output %s" % (line, lines))
Exemple #2
0
    def test_signals_usage(self):
        """ Test signal handling. """
        from invenio.base.scripts.database import main as db_main
        from invenio.base.signals import pre_command, post_command
        from invenio.base.manage import main, version as im_version

        def pre_handler_version(sender, *args, **kwargs):
            print('>>> pre_handler_version')

        def post_handler_version(sender, *args, **kwargs):
            print('>>> post_handler_version')

        # Bind only `inveniomanage version` command to pre/post handler.
        pre_command.connect(pre_handler_version, sender=im_version)
        post_command.connect(post_handler_version, sender=im_version)

        def pre_handler_general_test(sender, *args, **kwargs):
            print('>>> pre_handler_general')

        def post_handler_general_test(sender, *args, **kwargs):
            print('>>> post_handler_general')

        # Bind all commands to pre/post general handler.
        pre_command.connect(pre_handler_general_test)
        pre_command.connect(post_handler_general_test)

        # Expect both version and general handlers.
        out, dummy_exit_code = run('inveniomanage version', main)

        lines = out.split('\n')
        expected = [
            '>>> pre_handler_version', '>>> post_handler_version',
            '>>> pre_handler_general', '>>> post_handler_general'
        ]
        for line in expected:
            self.assertTrue(line in lines,
                            "%s was not found in output %s" % (line, lines))

        # Expect only general handlers.
        out, dummy_exit_code = run('database uri', db_main)

        lines = out.split('\n')
        expected = ['>>> pre_handler_general', '>>> post_handler_general']
        for line in expected:
            self.assertTrue(line in lines,
                            "%s was not found in output %s" % (line, lines))

        notexpected = ['>>> pre_handler_version', '>>> post_handler_version']
        for line in notexpected:
            self.assertFalse(
                line in lines,
                "%s was not expected in output %s" % (line, lines))
Exemple #3
0
    def test_signals_usage(self):
        """ Test signal handling. """
        from invenio.base.scripts.database import main as db_main
        from invenio.base.signals import pre_command, post_command
        from invenio.base.manage import main, version as im_version

        def pre_handler_version(sender, *args, **kwargs):
            print(">>> pre_handler_version")

        def post_handler_version(sender, *args, **kwargs):
            print(">>> post_handler_version")

        # Bind only `inveniomanage version` command to pre/post handler.
        pre_command.connect(pre_handler_version, sender=im_version)
        post_command.connect(post_handler_version, sender=im_version)

        def pre_handler_general_test(sender, *args, **kwargs):
            print(">>> pre_handler_general")

        def post_handler_general_test(sender, *args, **kwargs):
            print(">>> post_handler_general")

        # Bind all commands to pre/post general handler.
        pre_command.connect(pre_handler_general_test)
        pre_command.connect(post_handler_general_test)

        # Expect both version and general handlers.
        out = run_py_func(main, "inveniomanage version").out

        lines = out.split("\n")
        expected = (
            ">>> pre_handler_version",
            ">>> post_handler_version",
            ">>> pre_handler_general",
            ">>> post_handler_general",
        )
        for line in expected:
            self.assertTrue(line in lines, "%s was not found in output %s" % (line, lines))

        # Expect only general handlers.
        out = run_py_func(db_main, "database uri").out

        lines = out.split("\n")
        expected = (">>> pre_handler_general", ">>> post_handler_general")
        for line in expected:
            self.assertTrue(line in lines, "%s was not found in output %s" % (line, lines))

        notexpected = (">>> pre_handler_version", ">>> post_handler_version")
        for line in notexpected:
            self.assertFalse(line in lines, "%s was not expected in output %s" % (line, lines))
Exemple #4
0
        command.__class__ = SignalingCommand
        return super(Manager, self).add_command(name, command)


def set_serve_static_files(sender, *args, **kwargs):
    """Enable serving of static files for `runserver` command.

    Normally Apache serves static files, but during development and if you are
    using the Werkzeug standalone development server, you can set this flag to
    `True`, to enable static file serving.
    """
    current_app.config.setdefault('CFG_FLASK_SERVE_STATIC_FILES', True)


pre_command.connect(set_serve_static_files, sender=Server)


def create_ssl_context(config):
    """Create :class:`ssl.SSLContext` from application config.

    :param config: Dict-like application configuration.
    :returns: A valid context or in case TLS is not enabled `None`.

    The following configuration variables are processed:

    ============================ ==============================================
    `SERVER_TLS_ENABLE`          If `True`, a SSL context will be created. In
                                 this case, the required configuration
                                 variables must be provided.
    `SERVER_TLS_KEY` (required)  Filepath (string) of private key provided as
Exemple #5
0
                return res

        command.__class__ = SignalingCommand
        return super(Manager, self).add_command(name, command)


def set_serve_static_files(sender, *args, **kwargs):
    """Enable serving of static files for `runserver` command.

    Normally Apache serves static files, but during development and if you are
    using the Werkzeug standalone development server, you can set this flag to
    `True`, to enable static file serving.
    """
    current_app.config.setdefault('CFG_FLASK_SERVE_STATIC_FILES', True)

pre_command.connect(set_serve_static_files, sender=Server)


def register_manager(manager):
    """Register all manager plugins and default commands with the manager."""
    from six.moves.urllib.parse import urlparse
    managers = RegistryProxy('managers', ModuleAutoDiscoveryRegistry, 'manage')

    with manager.app.app_context():
        for script in find_modules('invenio.base.scripts'):
            manager.add_command(script.split('.')[-1],
                                import_string(script + ':manager'))
        for script in managers:
            if script.__name__ == 'invenio.base.manage':
                continue
            manager.add_command(script.__name__.split('.')[-2],