Beispiel #1
0
def initialize(skip_update=False):
    """
    Currently, always called before running commands. This may change in case
    commands that conflict with this behavior show up.
    """
    params = get_initialize_params()

    debug = params["debug"]
    skip_update = skip_update or params["skip_update"]
    settings = params["settings"]
    pythonpath = params["pythonpath"]

    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()

    version = get_version()

    if version_updated(kolibri.__version__, version):
        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(debug)

    if version_updated(kolibri.__version__, version) and not skip_update:
        if should_back_up(kolibri.__version__, version):
            # Non-dev version change, make a backup no matter what.
            from kolibri.core.deviceadmin.utils import dbbackup

            try:
                backup = dbbackup(version)
                logger.info(
                    "Backed up database to: {path}".format(path=backup))
            except IncompatibleDatabase:
                logger.warning(
                    "Skipped automatic database backup, not compatible with "
                    "this DB engine.")

        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__)

    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()
Beispiel #2
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()
Beispiel #3
0
def initialize(skip_update=False):  # noqa: max-complexity=12
    """
    Currently, always called before running commands. This may change in case
    commands that conflict with this behavior show up.
    """
    params = get_initialize_params()

    check_debian_user(params.get("no_input"))

    setup_logging(debug=params.get("debug"),
                  debug_database=params.get("debug_database"))

    skip_update = skip_update or params["skip_update"]
    settings = params["settings"]
    pythonpath = params["pythonpath"]

    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()

    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__)

    sanity_checks.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:
            sanity_checks.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))
                sys.exit(1)
        except DatabaseInaccessible as e:
            logging.error("Tried to check that the database was accessible "
                          "and an error occurred: {}".format(e))
            sys.exit(1)
Beispiel #4
0
def initialize(skip_update=False):
    """
    Currently, always called before running commands. This may change in case
    commands that conflict with this behavior show up.
    """
    params = get_initialize_params()

    debug = params["debug"]
    skip_update = skip_update or params["skip_update"]
    settings = params["settings"]
    pythonpath = params["pythonpath"]

    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()

    version = get_version()

    if version_updated(kolibri.__version__, version):
        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()

    try:
        django.setup()
        if debug:
            from django.conf import settings

            settings.DEBUG = True

    except (DatabaseError, SQLite3DatabaseError) as e:
        if "malformed" in str(e):
            logger.error(
                "Your database appears to be corrupted. If you encounter this,"
                "please immediately back up all files in the .kolibri folder that"
                "end in .sqlite3, .sqlite3-shm, .sqlite3-wal, or .log and then"
                "contact Learning Equality. Thank you!")
        raise

    if version_updated(kolibri.__version__, version) and not skip_update:
        if should_back_up(kolibri.__version__, version):
            # Non-dev version change, make a backup no matter what.
            from kolibri.core.deviceadmin.utils import dbbackup

            try:
                backup = dbbackup(version)
                logger.info(
                    "Backed up database to: {path}".format(path=backup))
            except IncompatibleDatabase:
                logger.warning(
                    "Skipped automatic database backup, not compatible with "
                    "this DB engine.")

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