#!/usr/bin/env python
import os
import sys

from unipath import Path

if __name__ == "__main__":
    os.environ.setdefault("DJANGO_SETTINGS_MODULE", "instance1_site.settings.stage")

    BASE_DIR = Path(os.path.abspath(__file__)).parent

    # Set PYTHONPATH to include project directory
    sys.path.insert(0, BASE_DIR)

    # Also include lib/ directory in our project
    sys.path.insert(0, BASE_DIR.child('lib'))

    # Let us find where we have Booktype installed
    if 'BOOKTYPE' in os.environ:
        sys.path.insert(0, os.path.join(os.environ['BOOKTYPE'], 'lib'))
    else:
        sys.path.insert(0, '/usr/local/src/booktype/lib')

    from django.core.management import execute_from_command_line

    execute_from_command_line(sys.argv)