Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Changes between Version 7 and Version 8 of TurboGearsOnDreamHost


Ignore:
Timestamp:
01/19/06 14:58:38 (13 years ago)
Author:
msarahan@…
Comment:

Added SVN code section

Legend:

Unmodified
Added
Removed
Modified
  • TurboGearsOnDreamHost

    v7 v8  
    390390WSGIServer(application=wsgiApp).run() 
    391391}}} 
     392 
     393= Code for SVN/0.9 = 
     394 
     395{{{ 
     396#!/home/<user>/bin/python/bin/python 
     397# 
     398# File name: tg_fastcgi.fcgi 
     399# 
     400# This module provides the glue for running TurboGears applications behind  
     401# FastCGI-enabled web servers. The code in this module depends on the fastcgi 
     402# module downloadable from here: 
     403# 
     404# http://www.saddi.com/software/py-lib/py-lib/fcgi.py 
     405# 
     406# NOTE: The fcgi.py file needs to be placed in a location that is on the 
     407# system path, such as the same the directory as the tg_fastcgi.py file 
     408# or in the base directory of the TG app code. 
     409# 
     410# To configure this module, please edit the three variables in the "USER EDIT 
     411# SECTION" before starting the TG application.  Also remember to edit the 
     412# top of this file with the correct Python installation information.  Please note additional edits required for 0.9 - ALL CAPS! 
     413 
     414import cherrypy 
     415import sys 
     416import os 
     417from os.path import * 
     418import pkg_resources 
     419 
     420pkg_resources.require("TurboGears") 
     421 
     422# -- START USER EDIT SECTION 
     423# -- Users must edit this section --  
     424code_dir = ''           # (Required) The base directory of the TG app code. 
     425root_class_name = ''    # (Required) The fully qualified Root class name. 
     426log_dir = ''            # (Optional) The log directory. Default = code_dir. 
     427# -- END USER EDIT SECTION 
     428 
     429def tg_init(): 
     430    """ Checks for the required data and initializes the application. """ 
     431 
     432    global code_dir 
     433    global root_class_name 
     434    global log_dir 
     435    last_mark = 0 
     436 
     437    # Input checks 
     438    if not code_dir or not isdir(code_dir): 
     439        raise ValueError("""The code directory setting is missing. 
     440                            The fastcgi code will be unable to find 
     441                            the TG code without this setting.""") 
     442 
     443    if not root_class_name: 
     444        raise ValueError("""The fully qualified root class name must 
     445                            be provided.""") 
     446 
     447    last_mark = root_class_name.rfind('.') 
     448     
     449    if (last_mark < 1) or (last_mark + 1) == len(root_class_name): 
     450        raise ValueError("""The user-defined class name is invalid. 
     451                            Please make sure to include a fully 
     452                            qualified class name for the root_class 
     453                            value (e.g. wiki20.controllers.Root).""")     
     454 
     455    sys.path.append(code_dir) 
     456 
     457    # Change the directory so the TG log file will not be written to the 
     458    # web app root. 
     459    if log_dir and isdir(log_dir): 
     460        os.chdir(log_dir) 
     461    else: 
     462        os.chdir(code_dir) 
     463        log_dir = code_dir 
     464 
     465    sys.stdout = open(join(log_dir, 'stdout.log'),'a') 
     466    sys.stderr = open(join(log_dir, 'stderr.log'),'a')         
     467 
     468    if exists(join(code_dir, "setup.py")): 
     469        turbogears.update_config(configfile=join(code_dir, "devcfg.py"),modulename="PROJECTNAME.config") 
     470    else: 
     471        turbogears.update_config(configfile=join(code_dir, "prodcfg.py"),modulename="PROJECTNAME.config") 
     472 
     473    # Set environment to production to disable auto-reload and 
     474    # add virutal path information. 
     475    cherrypy.config.update({ 
     476        'global': {'server.environment': 'production'}}) 
     477 
     478    # Parse out the root class information for Cherrypy Root class. 
     479    package_name = root_class_name[:last_mark] 
     480    class_name = root_class_name[last_mark+1:] 
     481    exec('from %s import %s as Root' % (package_name, class_name)) 
     482    cherrypy.root = Root() 
     483 
     484# Main section - 
     485# Initialize the application, then start the server. 
     486tg_init() 
     487 
     488from fcgi import WSGIServer 
     489cherrypy.server.start(initOnly=True, serverClass=None) 
     490 
     491from cherrypy._cpwsgi import wsgiApp 
     492WSGIServer(application=wsgiApp).run() 
     493}}}