pyalchemybiz/pyalchemybiz/config/environment.py
Jan Dittberner b53e8c48df model cleanup
* add __repr__() to all current module objects (fixes #10)
 * pep8 fixes in all Python files (addresses #9)
 * create subdirectory for customer templates (addresses #2)


git-svn-id: file:///var/www/wwwusers/usr01/svn/pyalchemybiz/trunk@8 389c73d4-bf09-4d3d-a15e-f94a37d0667a
2008-10-05 22:32:59 +00:00

55 lines
1.8 KiB
Python

"""Pylons environment configuration"""
import os
from pylons import config
from sqlalchemy import engine_from_config
from sqlalchemy.exceptions import NoSuchTableError
from migrate.versioning.api import db_version
from pyalchemybiz.model import init_model
import pyalchemybiz.lib.app_globals as app_globals
import pyalchemybiz.lib.helpers
from pyalchemybiz.config.routing import make_map
def load_environment(global_conf, app_conf):
"""Configure the Pylons environment via the ``pylons.config``
object
"""
# Pylons paths
root = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
paths = dict(root=root,
controllers=os.path.join(root, 'controllers'),
static_files=os.path.join(root, 'public'),
templates=[os.path.join(root, 'templates')])
# Initialize config with the basic options
config.init_app(global_conf, app_conf, package='pyalchemybiz',
template_engine='mako', paths=paths)
config['routes.map'] = make_map()
config['pylons.g'] = app_globals.Globals()
config['pylons.h'] = pyalchemybiz.lib.helpers
# Customize templating options via this variable
tmpl_options = config['buffet.template_options']
# CONFIGURATION OPTIONS HERE (note: all config options will override
# any Pylons config options)
engine = \
engine_from_config(config, 'sqlalchemy.default.')
try:
init_model(engine)
except Exception:
# special handling for calls in websetup.py
import inspect
frame = inspect.currentframe()
try:
functions = [current[3] for current in \
inspect.getouterframes(frame)]
if functions[1] != 'setup_config':
raise
finally:
del frame