🧑‍💻(tasks) run management commands

This allows to run management commands from a celery task.
This commit is contained in:
Quentin BEY
2025-03-14 17:16:25 +01:00
committed by BEY Quentin
parent f0258bbde7
commit 1ec98f0948
5 changed files with 159 additions and 7 deletions

View File

@@ -0,0 +1,49 @@
"""Utility module providing I/O related classes and functions."""
from io import StringIO
class TeeStringIO:
"""String IO implementation that captures output while preserving original logger output."""
def __init__(self, logger_output):
"""Initialize a TeeStringIO instance.
Args:
logger_output: A callable that will receive captured output.
"""
self.logger_output = logger_output
self.buffer = StringIO()
def write(self, value):
"""Write a string to both the logger and internal buffer.
Args:
value: The string to write.
"""
self.logger_output(value.strip("\n"))
self.buffer.write(value)
def read(self):
"""Read the contents of the buffer.
Returns:
The buffer contents as a string.
"""
return self.buffer.read()
def seek(self, *args, **kwargs):
"""Set the buffer's position.
Args:
*args: Positional arguments passed to the underlying buffer.
**kwargs: Keyword arguments passed to the underlying buffer.
Returns:
The new position in the buffer.
"""
return self.buffer.seek(*args, **kwargs)
def flush(self):
"""Flush the internal buffer."""
self.buffer.flush()