~ubuntu-branches/ubuntu/trusty/pisa/trusty

« back to all changes in this revision

Viewing changes to demo/tgpisa/tgpisa/commands.py

  • Committer: Bazaar Package Importer
  • Author(s): W. Martin Borgert
  • Date: 2010-02-08 22:02:40 UTC
  • Revision ID: james.westby@ubuntu.com-20100208220240-cwsifrpnqeaug5x5
Tags: upstream-3.0.32
ImportĀ upstreamĀ versionĀ 3.0.32

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# -*- coding: utf-8 -*-
 
2
"""This module contains functions called from console script entry points."""
 
3
 
 
4
import os
 
5
import sys
 
6
 
 
7
from os.path import dirname, exists, join
 
8
 
 
9
import pkg_resources
 
10
pkg_resources.require("TurboGears")
 
11
 
 
12
import turbogears
 
13
import cherrypy
 
14
 
 
15
cherrypy.lowercase_api = True
 
16
 
 
17
class ConfigurationError(Exception):
 
18
    pass
 
19
 
 
20
def start():
 
21
    """Start the CherryPy application server."""
 
22
 
 
23
    setupdir = dirname(dirname(__file__))
 
24
    curdir = os.getcwd()
 
25
 
 
26
    # First look on the command line for a desired config file,
 
27
    # if it's not on the command line, then look for 'setup.py'
 
28
    # in the current directory. If there, load configuration
 
29
    # from a file called 'dev.cfg'. If it's not there, the project
 
30
    # is probably installed and we'll look first for a file called
 
31
    # 'prod.cfg' in the current directory and then for a default
 
32
    # config file called 'default.cfg' packaged in the egg.
 
33
    if len(sys.argv) > 1:
 
34
        configfile = sys.argv[1]
 
35
    elif exists(join(setupdir, "setup.py")):
 
36
        configfile = join(setupdir, "dev.cfg")
 
37
    elif exists(join(curdir, "prod.cfg")):
 
38
        configfile = join(curdir, "prod.cfg")
 
39
    else:
 
40
        try:
 
41
            configfile = pkg_resources.resource_filename(
 
42
              pkg_resources.Requirement.parse("tgpisa"),
 
43
                "config/default.cfg")
 
44
        except pkg_resources.DistributionNotFound:
 
45
            raise ConfigurationError("Could not find default configuration.")
 
46
 
 
47
    turbogears.update_config(configfile=configfile,
 
48
        modulename="tgpisa.config")
 
49
 
 
50
    from tgpisa.controllers import Root
 
51
 
 
52
    turbogears.start_server(Root())