Exemple #1
0
def start_django(port=5000):
    from kolibri.utils.cli import initialize, setup_logging, start

    logging.info("Starting server...")
    setup_logging(debug=False)
    initialize()
    start.callback(port, background=False)
Exemple #2
0
def get_init_url(next_url='/'):
    # we need to initialize Kolibri to allow us to access the app key
    from kolibri.utils.cli import initialize
    initialize(skip_update=True)

    from kolibri.plugins.app.utils import interface
    return interface.get_initialize_url(next_url=next_url)
Exemple #3
0
    def __run_kolibri_start(self):
        if not self.__context.await_setup_result():
            self.__context.is_starting = False
            return

        self.__context.is_starting = True

        self.__active_extensions.update_kolibri_environ(os.environ)

        from kolibri.plugins.registry import registered_plugins
        from kolibri.utils.cli import initialize, setup_logging, start

        registered_plugins.register_plugins(["kolibri.plugins.app"])

        setup_logging(debug=False)
        initialize()

        self.__automatic_provisiondevice()
        self.__update_app_key()

        try:
            from ..kolibri_globals import KOLIBRI_HTTP_PORT

            # TODO: Start on port 0 and get randomized port number from
            #       Kolibri. This requires some changes in Kolibri itself.
            #       After doing this, we should be able to remove some weird
            #       dependencies with Kolibri in the globals module.
            start.callback(KOLIBRI_HTTP_PORT, background=False)
        except SystemExit:
            # Kolibri sometimes calls sys.exit, but we don't want to exit
            pass
Exemple #4
0
def test_update_no_version_change(dbbackup, update, orig_version=None):
    """
    Tests that when the version doesn't change, we are not doing things we
    shouldn't
    """
    cli.initialize()
    update.assert_not_called()
    dbbackup.assert_not_called()
Exemple #5
0
def test_update(update, version_file=None, orig_version=None):
    """
    Tests that update() function performs as expected
    """
    version_file = cli.version_file()
    open(version_file, "w").write(orig_version + "_test")
    cli.initialize()
    update.assert_called_once()
Exemple #6
0
def test_update_no_version_change(dbbackup, update, orig_version=None):
    """
    Tests that when the version doesn't change, we are not doing things we
    shouldn't
    """
    cli.initialize()
    update.assert_not_called()
    dbbackup.assert_not_called()
Exemple #7
0
def test_update_exits_if_running(get_version):
    """
    Tests that update() function performs as expected
    """
    with patch("kolibri.utils.cli.server.get_status"):
        try:
            cli.initialize()
            pytest.fail("Update did not exit when Kolibri was already running")
        except SystemExit:
            pass
Exemple #8
0
def test_migrate_if_unmigrated(version_updated, _migrate_databases):
    # No matter what, ensure that version_updated returns False
    version_updated.return_value = False
    from morango.models import InstanceIDModel

    with patch.object(InstanceIDModel, "get_or_create_current_instance"
                      ) as get_or_create_current_instance:
        get_or_create_current_instance.side_effect = OperationalError("Test")
        cli.initialize()
        _migrate_databases.assert_called_once()
Exemple #9
0
def start_kolibri_server():
    from kolibri.utils.cli import initialize, setup_logging, start
    from kolibri.plugins.registry import registered_plugins

    registered_plugins.register_plugins(['kolibri.plugins.app'])

    logging.info("Starting server...")
    setup_logging(debug=False)
    initialize()
    automatic_provisiondevice()
    start.callback(KOLIBRI_PORT, background=False)
def init_kolibri():
    from kolibri.plugins.registry import registered_plugins
    from kolibri.utils.cli import initialize, setup_logging

    registered_plugins.register_plugins(["kolibri.plugins.app"])

    if importlib.util.find_spec("kolibri_app_desktop_xdg_plugin"):
        registered_plugins.register_plugins(["kolibri_app_desktop_xdg_plugin"])

    setup_logging(debug=False)
    initialize()
Exemple #11
0
def test_first_run(dbbackup, plugin, update, get_version):
    """
    Tests that the first_run() function performs as expected
    """

    cli.initialize()
    update.assert_called_once()
    dbbackup.assert_not_called()

    # Check that it got called for each default plugin
    from kolibri.utils import conf

    assert set(conf.config["INSTALLED_APPS"]) == set(conf.DEFAULT_PLUGINS)
