kolibri/utils/cli.py
def main(args=None):  # noqa: max-complexity=13
    """
    Kolibri's main function. Parses arguments and calls utility functions.
    Utility functions should be callable for unit testing purposes, but remember
    to use main() for integration tests in order to test the argument API.
    """

    signal.signal(signal.SIGINT, signal.SIG_DFL)

    arguments, django_args = parse_args(args)

    debug = arguments["--debug"]

    if arguments["start"]:
        port = _get_port(arguments["--port"])
        if OPTIONS["Server"]["CHERRYPY_START"]:
            check_other_kolibri_running(port)

    try:
        initialize(debug=debug, skip_update=arguments["--skipupdate"])
    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

    daemon = not arguments["--foreground"]
    # On Mac, Python crashes when forking the process, so prevent daemonization until we can figure out
    # a better fix. See https://github.com/learningequality/kolibri/issues/4821
    if sys.platform == "darwin":
        daemon = False

    # Alias
    if arguments["shell"]:
        arguments["manage"] = True
        arguments["COMMAND"] = "shell"

    if arguments["manage"]:
        command = arguments["COMMAND"]
        manage(command, args=django_args)
        return

    if arguments["plugin"]:
        plugin_name = arguments["PLUGIN"]
        plugin(plugin_name, **arguments)
        return

    if arguments["start"]:
        try:
            server._write_pid_file(server.STARTUP_LOCK, port)
        except (IOError, OSError):
            logger.warn(
                "Impossible to create file lock to communicate starting process"
            )
        # Check if the content directory exists when Kolibri runs after the first time.
        check_content_directory_exists_and_writable()

        # Defragment the db
        call_command("vacuumsqlite")

        # Clear old sessions up
        call_command("clearsessions")

        start(port, daemon=daemon)
        return

    if arguments["stop"]:
        stop()
        return

    if arguments["status"]:
        status_code = status()
        sys.exit(status_code)
        return

    if arguments["services"]:
        try:
            server._write_pid_file(server.STARTUP_LOCK, None)
        except (IOError, OSError):
            logger.warn(
                "Impossible to create file lock to communicate starting process"
            )

        services(daemon=daemon)
        return

    if arguments["language"] and arguments["setdefault"]:
        set_default_language(arguments["<langcode>"])

    Kolibri's main function. Parses arguments and calls utility functions.
    Utility functions should be callable for unit testing purposes, but remember
    to use main() for integration tests in order to test the argument API.
    
Kolibri's main function. Parses arguments and calls utility functions.
Utility functions should be callable for unit testing purposes, but remember
to use main() for integration tests in order to test the argument API.
Kolibri ' s main function . Parses arguments and calls utility functions . Utility functions should be callable for unit testing purposes but remember to use main () for integration tests in order to test the argument API .
def main(args=None):  
    signal.signal(signal.SIGINT, signal.SIG_DFL)
    arguments, django_args = parse_args(args)
    debug = arguments["--debug"]
    if arguments["start"]:
        port = _get_port(arguments["--port"])
        if OPTIONS["Server"]["CHERRYPY_START"]:
            check_other_kolibri_running(port)
    try:
        initialize(debug=debug, skip_update=arguments["--skipupdate"])
    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
    daemon = not arguments["--foreground"]
    if sys.platform == "darwin":
        daemon = False
    if arguments["shell"]:
        arguments["manage"] = True
        arguments["COMMAND"] = "shell"
    if arguments["manage"]:
        command = arguments["COMMAND"]
        manage(command, args=django_args)
        return
    if arguments["plugin"]:
        plugin_name = arguments["PLUGIN"]
        plugin(plugin_name, **arguments)
        return
    if arguments["start"]:
        try:
            server._write_pid_file(server.STARTUP_LOCK, port)
        except (IOError, OSError):
            logger.warn(
                "Impossible to create file lock to communicate starting process"
            )
        check_content_directory_exists_and_writable()
        call_command("vacuumsqlite")
        call_command("clearsessions")
        start(port, daemon=daemon)
        return
    if arguments["stop"]:
        stop()
        return
    if arguments["status"]:
        status_code = status()
        sys.exit(status_code)
        return
    if arguments["services"]:
        try:
            server._write_pid_file(server.STARTUP_LOCK, None)
        except (IOError, OSError):
            logger.warn(
                "Impossible to create file lock to communicate starting process"
            )
        services(daemon=daemon)
        return
    if arguments["language"] and arguments["setdefault"]:
        set_default_language(arguments["<langcode>"])
def main ( args = None ) : signal . signal ( signal . SIGINT , signal . SIG_DFL ) arguments , django_args = parse_args ( args ) debug = arguments [ "--debug" ] if arguments [ "start" ] : port = _get_port ( arguments [ "--port" ] ) if OPTIONS [ "Server" ] [ "CHERRYPY_START" ] : check_other_kolibri_running ( port ) try : initialize ( debug = debug , skip_update = arguments [ "--skipupdate" ] ) 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 daemon = not arguments [ "--foreground" ] if sys . platform == "darwin" : daemon = False if arguments [ "shell" ] : arguments [ "manage" ] = True arguments [ "COMMAND" ] = "shell" if arguments [ "manage" ] : command = arguments [ "COMMAND" ] manage ( command , args = django_args ) return if arguments [ "plugin" ] : plugin_name = arguments [ "PLUGIN" ] plugin ( plugin_name , ** arguments ) return if arguments [ "start" ] : try : server . _write_pid_file ( server . STARTUP_LOCK , port ) except ( IOError , OSError ) : logger . warn ( "Impossible to create file lock to communicate starting process" ) check_content_directory_exists_and_writable ( ) call_command ( "vacuumsqlite" ) call_command ( "clearsessions" ) start ( port , daemon = daemon ) return if arguments [ "stop" ] : stop ( ) return if arguments [ "status" ] : status_code = status ( ) sys . exit ( status_code ) return if arguments [ "services" ] : try : server . _write_pid_file ( server . STARTUP_LOCK , None ) except ( IOError , OSError ) : logger . warn ( "Impossible to create file lock to communicate starting process" ) services ( daemon = daemon ) return if arguments [ "language" ] and arguments [ "setdefault" ] : set_default_language ( arguments [ "<langcode>" ] )
Kolibri's main function.
Kolibri ' s main function .
# noqa: max-complexity=13 """
    Kolibri's main function. Parses arguments and calls utility functions.
    Utility functions should be callable for unit testing purposes, but remember
    to use main() for integration tests in order to test the argument API.
    """ # On Mac, Python crashes when forking the process, so prevent daemonization until we can figure out # a better fix. See https://github.com/learningequality/kolibri/issues/4821 # Alias # Check if the content directory exists when Kolibri runs after the first time. # Defragment the db # Clear old sessions up
args