From 01e9cfb5043e66e317ea094135488251fbe63405 Mon Sep 17 00:00:00 2001 From: Hironsan Date: Mon, 21 Feb 2022 14:13:41 +0900 Subject: [PATCH] Replace subprocess with call_command --- backend/cli.py | 28 +++++++++------------------- 1 file changed, 9 insertions(+), 19 deletions(-) diff --git a/backend/cli.py b/backend/cli.py index cca13d75..6d358f10 100644 --- a/backend/cli.py +++ b/backend/cli.py @@ -2,16 +2,18 @@ import argparse import multiprocessing import os import platform -import subprocess import sys +import django +from django.core import management + from .config.celery import app os.environ["STANDALONE"] = "True" os.environ.setdefault("DJANGO_SETTINGS_MODULE", "config.settings.production") base = os.path.abspath(os.path.dirname(__file__)) sys.path.append(base) -manage_path = os.path.join(base, "manage.py") +django.setup() parser = argparse.ArgumentParser(description="doccano, text annotation for machine learning practitioners.") @@ -56,27 +58,15 @@ def run_on_windows(args): def command_db_init(args): print("Setup Database.") - subprocess.call([sys.executable, manage_path, "wait_for_db"], shell=False) - subprocess.call([sys.executable, manage_path, "migrate"], shell=False) - subprocess.call([sys.executable, manage_path, "create_roles"], shell=False) + management.call_command("wait_for_db") + management.call_command("migrate") + management.call_command("create_roles") def command_user_create(args): print("Create admin user.") - subprocess.call( - [ - sys.executable, - manage_path, - "create_admin", - "--username", - args.username, - "--password", - args.password, - "--email", - args.email, - "--noinput", - ], - shell=False, + management.call_command( + "create_admin", "--noinput", username=args.username, password=args.password, email=args.email )