2021-05-25 01:25:00 +02:00
|
|
|
from datetime import datetime
|
2022-07-29 22:44:15 +02:00
|
|
|
from functools import wraps
|
|
|
|
from typing import Callable
|
2020-10-12 19:48:47 +02:00
|
|
|
|
2022-12-26 00:35:56 +01:00
|
|
|
from dateutil.tz import tzlocal
|
2020-10-12 19:48:47 +02:00
|
|
|
from django.core.management.commands.runserver import Command as DjangoCommand
|
2023-10-12 19:43:45 +02:00
|
|
|
from typing_extensions import override
|
2020-10-12 19:48:47 +02:00
|
|
|
|
|
|
|
|
2022-07-29 22:44:15 +02:00
|
|
|
def output_styler(style_func: Callable[[str], str]) -> Callable[[str], str]:
|
|
|
|
# Might fail to suppress the date line around midnight, but, whatever.
|
2022-12-26 00:35:56 +01:00
|
|
|
date_prefix = datetime.now(tzlocal()).strftime("%B %d, %Y - ")
|
2020-10-12 19:48:47 +02:00
|
|
|
|
2022-07-29 22:44:15 +02:00
|
|
|
@wraps(style_func)
|
|
|
|
def _wrapped_style_func(message: str) -> str:
|
2023-02-09 00:16:37 +01:00
|
|
|
if message == "Performing system checks...\n\n" or message.startswith(
|
|
|
|
("System check identified no issues", date_prefix)
|
2021-05-25 01:25:00 +02:00
|
|
|
):
|
2022-07-29 22:44:15 +02:00
|
|
|
message = ""
|
|
|
|
elif "Quit the server with " in message:
|
|
|
|
message = (
|
|
|
|
"Django process (re)started. " + message[message.index("Quit the server with ") :]
|
2021-02-12 08:19:30 +01:00
|
|
|
)
|
2022-07-29 22:44:15 +02:00
|
|
|
return style_func(message)
|
2021-05-25 01:25:00 +02:00
|
|
|
|
2022-07-29 22:44:15 +02:00
|
|
|
return _wrapped_style_func
|
2021-05-25 01:25:00 +02:00
|
|
|
|
|
|
|
|
2022-07-29 22:44:15 +02:00
|
|
|
class Command(DjangoCommand):
|
2023-10-12 19:43:45 +02:00
|
|
|
@override
|
2021-05-25 01:25:00 +02:00
|
|
|
def inner_run(self, *args: object, **options: object) -> None:
|
2022-07-29 22:44:15 +02:00
|
|
|
self.stdout.style_func = output_styler(self.stdout.style_func)
|
|
|
|
super().inner_run(*args, **options)
|