Source code for ferrosoft.apps.ferrobase.management.commands.ferrobase_update

#  Copyright (c) 2025 Ferrosoft GmbH. All rights reserved.
from django.core.management import BaseCommand
from django.core.management.base import OutputWrapper
from django.core.management.color import Style

from ferrosoft.apps.ferrobase.services.update import StatusWriter, Updater


[docs] class CommandStatusWriter(StatusWriter): """Bridges ``Updater`` status callbacks to Django management command output. Maps ``StatusWriter`` severity levels (error, notice, success) to the corresponding Django ``OutputWrapper`` style methods so that messages are coloured consistently with other management output. """ def __init__(self, output: OutputWrapper, style: Style) -> None: self.output = output self.style = style
[docs] def error(self, message: str): self.output.write(self.style.ERROR(message))
[docs] def notice(self, message: str): self.output.write(self.style.NOTICE(message))
[docs] def success(self, message: str): self.output.write(self.style.SUCCESS(message))
[docs] class Command(BaseCommand): """Management command that synchronises database resources with the current release. Invokes ``Updater.run`` which upserts built-in data (countries, languages, measurement units, subscription plans, etc.) into the master database. Progress and errors are reported through ``CommandStatusWriter``. """ help = "Update database resources with data from current release."
[docs] def handle(self, *args, **options): Updater().run(CommandStatusWriter(self.stdout, self.style))