manage.py 1.46 KB
Newer Older
Tanner Prestegard's avatar
Tanner Prestegard committed
1
#!/usr/bin/env python
2

Tanner Prestegard's avatar
Tanner Prestegard committed
3
import os
4
from os.path import abspath, dirname, exists, join
Tanner Prestegard's avatar
Tanner Prestegard committed
5
import sys
Brian Moe's avatar
Brian Moe committed
6

7
# Parameters
8
DEFAULT_SETTINGS_MODULE = 'config.settings.vm.dev'
9
PROJECT_ROOT_NAME = 'gracedb'
10 11
BASE_DIR = abspath(dirname(__file__))
VENV_PATH = abspath(join(BASE_DIR, '..', 'djangoenv'))
12 13

if __name__ == '__main__':
14
    # Add the project root to the python path.
15 16
    sys.path.append(join(BASE_DIR, PROJECT_ROOT_NAME))

17 18 19
    # Set up virtualenv if it exists and is not active
    if (exists(VENV_PATH) and 'VIRTUAL_ENV' not in os.environ):
        VIRTUALENV_ACTIVATOR = abspath(join(VENV_PATH, 'bin',
20 21
            'activate_this.py'))
        execfile(VIRTUALENV_ACTIVATOR, dict(__file__=VIRTUALENV_ACTIVATOR))
22

23 24 25
    # Set DJANGO_SETTINGS_MODULE environment variable
    os.environ.setdefault('DJANGO_SETTINGS_MODULE', DEFAULT_SETTINGS_MODULE)

Tanner Prestegard's avatar
Tanner Prestegard committed
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
    try:
        from django.core.management import execute_from_command_line
    except ImportError:
        # The above import may fail for some other reason. Ensure that the
        # issue is really that Django is missing to avoid masking other
        # exceptions on Python 2.
        try:
            import django
        except ImportError:
            raise ImportError(
                "Couldn't import Django. Are you sure it's installed and "
                "available on your PYTHONPATH environment variable? Did you "
                "forget to activate a virtual environment?"
            )
        raise
41
    execute_from_command_line(sys.argv)