cmsmanage/doorcontrol/management/commands/update_doors.py
Adam Goldsmith b6280d701f
All checks were successful
Ruff / ruff (push) Successful in 2m1s
Test / test (push) Successful in 7m20s
doorcontrol: Migrate door updater over from memberPlumbing
2024-02-23 18:39:41 -05:00

33 lines
1.0 KiB
Python

import logging
from django.core.management.base import BaseCommand, CommandError
from doorcontrol.models import Door
from doorcontrol.tasks.update_doors import logger, update_door
class Command(BaseCommand):
def add_arguments(self, parser):
parser.add_argument("door_names", nargs="*")
parser.add_argument("--dry-run", action="store_true")
def handle(
self, *args, door_names: list[str], dry_run: bool, verbosity: int, **options
):
verbosity_levels = {
0: logging.ERROR,
1: logging.WARNING,
2: logging.INFO,
3: logging.DEBUG,
}
logger.setLevel(verbosity_levels.get(verbosity, logging.WARNING))
doors = Door.objects.all()
if door_names:
doors = doors.filter(name__in=door_names)
if len(doors) != len(door_names):
raise CommandError("Not all door names matched doors in database")
for door in doors:
update_door(door, dry_run=dry_run)