[Zope-Checkins] CVS: Zope/bin - zope.py:1.1.2.1

Chris McDonough chrism@zope.com
Sun, 29 Sep 2002 17:48:24 -0400


Update of /cvs-repository/Zope/bin
In directory cvs.zope.org:/tmp/cvs-serv14316/bin

Added Files:
      Tag: chrism-install-branch
	zope.py 
Log Message:
Move some files around that were committed into the wrong locations.


=== Added File Zope/bin/zope.py ===
##############################################################################
#
# Copyright (c) 2001 Zope Corporation and Contributors. All Rights Reserved.
#
# This software is subject to the provisions of the Zope Public License,
# Version 2.0 (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
#
##############################################################################
"""
This is a replacement for z2.py which uses a config file.

Do not change this file unless you know what you're doing. ;-)
"""

import os, sys, getopt, warnings, traceback

# assume that this file is sys.argv[0], and that it lives in ZOPE_HOME
# or ZOPE_HOME/bin in order to set get the default SOFTWARE_HOME appropriately
# so we can get at the Controller package.

HERE = os.path.split(os.path.abspath(os.path.normpath(sys.argv[0])))[0]
if os.path.split(HERE)[1] == 'bin':
    # zope.py is probably in a 'bin' directory in the ZOPE_HOME
    SOFTWARE_HOME = os.path.join(os.path.split(HERE)[0], 'lib', 'python')
else:
    # zope.py is probably in the root directory of the ZOPE_HOME
    SOFTWARE_HOME = os.path.join(HERE, 'lib', 'python')

def check_python_version():
    # check for Python version
    python_version = sys.version.split()[0]
    if python_version < '2.1':
        raise 'Invalid python version', python_version
    if python_version[:3] == '2.1':
        if python_version[4:5] < '3':
            err = ('You are running Python version %s.  This Python version '
                   'has known bugs that may cause Zope to run improperly. '
                   'Consider upgrading to a Python in the 2.1 series '
                   'with at least version number 2.1.3.  (Note that Zope does '
                   'not yet run under any Python 2.2 version).' %
                   python_version)
            warnings.warn(err)
    if python_version[:3] == '2.2':
        err = ('You are running Python version %s.  This Python version '
               'has not yet been tested with Zope and you may experience '
               'operational problems as a result.  Consider using '
               'Python 2.1.3 instead.' % python_version)
        warnings.warn(err)

def usage():
    print """
zope.py [--config-location=filename-or-url] [--software_home=path]

zope.py starts a Zope instance.

If the software-home option is not passed, Zope assumes that the software
home

If the config-location option is not passed, an attempt is made to obtain
configuration info from a file in the current working directory named
'%s'.  An alternate absolute or relative filename may be
provided, or a URL may be provided.  If a URL is specified, it should begin
with 'http://'.  The url should return a file in the same format as the
filesystem config file.
""" % {'me':sys.argv[0]}

if __name__ == '__main__':
    check_python_version()
    config_location = 'zope.conf'
    url = None
    sw_home = SOFTWARE_HOME
    longopts = [ "help", "config-location="]
    try:
        opts, args = getopt.getopt(sys.argv[1:], "h", longopts)
    except getopt.GetoptError, v:
        print v
        usage()
        sys.exit(127)
    for k, v in opts:
        if k in ('-h', '--help'):
            usage()
            sys.exit(0)
        if k == '--config-location':
            config_location = v
        if k == '--software-home':
            sw_home = v
    if not os.path.exists(sw_home):
        print "software-home directory %s doesn't exist!" % sw_home
        usage()
        sys.exit(127)
    # an importer may have already set SOFTWARE_HOME
    if sw_home not in sys.path:
        sys.path.insert(0, sw_home)
    try:
        from Controller import Main
        Main.start_zope(config_location)
    except SystemExit:
        pass
    except:
        try:
            import zLOG
            zLOG.LOG("Zope Initialization", zLOG.PANIC, "Startup exception",
                     error=sys.exc_info())
        except:
            pass
        traceback.print_exc()
        # tell zdaemon not to restart us by setting 255 exit code
        sys.exit(255)