#!/usr/bin/env python2.3
##############################################################################
#
# Copyright (c) 2004 Zope Corporation and Contributors.
# All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.1 (ZPL).  A copy of the ZPL should accompany this distribution.
# THIS SOFTWARE IS PROVIDED "AS IS" AND ANY AND ALL EXPRESS OR IMPLIED
# WARRANTIES ARE DISCLAIMED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF TITLE, MERCHANTABILITY, AGAINST INFRINGEMENT, AND FITNESS
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
"""Script to run the Zope Application Server from the Python prompt.

$Id: debugzope 28654 2004-12-20 21:13:50Z gintautasm $
"""
import os
import sys

os.environ["PYTHONINSPECT"] = "true"

SCRIPT_NAME = os.path.abspath(__file__)
INSTANCE_HOME = os.path.dirname(os.path.dirname(SCRIPT_NAME))
del SCRIPT_NAME
SOFTWARE_HOME = os.path.join(INSTANCE_HOME, "src")

if SOFTWARE_HOME not in sys.path:
    sys.path.insert(0, SOFTWARE_HOME)

CONFIG_FILE = os.path.join(INSTANCE_HOME, "zope.conf")
if not os.path.exists(CONFIG_FILE):
    CONFIG_FILE += ".in"


def startup():
    # This removes the script directory from sys.path, which we do
    # since there are no modules here.
    #
    basepath = filter(None, sys.path)

    sys.path[:] = [os.path.join(INSTANCE_HOME, "lib", "python"),
                   SOFTWARE_HOME] + basepath

    from zope.app.server.main import debug
    db = debug(["-C", CONFIG_FILE] + sys.argv[1:])
    if "PYTHONSTARTUP" in os.environ:
        execfile(os.environ["PYTHONSTARTUP"])
    return db


if __name__ == '__main__':
    db = startup()
    del startup
    from zope.app.debug import Debugger
    debugger = Debugger.fromDatabase(db)
    del db
    del Debugger