Exemple #12
0
def test_update_no_version_change(dbbackup,
                                  update,
                                  version_file=None,
                                  orig_version=None):
    """
    Tests that when the version doesn't change, we are not doing things we
    shouldn't
    """
    version_file = cli.version_file()
    open(version_file, "w").write(orig_version)
    cli.initialize()
    update.assert_not_called()
    dbbackup.assert_not_called()
Exemple #13
0
def get_initialize_url(next_url=None):
    from kolibri.utils.cli import initialize
    from kolibri.plugins.registry import registered_plugins

    # The start_kolibri_server function is typically run in a different thread or process
    # than the app, so for get_initialize_url to work, we need to initialize Kolibri
    # in the app process as well.
    registered_plugins.register_plugins(['kolibri.plugins.app'])
    initialize()

    from kolibri.plugins.app.utils import interface

    return interface.get_initialize_url(next_url)
Exemple #14
0
def test_update(update, version_file=None, orig_version=None):
    """
    Tests that update() function performs as expected, creating a database
    backup automatically when version changes
    """
    version_file = cli.version_file()
    open(version_file, "w").write(orig_version + "_test")

    if is_sqlite_settings():
        with patch('kolibri.core.deviceadmin.utils.dbbackup') as dbbackup:
            cli.initialize()
            dbbackup.assert_called_once()
    else:
        cli.initialize()
    update.assert_called_once()
Exemple #15
0
def test_update(update, version_file=None, orig_version=None):
    """
    Tests that update() function performs as expected, creating a database
    backup automatically when version changes
    """
    version_file = cli.version_file()
    open(version_file, "w").write(orig_version + "_test")

    if is_sqlite_settings():
        with patch('kolibri.core.deviceadmin.utils.dbbackup') as dbbackup:
            cli.initialize()
            dbbackup.assert_called_once()
    else:
        cli.initialize()
    update.assert_called_once()
Exemple #16
0
def test_first_run(
        dbbackup, plugin, update, version_file=None, orig_version=None):
    """
    Tests that the first_run() function performs as expected
    """

    if version_file:
        os.unlink(version_file)

    cli.initialize()
    update.assert_called_once()
    dbbackup.assert_not_called()

    # Check that it got called for each default plugin
    from kolibri.core.settings import DEFAULT_PLUGINS
    assert plugin.call_count == len(DEFAULT_PLUGINS)
    def __run_kolibri_start(self):
        self.__context.await_is_stopped()
        setup_result = self.__context.await_setup_result()

        if setup_result != self.__context.SetupResult.SUCCESS:
            self.__context.is_starting = False
            return

        init_logging("kolibri-daemon-main.txt")

        self.__context.is_starting = True
        self.__context.is_stopped = False
        self.__context.start_result = None

        # Crudely ignore if there is already a server.pid file
        # This is probably safe because we are inside a (unique) dbus service.
        try:
            KOLIBRI_HOME_PATH.joinpath("server.pid").unlink()
        except FileNotFoundError:
            pass

        self.__active_extensions.update_kolibri_environ(os.environ)

        from kolibri.plugins.registry import registered_plugins
        from kolibri.utils.cli import initialize, setup_logging, start_with_ready_cb

        registered_plugins.register_plugins(["kolibri.plugins.app"])

        setup_logging(debug=False)
        initialize()

        self.__update_app_key()
        self.__update_kolibri_home()

        try:
            KOLIBRI_HTTP_PORT = 0
            start_with_ready_cb(
                port=KOLIBRI_HTTP_PORT,
                background=False,
                ready_cb=self.__kolibri_ready_cb,
            )
        except SystemExit:
            # Kolibri sometimes calls sys.exit, but we don't want to stop this process
            raise Exception("Caught SystemExit")
        except Exception as error:
            raise error
#!/usr/bin/python3
from kolibri.utils.cli import initialize

initialize()

import click
import enum
import operator

from datetime import datetime

from kolibri.core.content.models import ChannelMetadata
from kolibri.core.content.models import ContentNode
from kolibri.dist.django.db.models import Q


class OutputFormat(enum.Enum):
    PLAIN = enum.auto()
    INI = enum.auto()


output_format_str_list = list(map(operator.attrgetter("name"), OutputFormat))


@click.command()
@click.argument("output", type=click.File("w"), default="-")
@click.option(
    "-f",
    "--format",
    "output_format_str",
    type=click.Choice(output_format_str_list, case_sensitive=False),
Exemple #19
0
def test_update(update, get_version):
    """
    Tests that update() function performs as expected
    """
    cli.initialize()
    update.assert_called_once()