#!/usr/bin/env python2.7

## Add path for when we're not already in the path (via proper installation).

import sys
import os
dev_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..', '..'))
sys.path.insert(0, dev_path)

## Change to the root of the project (which Gunicorn requires).

import mr
root_path = os.path.abspath(os.path.join(os.path.dirname(mr.__file__), '..'))

os.chdir(root_path)

## Start Gunicorn.

import subprocess

cmd = ['gunicorn', '-c', 'mr/resources/data/gunicorn_conf_dev.py', 'mr.app.main:app']

p = subprocess.Popen(cmd, env=os.environ)
r = p.wait()
if r != 0:
    raise EnvironmentError("Gunicorn launch failed.")
