22"""Main application"""
33
44import logging
5+ from collections .abc import Callable
56from pprint import pformat
67from typing import Any
78
1112 setup_realtime_collaboration ,
1213)
1314
14- from ._meta import WELCOME_DB_LISTENER_MSG , WELCOME_GC_MSG , WELCOME_MSG , info
15+ from ._meta import (
16+ WELCOME_AUTH_APP_MSG ,
17+ WELCOME_DB_LISTENER_MSG ,
18+ WELCOME_GC_MSG ,
19+ WELCOME_MSG ,
20+ info ,
21+ )
1522from .activity .plugin import setup_activity
1623from .announcements .plugin import setup_announcements
1724from .api_keys .plugin import setup_api_keys
6269_logger = logging .getLogger (__name__ )
6370
6471
65- async def _welcome_banner (app : web .Application ):
66- settings = get_application_settings (app )
67- print (WELCOME_MSG , flush = True ) # noqa: T201
68- if settings .WEBSERVER_GARBAGE_COLLECTOR :
69- print ("with" , WELCOME_GC_MSG , flush = True ) # noqa: T201
70- if settings .WEBSERVER_DB_LISTENER :
71- print ("with" , WELCOME_DB_LISTENER_MSG , flush = True ) # noqa: T201
72+ def _create_welcome_banner (banner_msg : str ) -> Callable :
73+ """Creates a welcome banner function with optional GC and DB listener messages"""
74+
75+ async def _welcome_banner (app : web .Application ):
76+ settings = get_application_settings (app )
77+
78+ print (banner_msg , flush = True ) # noqa: T201
79+ if settings .WEBSERVER_GARBAGE_COLLECTOR :
80+ print ("with" , WELCOME_GC_MSG , flush = True ) # noqa: T201
81+ if settings .WEBSERVER_DB_LISTENER :
82+ print ("with" , WELCOME_DB_LISTENER_MSG , flush = True ) # noqa: T201
83+
84+ return _welcome_banner
85+
86+
87+ def _create_finished_banner () -> Callable :
88+ """Creates a finished banner function"""
7289
90+ async def _finished_banner (app : web .Application ):
91+ assert app # nosec
92+ print (info .get_finished_banner (), flush = True ) # noqa: T201
7393
74- async def _finished_banner (app : web .Application ):
75- assert app # nosec
76- print (info .get_finished_banner (), flush = True ) # noqa: T201
94+ return _finished_banner
7795
7896
7997def create_application () -> web .Application :
@@ -166,8 +184,8 @@ def create_application() -> web.Application:
166184 setup_realtime_collaboration (app )
167185
168186 # NOTE: *last* events
169- app .on_startup .append (_welcome_banner )
170- app .on_shutdown .append (_finished_banner )
187+ app .on_startup .append (_create_welcome_banner ( WELCOME_MSG ) )
188+ app .on_shutdown .append (_create_finished_banner () )
171189
172190 _logger .debug ("Routes in app: \n %s" , pformat (app .router .named_resources ()))
173191
@@ -183,8 +201,8 @@ def create_application_auth() -> web.Application:
183201 setup_login_auth (app )
184202
185203 # NOTE: *last* events
186- app .on_startup .append (_welcome_banner )
187- app .on_shutdown .append (_finished_banner )
204+ app .on_startup .append (_create_welcome_banner ( WELCOME_AUTH_APP_MSG ) )
205+ app .on_shutdown .append (_create_finished_banner () )
188206
189207 _logger .debug (
190208 "Routes in application-auth: \n %s" , pformat (app .router .named_resources ())
0 commit comments