Turbogears... almost there!

apps

#1

Hi all

I’m hopefully on my last mile in setting up turbogears to work with my shared hosting account, but I need some help. I am using fastcgi to run turbogears behind apache. The file dispatch.fcgi is in a directory one below the web root and is as follows:


import sys
import os
from os.path import *
import cherrypy
import pkg_resources
import turbogears

pkg_resources.require(“TurboGears”)

– START USER EDIT SECTION

– Users must edit this section –

code_dir = ‘/home/zubinweb/tg_web/Wiki-20/’ # (Required) The base directory of the TG app code.
root_class_name = ‘wiki20.controllers.Root’ # (Required) The fully qualified Root class name.
project_module_name = ‘wiki20.config’ # (Required) The config module name. Replace

PROJECTNAME with your project’s name (e.g. wiki20).

log_dir = ‘’ # (Optional) The log directory. Default = code_dir.

– END USER EDIT SECTION

def tg_init():
""" Checks for the required data and initializes the application. “”"

global code_dir
global root_class_name
global log_dir
global project_module_name
last_mark = 0

Input checks

if not code_dir or not isdir(code_dir):
raise ValueError(""“The code directory setting is missing.
The fastcgi code will be unable to find
the TG code without this setting.”"")

if not root_class_name:
raise ValueError(""“The fully qualified root class name must
be provided.”"")

last_mark = root_class_name.rfind(’.’)

if (last_mark < 1) or (last_mark + 1) == len(root_class_name):
raise ValueError(""“The user-defined class name is invalid.
Please make sure to include a fully
qualified class name for the root_class
value (e.g. wiki20.controllers.Root).”"")

sys.path.append(code_dir)

Change the directory so the TG log file will not be written to the

web app root.

if log_dir and isdir(log_dir):
os.chdir(log_dir)
else:
os.chdir(code_dir)
log_dir = code_dir

sys.stdout = open(join(log_dir, ‘stdout.log’),‘a’)
sys.stderr = open(join(log_dir, ‘stderr.log’),‘a’)

if exists(join(code_dir, “setup.py”)):
turbogears.update_config(configfile=join(code_dir, “devcfg.py”),modulename=project_module_name)
else:
turbogears.update_config(configfile=join(code_dir, “prodcfg.py”),modulename=project_module_name)

Set environment to production to disable auto-reload and

add virutal path information.

cherrypy.config.update({
‘global’: {‘server.environment’: ‘production’}})

Parse out the root class information for Cherrypy Root class.

package_name = root_class_name[:last_mark]
class_name = root_class_name[last_mark+1:]
exec(‘from %s import %s as Root’ % (package_name, class_name))
cherrypy.root = Root()

Main section -

Initialize the application, then start the server.

tg_init()

from fcgi import WSGIServer
cherrypy.server.start(initOnly=True, serverClass=None)

from cherrypy._cpwsgi import wsgiApp
WSGIServer(application=wsgiApp).run()

Also my .htaccess looks like:

RewriteEngine On
RewriteBase /x/
RewriteRule ^(dispatch.fcgi/.)$ - [QSA,L]
RewriteRule ^(.
)$ $1 [QSA,L]

However, when I access the location x/dispatch.fcgi from a web browser I get:


404 Not Found

The path ‘/x/dispatch.fcgi’ was not found.

Powered by CherryPy 2.2.1

I can run dispatch.cgi from my shell command line without any problems but I always get the above error when I try to access the same file via a web browser. I’ve googled around but have not yet found an answer to this problem. Has anyone here experienced similar difficulties when running fastcgi stuff on DreamHost?

My setup includes a custom version of python 2.4 which I installed locally on my account and I have activated fastcgi support and can see those processes when using ‘ps’ or ‘top’

Thanks!

Zubinix