1 | from paste import httpexceptions |
---|
2 | from paste.cascade import Cascade |
---|
3 | from paste.urlparser import StaticURLParser |
---|
4 | from paste.registry import RegistryManager |
---|
5 | from paste.deploy.config import ConfigMiddleware, CONFIG |
---|
6 | from paste.deploy.converters import asbool |
---|
7 | |
---|
8 | from pylons.error import error_template |
---|
9 | from pylons.middleware import ErrorHandler, ErrorDocuments, StaticJavascripts, error_mapper |
---|
10 | import pylons.wsgiapp |
---|
11 | |
---|
12 | from ows_server.config.environment import load_environment |
---|
13 | import ows_server.lib.helpers |
---|
14 | import ows_server.lib.app_globals as app_globals |
---|
15 | |
---|
16 | from ows_server.config.ndgMiddleware import ndgMiddleware |
---|
17 | |
---|
18 | # Logging doesn't need configuring if you have paste.translogger in your config file. |
---|
19 | #import logging |
---|
20 | |
---|
21 | def make_app(global_conf, full_stack=True, **app_conf): |
---|
22 | """Create a WSGI application and return it |
---|
23 | |
---|
24 | global_conf is a dict representing the Paste configuration options, the |
---|
25 | paste.deploy.converters should be used when parsing Paste config options |
---|
26 | to ensure they're treated properly. |
---|
27 | |
---|
28 | """ |
---|
29 | # Setup the Paste CONFIG object, adding app_conf/global_conf for legacy code |
---|
30 | conf = global_conf.copy() |
---|
31 | conf.update(app_conf) |
---|
32 | conf.update(dict(app_conf=app_conf, global_conf=global_conf)) |
---|
33 | CONFIG.push_process_config(conf) |
---|
34 | |
---|
35 | # Load our Pylons configuration defaults |
---|
36 | config = load_environment(global_conf, app_conf) |
---|
37 | config.init_app(global_conf, app_conf, package='ows_server', |
---|
38 | template_engine='kid') |
---|
39 | |
---|
40 | # Load our default Pylons WSGI app and make g available |
---|
41 | app = pylons.wsgiapp.PylonsApp(config, helpers=ows_server.lib.helpers, |
---|
42 | g=app_globals.Globals) |
---|
43 | g = app.globals |
---|
44 | app = ConfigMiddleware(app, conf) |
---|
45 | |
---|
46 | # YOUR MIDDLEWARE |
---|
47 | # Put your own middleware here, so that any problems are caught by the error |
---|
48 | # handling middleware underneath |
---|
49 | |
---|
50 | app = ndgMiddleware(app,g) |
---|
51 | g=app.globals |
---|
52 | |
---|
53 | # Configure logging |
---|
54 | #logging.basicConfig(format='%(thread)s %(name)s %(levelname)s %(message)s') |
---|
55 | |
---|
56 | # If errror handling and exception catching will be handled by middleware |
---|
57 | # for multiple apps, you will want to set full_stack = False in your config |
---|
58 | # file so that it can catch the problems. |
---|
59 | if asbool(full_stack): |
---|
60 | # Change HTTPExceptions to HTTP responses |
---|
61 | app = httpexceptions.make_middleware(app, global_conf) |
---|
62 | |
---|
63 | # Error Handling |
---|
64 | app = ErrorHandler(app, global_conf, error_template=error_template, **config.errorware) |
---|
65 | |
---|
66 | # Display error documents for 401, 403, 404 status codes (if debug is disabled also |
---|
67 | # intercepts 500) |
---|
68 | #app = ErrorDocuments(app, global_conf, mapper=error_mapper, **app_conf) |
---|
69 | |
---|
70 | # Establish the Registry for this application |
---|
71 | app = RegistryManager(app) |
---|
72 | |
---|
73 | # Allow static files from outside the egg too ... g.htdocs defined in ndgDiscovery.config |
---|
74 | if g.htdocs: |
---|
75 | static_paths = [g.htdocs,config.paths['static_files']] |
---|
76 | else: static_paths= [config.paths['static_files']] |
---|
77 | static_app = [StaticURLParser(path) for path in static_paths] |
---|
78 | javascripts_app = StaticJavascripts() |
---|
79 | app = Cascade(static_app +[javascripts_app, app]) |
---|
80 | return app |
---|