annotate pylons_app/config/environment.py @ 0:564e40829f80

initial commit.
author Marcin Kuzminski
date Thu, 18 Feb 2010 13:01:57 +0100
parents
children 5f30a6d558dc
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
1 """Pylons environment configuration"""
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
2 import logging
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
3 import os
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
4 from pylons import config
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
5 from mako.lookup import TemplateLookup
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
6 from pylons.error import handle_mako_error
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
7 import pylons_app.lib.app_globals as app_globals
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
8 import pylons_app.lib.helpers
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
9 from pylons_app.config.routing import make_map
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
10
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
11 log = logging.getLogger(__name__)
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
12
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
13 def load_environment(global_conf, app_conf):
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
14 """Configure the Pylons environment via the ``pylons.config``
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
15 object
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
16 """
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
17 # Pylons paths
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
18 root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
19 paths = dict(root = root,
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
20 controllers = os.path.join(root, 'controllers'),
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
21 static_files = os.path.join(root, 'public'),
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
22 templates = [os.path.join(root, 'templates')])
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
23
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
24 # Initialize config with the basic options
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
25 config.init_app(global_conf, app_conf, package = 'pylons_app',
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
26 template_engine = 'mako', paths = paths)
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
27
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
28 config['routes.map'] = make_map()
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
29 config['pylons.g'] = app_globals.Globals()
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
30 config['pylons.h'] = pylons_app.lib.helpers
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
31
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
32 # Create the Mako TemplateLookup, with the default auto-escaping
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
33 config['pylons.g'].mako_lookup = TemplateLookup(
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
34 directories = paths['templates'],
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
35 error_handler = handle_mako_error,
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
36 module_directory = os.path.join(app_conf['cache_dir'], 'templates'),
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
37 input_encoding = 'utf-8', default_filters = ['escape'],
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
38 imports = ['from webhelpers.html import escape'])
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
39
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
40 # Customize templating options via this variable
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
41 tmpl_options = config['buffet.template_options']
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
42
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
43 # CONFIGURATION OPTIONS HERE (note: all config options will override
564e40829f80 initial commit.
Marcin Kuzminski
parents:
diff changeset
44 # any Pylons config options)