35 lines
875 B
Python
35 lines
875 B
Python
import os
|
|
import shutil
|
|
import subprocess
|
|
import time
|
|
|
|
from .postgres_container import PostgresContainer
|
|
|
|
ROOT_DIR = None
|
|
|
|
|
|
def run(args):
|
|
global ROOT_DIR
|
|
with PostgresContainer() as postgres:
|
|
locality_env = {
|
|
'LOCALITY_DATABASE_URL': postgres.get_url(),
|
|
'LOCALITY_STATIC_FILE_PATH': os.path.join(
|
|
ROOT_DIR,
|
|
'static'),
|
|
'LOCALITY_HMAC_SECRET': 'iknf4390-8guvmr3'
|
|
}
|
|
|
|
cargo_bin = shutil.which('cargo')
|
|
locality_process = subprocess.Popen(
|
|
[cargo_bin, 'run'], env=locality_env, cwd=ROOT_DIR
|
|
)
|
|
|
|
try:
|
|
while locality_process.poll() is None:
|
|
time.sleep(0.5)
|
|
except KeyboardInterrupt:
|
|
pass
|
|
finally:
|
|
if locality_process.poll() is None:
|
|
locality_process.terminate()
|