funkwhale/api/funkwhale_api/common/management/commands/gitpod.py

73 wiersze
2.2 KiB
Python

from django.core.management.commands.migrate import Command as BaseCommand
from django.core.management import call_command
from funkwhale_api.music.models import Library
from funkwhale_api.users.models import User
import uvicorn
import debugpy
import os
class Command(BaseCommand):
help = "Manage gitpod environment"
def add_arguments(self, parser):
parser.add_argument("command", nargs="?", type=str)
def handle(self, *args, **options):
command = options["command"]
if not command:
return self.show_help()
if command == "init":
return self.init()
if command == "dev":
return self.dev()
def show_help(self):
self.stdout.write("")
self.stdout.write("Available commands:")
self.stdout.write("init - Initialize gitpod workspace")
self.stdout.write("dev - Run Funkwhale in development mode with debug server")
self.stdout.write("")
def init(self):
try:
user = User.objects.get(username="gitpod")
except Exception:
call_command("createsuperuser", username="gitpod", email="gitpod@example.com", no_input=False)
user = User.objects.get(username="gitpod")
user.set_password('gitpod')
if not user.actor:
user.create_actor()
user.save()
# Download music catalog
os.system("git clone https://dev.funkwhale.audio/funkwhale/catalog.git /tmp/catalog")
os.system("mv -f /tmp/catalog/music /workspace/funkwhale/data")
os.system("rm -rf /tmp/catalog/music")
# # Import music catalog into library
call_command("script", "migrate_to_user_libraries", no_input=False)
call_command(
"import_files",
Library.objects.get(actor=user.actor).uuid,
"/workspace/funkwhale/data/music/",
recursive=True,
in_place=True,
no_input=False,
)
def dev(self):
debugpy.listen(5678)
uvicorn.run(
"config.asgi:application",
host="0.0.0.0",
port=5000,
reload=True,
reload_dirs=["/workspace/funkwhale/api/config/", "/workspace/funkwhale/api/funkwhale_api/"],
)