aift

AIFT application entry point.

This module serves as the main entry point for the AI Forensic Triage (AIFT) application. It validates the Python runtime version, loads the YAML configuration, creates the Flask application, and starts the local development server. A browser window is automatically opened after a short delay.

Usage::

python aift.py
 1"""AIFT application entry point.
 2
 3This module serves as the main entry point for the AI Forensic Triage (AIFT)
 4application. It validates the Python runtime version, loads the YAML
 5configuration, creates the Flask application, and starts the local development
 6server. A browser window is automatically opened after a short delay.
 7
 8Usage::
 9
10    python aift.py
11"""
12
13from __future__ import annotations
14
15import sys
16import threading
17import webbrowser
18
19from runtime_compat import UnsupportedPythonVersionError, assert_supported_python_version
20
21
22def main() -> None:
23    """Load configuration, create the Flask app, and start the development server.
24
25    Reads server host and port from ``config.yaml``, creates the Flask
26    application via the application factory, schedules a browser launch
27    after a 1-second delay, and starts the Flask development server with
28    the reloader and debug mode disabled.
29
30    Raises:
31        UnsupportedPythonVersionError: If the active Python version falls
32            outside the supported range (3.10 -- 3.13).
33    """
34    assert_supported_python_version()
35
36    from app import create_app
37    from app.config import ConfigurationError, load_config
38
39    try:
40        config = load_config()
41    except ConfigurationError as exc:
42        print(
43            f"ERROR: Cannot start AIFT — invalid configuration:\n"
44            + "\n".join(f"  - {e}" for e in exc.errors),
45            file=sys.stderr,
46        )
47        raise SystemExit(1) from None
48
49    server_config = config.get("server", {})
50    host = server_config.get("host", "127.0.0.1")
51    port = int(server_config.get("port", 5000))
52
53    app = create_app()
54    url = f"http://{host}:{port}"
55
56    def _open_browser() -> None:
57        try:
58            webbrowser.open(url)
59        except Exception:
60            # Browser launch failures should not prevent server startup.
61            pass
62
63    threading.Timer(1.0, _open_browser).start()
64    app.run(host=host, port=port, debug=False, use_reloader=False)
65
66
67if __name__ == "__main__":
68    try:
69        main()
70    except UnsupportedPythonVersionError as error:
71        print(str(error), file=sys.stderr)
72        raise SystemExit(1) from None
def main() -> None:
23def main() -> None:
24    """Load configuration, create the Flask app, and start the development server.
25
26    Reads server host and port from ``config.yaml``, creates the Flask
27    application via the application factory, schedules a browser launch
28    after a 1-second delay, and starts the Flask development server with
29    the reloader and debug mode disabled.
30
31    Raises:
32        UnsupportedPythonVersionError: If the active Python version falls
33            outside the supported range (3.10 -- 3.13).
34    """
35    assert_supported_python_version()
36
37    from app import create_app
38    from app.config import ConfigurationError, load_config
39
40    try:
41        config = load_config()
42    except ConfigurationError as exc:
43        print(
44            f"ERROR: Cannot start AIFT — invalid configuration:\n"
45            + "\n".join(f"  - {e}" for e in exc.errors),
46            file=sys.stderr,
47        )
48        raise SystemExit(1) from None
49
50    server_config = config.get("server", {})
51    host = server_config.get("host", "127.0.0.1")
52    port = int(server_config.get("port", 5000))
53
54    app = create_app()
55    url = f"http://{host}:{port}"
56
57    def _open_browser() -> None:
58        try:
59            webbrowser.open(url)
60        except Exception:
61            # Browser launch failures should not prevent server startup.
62            pass
63
64    threading.Timer(1.0, _open_browser).start()
65    app.run(host=host, port=port, debug=False, use_reloader=False)

Load configuration, create the Flask app, and start the development server.

Reads server host and port from config.yaml, creates the Flask application via the application factory, schedules a browser launch after a 1-second delay, and starts the Flask development server with the reloader and debug mode disabled.

Raises:
  • UnsupportedPythonVersionError: If the active Python version falls outside the supported range (3.10 -- 3.13).