def check_database_is_migrated(): """ Use a check that the database instance id model is initialized to check if the database is in a proper state to be used. This must only be run after django initialization. """ apps.check_apps_ready() from django.db import connection from morango.models import InstanceIDModel try: InstanceIDModel.get_or_create_current_instance()[0] connection.close() return except OperationalError: try: migrate_databases() return except Exception as e: logging.error( "Tried to migrate the database but another error occurred: {}". format(e)) except Exception as e: logging.error( "Tried to check that the database was accessible and an error occurred: {}" .format(e)) sys.exit(1)
def get_metrics(self, app_label=None): """Return list of registered metric classes, optionally filtered on an app_label.""" apps.check_apps_ready() app_labels = [app_label] if app_label else self.all_metrics.keys() result = [] for app_label in app_labels: app_metrics = self._get_metrics_for_app(app_label=app_label) result.extend(list(app_metrics.values())) return result
def get_metric(self, app_label, metric_name=None): """Return the metric matching the given app_label and model_name. As a shortcut, app_label may be in the form <app_label>.<model_name>. model_name is case-insensitive. Raise LookupError if no application exists with this label, or no metric exists with this name in the application. Raise ValueError if called with a single argument that doesn't contain exactly one dot. """ apps.check_apps_ready() if metric_name is None: app_label, metric_name = app_label.split(".") app_metrics = self._get_metrics_for_app(app_label=app_label) try: return app_metrics[metric_name.lower()] except KeyError: raise LookupError("App '{}' doesn't have a '{}' metric.".format( app_label, metric_name))
from kolibri.core.content.models import ChannelMetadata from kolibri.core.content.permissions import CanExportLogs from kolibri.core.content.permissions import CanManageContent from kolibri.core.content.utils.channels import get_mounted_drive_by_id from kolibri.core.content.utils.channels import get_mounted_drives_with_channel_info from kolibri.core.content.utils.paths import get_content_database_file_path from kolibri.core.tasks.exceptions import JobNotFound from kolibri.core.tasks.exceptions import UserCancelledError from kolibri.core.tasks.job import State from kolibri.core.tasks.main import queue from kolibri.utils import conf try: from django.apps import apps apps.check_apps_ready() except AppRegistryNotReady: import django django.setup() NETWORK_ERROR_STRING = _("There was a network error.") DISK_IO_ERROR_STRING = _("There was a disk access error.") CATCHALL_SERVER_ERROR_STRING = _("There was an unknown error.") def validate_content_task(request, task_description, require_channel=False): try: channel_id = task_description["channel_id"]
def _populate_app_cache(): global app_cache apps.check_apps_ready() for ac in apps.app_configs.values(): app_cache[ac.name] = ac
def _populate_app_cache(): apps.check_apps_ready() for app_config in apps.app_configs.values(): app_cache[app_config.name] = app_config
import logging as logger from django.apps.registry import AppRegistryNotReady try: from django.apps import apps apps.check_apps_ready() except AppRegistryNotReady: import django django.setup() import requests import platform from django.core.management import call_command from django.http import Http404 from django.utils.translation import ugettext as _ from django_q.humanhash import uuid from kolibri.content.models import ChannelMetadataCache from kolibri.content.utils.channels import get_mounted_drives_with_channel_info from kolibri.content.utils.paths import get_content_database_file_url from rest_framework import serializers, viewsets from rest_framework.decorators import list_route from rest_framework.response import Response from django_q.tasks import async from django_q.models import Task, OrmQ from multiprocessing import Process logging = logger.getLogger(__name__) def windows_handle_async_call(target_func, *args, **kwargs): import django
def check_django_stack_ready(): """Checks that all Django apps are loaded""" apps.check_apps_ready()