예제 #1
0
 def test_content_dir_dne(self, logging_mock, get_version):
     with self.assertRaises(SystemExit):
         sanity_checks.check_content_directory_exists_and_writable()
         logging_mock.assert_called()
예제 #2
0
 def test_content_dir_not_writable(self, access_mock, logging_mock):
     with self.assertRaises(SystemExit):
         sanity_checks.check_content_directory_exists_and_writable()
         logging_mock.assert_called()
예제 #3
0
def initialize(
    skip_update=False,
    settings=None,
    debug=False,
    debug_database=False,
    no_input=False,
    pythonpath=None,
):  # noqa: max-complexity=12
    """
    This should be called before starting the Kolibri app, it initializes Kolibri plugins
    and sets up Django.
    """
    check_debian_user(no_input)

    setup_logging(debug=debug, debug_database=debug_database)

    default_options = DefaultDjangoOptions(settings, pythonpath)

    handle_default_options(default_options)

    # Do this here so that we can fix any issues with our configuration file before
    # we attempt to set up django.
    autoremove_unavailable_plugins()

    # Check if there is an options.ini file exist inside the KOLIBRI_HOME folder
    check_default_options_exist()

    version = get_version()

    updated = version_updated(kolibri.__version__, version)

    if updated:
        check_plugin_config_file_location(version)
        # Reset the enabled plugins to the defaults
        # This needs to be run before dbbackup because
        # dbbackup relies on settings.INSTALLED_APPS
        enable_new_default_plugins()

    _setup_django()

    if updated and not skip_update:
        conditional_backup(kolibri.__version__, version)

        if version:
            logger.info(
                "Version was {old}, new version: {new}".format(
                    old=version, new=kolibri.__version__
                )
            )
        else:
            logger.info("New install, version: {new}".format(new=kolibri.__version__))
        update(version, kolibri.__version__)

    check_content_directory_exists_and_writable()

    if not skip_update:
        # Run any plugin specific updates here in case they were missed by
        # our Kolibri version based update logic.
        run_plugin_updates()

        check_django_stack_ready()

        try:
            check_database_is_migrated()
        except DatabaseNotMigrated:
            try:
                _migrate_databases()
            except Exception as e:
                logging.error(
                    "The database was not fully migrated. Tried to "
                    "migrate the database and an error occurred: "
                    "{}".format(e)
                )
                raise
        except DatabaseInaccessible as e:
            logging.error(
                "Tried to check that the database was accessible "
                "and an error occurred: {}".format(e)
            )
            raise

    import_tasks_module_from_django_apps()