diff options
Diffstat (limited to 'paste/servers')
| -rw-r--r-- | paste/servers/cgi_server.py | 27 | ||||
| -rw-r--r-- | paste/servers/server_script_template.py.txt | 13 |
2 files changed, 30 insertions, 10 deletions
diff --git a/paste/servers/cgi_server.py b/paste/servers/cgi_server.py index 11e2d13..bd402bf 100644 --- a/paste/servers/cgi_server.py +++ b/paste/servers/cgi_server.py @@ -1,5 +1,6 @@ import os import sys +import commands from paste import server def serve(conf, app): @@ -16,6 +17,7 @@ def serve(conf, app): if other_conf.has_key('verbose'): del other_conf['verbose'] replacements['other_conf'] = other_conf + replacements['extra_sys_path'] = find_extra_sys_path() template_fn = os.path.join(os.path.dirname(__file__), 'server_script_template.py.txt') @@ -26,8 +28,8 @@ def serve(conf, app): print "#!%s" % sys.executable print template print "if __name__ == '__main__':" - print " from paste.cgiserver import run_with_cgi" - print " run_with_cgi(app)" + print " from paste.servers.cgi_wsgi import run_with_cgi" + print " run_with_cgi(app, redirect_stdout=True)" description = """\ A 'server' that creates a CGI script that you can use to invoke your @@ -40,3 +42,24 @@ Typically you would use this like: %prog --server=cgi > .../cgi-bin/myapp.cgi chmod +x .../cgi-bin/myapp.cgi """ + +def find_extra_sys_path(): + """ + Tries to find all the items on sys.path that wouldn't be there + normally. + """ + args = [sys.executable, "-c", "import sys; print sys.path"] + old_keys = {} + for key, value in os.environ.items(): + if key.startswith('PYTHON'): + old_keys[key] = value + del os.environ[key] + result = commands.getoutput('%s -c "import sys; print sys.path"' + % sys.executable) + os.environ.update(old_keys) + bare_sys_path = eval(result) + extra = [path for path in sys.path + if path not in bare_sys_path] + return extra + + diff --git a/paste/servers/server_script_template.py.txt b/paste/servers/server_script_template.py.txt index aa5c1cb..e1e7e86 100644 --- a/paste/servers/server_script_template.py.txt +++ b/paste/servers/server_script_template.py.txt @@ -1,19 +1,16 @@ import os +import sys +sys.path.extend(@@extra_sys_path@@) from paste import server from paste.pyconfig import Config -from paste.configmiddleware import config_middleware -from paste.webkit import wsgiwebkit -conf = Config() -conf.load_dict(server.default_ops, default=True) +conf = Config(with_default=True) conf.load_dict(@@other_conf@@) server.load_conf(conf, @@default_config_fn@@) if not conf.get('no_server_conf') and os.path.exists('server.conf'): server.load_conf(conf, 'server.conf') if conf.get('config_file'): server.load_conf(conf, conf['config_file']) -if conf.get('sys_path'): - server.update_sys_path(conf['sys_path'], conf['verbose']) +conf.update_sys_path() -app = wsgiwebkit.webkit(conf['publish_dir'], use_lint=conf.get('lint')) -app = config_middleware(app, conf) +app = server.make_app(conf) |
