fedora-infrastructure/fas/fas/commands.py
Toshio Kuratomi b9c97d7e3e * Reference os.path commands with os.path namespace.
* Add check that dev.cfg exists before using it.
* Change production config name to fas.cfg
* Look for the config file in /etc
2008-03-08 12:29:50 -08:00

51 lines
1.8 KiB
Python

# -*- coding: utf-8 -*-
"""This module contains functions called from console script entry points."""
import os
import sys
import pkg_resources
pkg_resources.require("TurboGears")
import turbogears
import cherrypy
cherrypy.lowercase_api = True
class ConfigurationError(Exception):
pass
def start():
'''Start the CherryPy application server.'''
setupdir = os.path.dirname(os.path.dirname(__file__))
curdir = os.getcwd()
# First look on the command line for a desired config file,
# if it's not on the command line, then look for 'setup.py'
# in the current directory. If there, load configuration
# from a file called 'dev.cfg'. If it's not there, the project
# is probably installed and we'll look first for a file called
# 'prod.cfg' in the current directory and then for a default
# config file called 'default.cfg' packaged in the egg.
if len(sys.argv) > 1:
configfile = sys.argv[1]
elif os.path.exists(os.path.join(setupdir, 'setup.py')) \
and os.path.exists(os.path.join(setupdir, 'dev.cfg')):
configfile = os.path.join(setupdir, 'dev.cfg')
elif os.path.exists(os.path.join(curdir, 'fas.cfg')):
configfile = os.path.join(curdir, 'fas.cfg')
elif os.path.exists(os.path.join('/etc/fas.cfg')):
configfile = os.path.join('/etc/fas.cfg')
else:
try:
configfile = pkg_resources.resource_filename(
pkg_resources.Requirement.parse("fas"),
"config/default.cfg")
except pkg_resources.DistributionNotFound:
raise ConfigurationError("Could not find default configuration.")
turbogears.update_config(configfile=configfile,
modulename="fas.config")
from fas.controllers import Root
turbogears.start_server(Root())