Esempio n. 1
0
def status():
    """
    How is Kolibri doing?
    Check the server's status. For possible statuses, see the status dictionary
    server.status_messages

    Status *always* outputs the current status in the first line of stderr.
    The following lines contain optional information such as the addresses where
    the server is listening.

    TODO: We can't guarantee the above behavior because of the django stack
    being loaded regardless

    Exits with status_code, key has description in server.status_messages
    """
    status_code, urls = server.get_urls()

    if status_code == server.STATUS_RUNNING:
        sys.stderr.write("{msg:s} (0)\n".format(msg=server.status_messages[0]))
        if urls:
            sys.stderr.write("Kolibri running on:\n\n")
            for addr in urls:
                sys.stderr.write("\t{}\n".format(addr))
    else:
        verbose_status = server.status_messages[status_code]
        sys.stderr.write("{msg:s} ({code:d})\n".format(code=status_code,
                                                       msg=verbose_status))
    sys.exit(status_code)
Esempio n. 2
0
    def get(self, request, format=None):
        info = {}

        info['version'] = kolibri.__version__

        status, urls = get_urls()
        if not urls:
            # Will not return anything when running the debug server, so at least return the current URL
            urls = [request.build_absolute_uri('/')]

        filtered_urls = [url for url in urls if '127.0.0.1' not in url and 'localhost' not in url]

        if filtered_urls:
            urls = filtered_urls

        info['urls'] = urls

        if settings.DATABASES['default']['ENGINE'].endswith('sqlite3'):
            # If any other database backend, will not be file backed, so no database path to return
            info['database_path'] = settings.DATABASES['default']['NAME']

        instance_model = InstanceIDModel.get_or_create_current_instance()[0]

        info['device_name'] = instance_model.hostname
        info['device_id'] = instance_model.id
        info['os'] = instance_model.platform

        info['content_storage_free_space'] = get_free_space()

        # This returns the localized time for the server
        info['server_time'] = local_now()
        # Returns the named timezone for the server (the time above only includes the offset)
        info['server_timezone'] = settings.TIME_ZONE

        return Response(info)
Esempio n. 3
0
    def get(self, request, format=None):
        info = {}

        info["version"] = kolibri.__version__

        status, urls = get_urls()
        if not urls:
            # Will not return anything when running the debug server, so at least return the current URL
            urls = [
                request.build_absolute_uri(OPTIONS["Deployment"]["URL_PATH_PREFIX"])
            ]

        filtered_urls = [
            url for url in urls if "127.0.0.1" not in url and "localhost" not in url
        ]

        if filtered_urls:
            urls = filtered_urls

        info["urls"] = urls

        db_engine = settings.DATABASES["default"]["ENGINE"]

        if db_engine.endswith("sqlite3"):
            # Return path to .sqlite file (usually in KOLIBRI_HOME folder)
            info["database_path"] = settings.DATABASES["default"]["NAME"]
        elif db_engine.endswith("postgresql"):
            info["database_path"] = "postgresql"
        else:
            info["database_path"] = "unknown"

        instance_model = InstanceIDModel.get_or_create_current_instance()[0]

        info["device_id"] = instance_model.id
        info["os"] = instance_model.platform

        info["content_storage_free_space"] = get_free_space(
            OPTIONS["Paths"]["CONTENT_DIR"]
        )

        # This returns the localized time for the server
        info["server_time"] = local_now()
        # Returns the named timezone for the server (the time above only includes the offset)
        info["server_timezone"] = settings.TIME_ZONE
        info["installer"] = installation_type()
        info["python_version"] = "{major}.{minor}.{micro}".format(
            major=version_info.major, minor=version_info.minor, micro=version_info.micro
        )
        return Response(info)
Esempio n. 4
0
    def get(self, request, format=None):
        info = {}

        info["version"] = kolibri.__version__

        status, urls = get_urls()
        if not urls:
            # Will not return anything when running the debug server, so at least return the current URL
            urls = [
                request.build_absolute_uri(
                    OPTIONS["Deployment"]["URL_PATH_PREFIX"])
            ]

        filtered_urls = [
            url for url in urls
            if "127.0.0.1" not in url and "localhost" not in url
        ]

        if filtered_urls:
            urls = filtered_urls

        info["urls"] = urls

        if settings.DATABASES["default"]["ENGINE"].endswith("sqlite3"):
            # If any other database backend, will not be file backed, so no database path to return
            info["database_path"] = settings.DATABASES["default"]["NAME"]

        instance_model = InstanceIDModel.get_or_create_current_instance()[0]

        info["device_name"] = instance_model.hostname
        info["device_id"] = instance_model.id
        info["os"] = instance_model.platform

        info["content_storage_free_space"] = get_free_space(
            OPTIONS["Paths"]["CONTENT_DIR"])

        # This returns the localized time for the server
        info["server_time"] = local_now()
        # Returns the named timezone for the server (the time above only includes the offset)
        info["server_timezone"] = settings.TIME_ZONE
        info["installer"] = installation_type()

        return Response(info)
Esempio n. 5
0
    def get(self, request, format=None):
        info = {}

        info['version'] = kolibri.__version__

        status, urls = get_urls()
        if not urls:
            # Will not return anything when running the debug server, so at least return the current URL
            urls = [request.build_absolute_uri('/')]

        filtered_urls = [
            url for url in urls
            if '127.0.0.1' not in url and 'localhost' not in url
        ]

        if filtered_urls:
            urls = filtered_urls

        info['urls'] = urls

        if settings.DATABASES['default']['ENGINE'].endswith('sqlite3'):
            # If any other database backend, will not be file backed, so no database path to return
            info['database_path'] = settings.DATABASES['default']['NAME']

        instance_model = InstanceIDModel.get_or_create_current_instance()[0]

        info['device_name'] = instance_model.hostname
        info['device_id'] = instance_model.id
        info['os'] = instance_model.platform

        info['content_storage_free_space'] = get_free_space()

        # This returns the localized time for the server
        info['server_time'] = local_now()
        # Returns the named timezone for the server (the time above only includes the offset)
        info['server_timezone'] = settings.TIME_ZONE

        return Response(info)