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
|
|
|
|
|
|
|
from django.core.management.commands.runserver import Command as DjangoCommand
|
|
|
|
|
|
|
|
|
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.
|
|
|
|
date_prefix = datetime.now().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:
|
2021-05-25 01:25:00 +02:00
|
|
|
if (
|
2022-07-29 22:44:15 +02:00
|
|
|
message == "Performing system checks...\n\n"
|
|
|
|
or message.startswith("System check identified no issues")
|
|
|
|
or message.startswith(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):
|
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)
|