mirror of
https://github.com/QingdaoU/OnlineJudge.git
synced 2025-11-04 14:49:58 +08:00
增加initinstall命令
This commit is contained in:
parent
40573615ec
commit
f19aa20817
@ -2,11 +2,9 @@
|
|||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
import MySQLdb
|
import MySQLdb
|
||||||
|
|
||||||
"""
|
"""
|
||||||
docker-compose启动的时候是并行启动的,可能执行本脚本的时候MySQL还没启动完
|
docker-compose启动的时候是并行启动的,可能执行本脚本的时候MySQL还没启动完
|
||||||
"""
|
"""
|
||||||
|
|
||||||
i = 3
|
i = 3
|
||||||
while i:
|
while i:
|
||||||
try:
|
try:
|
||||||
@ -21,6 +19,5 @@ while i:
|
|||||||
print "Failed to create database, error: " + str(e) + ", will retry in 3 seconds"
|
print "Failed to create database, error: " + str(e) + ", will retry in 3 seconds"
|
||||||
i -= 1
|
i -= 1
|
||||||
time.sleep(3)
|
time.sleep(3)
|
||||||
|
|
||||||
print "Failed to create database"
|
print "Failed to create database"
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|||||||
21
utils/management/commands/initinstall.py
Normal file
21
utils/management/commands/initinstall.py
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
# coding=utf-8
|
||||||
|
|
||||||
|
from django.core.management.base import BaseCommand
|
||||||
|
import os
|
||||||
|
|
||||||
|
|
||||||
|
class Command(BaseCommand):
|
||||||
|
def handle(self, *args, **options):
|
||||||
|
try:
|
||||||
|
if os.system("python manage.py migrate") != 0:
|
||||||
|
self.stdout.write(self.style.ERROR("Failed to execute command 'migrate'"))
|
||||||
|
exit(1)
|
||||||
|
if os.system("python manage.py migrate --database=submission") != 0:
|
||||||
|
self.stdout.write(self.style.ERROR("Failed to execute command 'migrate --database=submission'"))
|
||||||
|
exit(1)
|
||||||
|
if os.system("python manage.py initadmin") != 0:
|
||||||
|
self.stdout.write(self.style.ERROR("Failed to execute command 'initadmin'"))
|
||||||
|
exit(1)
|
||||||
|
self.stdout.write(self.style.SUCCESS("Done"))
|
||||||
|
except Exception as e:
|
||||||
|
self.stdout.write(self.style.ERROR("Failed to initialize, error: " + str(e)))
|
||||||
Loading…
Reference in New Issue
Block a user