mirror of
https://github.com/bugsink/bugsink.git
synced 2025-12-20 20:41:01 -06:00
As had been noted on some of the commands, 'ingest' was not the best place for them. However, [project-level apps are not supported in Django](https://forum.djangoproject.com/t/allow-project-to-have-management-commands/5220/2) So just create a 'main' app. I want to qualify it as 'myproject-main' though, to avoid further unqualified global namespace pollution. And I want to avoid prefixing with 'bugsink' b/c that's annoying for tab-completion. So 'bs' it is. I've moved all commands over; even though a case could be made that the "feeding" commands (raise_exception, send_json, stress_test) are somewhat related to ingestion, that's not a very good case :-)
31 lines
1.2 KiB
Python
31 lines
1.2 KiB
Python
import os
|
|
|
|
from django.core.management.base import BaseCommand
|
|
from django.contrib.auth import get_user_model
|
|
|
|
from phonehome.tasks import send_if_due
|
|
|
|
|
|
User = get_user_model()
|
|
|
|
|
|
class Command(BaseCommand):
|
|
help = "Pre-start command to run before the server starts."
|
|
|
|
def handle(self, *args, **options):
|
|
if os.getenv("CREATE_SUPERUSER", ""):
|
|
if ":" not in os.getenv("CREATE_SUPERUSER"):
|
|
raise ValueError("CREATE_SUPERUSER should be in the format 'username:password'")
|
|
|
|
username, password = os.getenv("CREATE_SUPERUSER").split(":")
|
|
|
|
if not User.objects.filter(username=username).exists():
|
|
User.objects.create_superuser(username=username, password=password)
|
|
print(f"Superuser created: {username}")
|
|
|
|
# Similar considerations apply here as those which are documented in bugsink.views._phone_home().
|
|
# By putting this in prestart, we add one more location to the list of kick-off locations; with the added
|
|
# benefit that this particular location also gives some signal for (Docker) installations that are prematurely
|
|
# aborted (i.e. we get a ping even if 'home' is never even reached).
|
|
send_if_due.delay()
|