Skip to content

Commit

Permalink
Clean aimmo runner
Browse files Browse the repository at this point in the history
  • Loading branch information
faucomte97 committed Sep 5, 2022
1 parent cdd30e8 commit 3475518
Showing 1 changed file with 10 additions and 39 deletions.
49 changes: 10 additions & 39 deletions aimmo_runner/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,17 @@

import logging
import os
import sys
import time

import django
import sys
from django.conf import settings

from .shell_api import log, run_command, run_command_async

ROOT_DIR_LOCATION = os.path.abspath(os.path.dirname((os.path.dirname(__file__))))

_MANAGE_PY = os.path.join(ROOT_DIR_LOCATION, "example_project", "manage.py")
_FRONTEND_BUNDLER_JS = os.path.join(
ROOT_DIR_LOCATION, "game_frontend", "djangoBundler.js"
)
_FRONTEND_BUNDLER_JS = os.path.join(ROOT_DIR_LOCATION, "game_frontend", "djangoBundler.js")

PROCESSES = []

Expand All @@ -27,25 +24,18 @@ def create_superuser_if_missing(username, password):
User.objects.get_by_natural_key(username)
except User.DoesNotExist:
log("Creating superuser %s with password %s" % (username, password))
User.objects.create_superuser(
username=username, email="admin@admin.com", password=password
)
User.objects.create_superuser(username=username, email="admin@admin.com", password=password)


def build_worker_package():
run_command(
[os.path.join(ROOT_DIR_LOCATION, "aimmo_runner", "build_worker_wheel.sh")],
capture_output=True,
)
run_command([os.path.join(ROOT_DIR_LOCATION, "aimmo_runner", "build_worker_wheel.sh")], capture_output=True)


def build_frontend(using_cypress, capture_output):
if using_cypress:
run_command(["node", _FRONTEND_BUNDLER_JS], capture_output=capture_output)
else:
frontend_bundler = run_command_async(
["node", _FRONTEND_BUNDLER_JS], capture_output=capture_output
)
frontend_bundler = run_command_async(["node", _FRONTEND_BUNDLER_JS], capture_output=capture_output)
PROCESSES.append(frontend_bundler)


Expand All @@ -63,13 +53,7 @@ def start_game_servers(build_target, server_args):
os.environ["AIMMO_MODE"] = "minikube"


def run(
server_wait=True,
using_cypress=False,
capture_output=False,
test_env=False,
build_target=None,
):
def run(server_wait=True, using_cypress=False, capture_output=False, test_env=False, build_target=None):
logging.basicConfig()

build_worker_package()
Expand All @@ -90,31 +74,18 @@ def run(

build_frontend(using_cypress, capture_output)

run_command(
["pip", "install", "-e", ROOT_DIR_LOCATION], capture_output=capture_output
)
run_command(["pip", "install", "-e", ROOT_DIR_LOCATION], capture_output=capture_output)

if not test_env:
run_command(
["python", _MANAGE_PY, "migrate", "--noinput"],
capture_output=capture_output,
)
run_command(
["python", _MANAGE_PY, "collectstatic", "--noinput", "--clear"],
capture_output=capture_output,
)

# create_superuser_if_missing(username="admin", password="admin")
run_command(["python", _MANAGE_PY, "migrate", "--noinput"], capture_output=capture_output)
run_command(["python", _MANAGE_PY, "collectstatic", "--noinput", "--clear"], capture_output=capture_output)

server_args = []
if not using_cypress:
start_game_servers(build_target, server_args)

os.environ["SERVER_ENV"] = "local"
server = run_command_async(
["python", _MANAGE_PY, "runserver"] + server_args,
capture_output=capture_output,
)
server = run_command_async(["python", _MANAGE_PY, "runserver"] + server_args, capture_output=capture_output)
PROCESSES.append(server)

if server_wait:
Expand Down

0 comments on commit 3475518

Please sign in to comment.