1 # -*- coding: utf-8 -*-
4 # Etalage -- Open Data POIs portal
5 # By: Emmanuel Raviart <eraviart@easter-eggs.com>
7 # Copyright (C) 2011 Easter-eggs
8 # http://gitorious.org/infos-pratiques/etalage
10 # This file is part of Etalage.
12 # Etalage is free software; you can redistribute it and/or modify
13 # it under the terms of the GNU Affero General Public License as
14 # published by the Free Software Foundation, either version 3 of the
15 # License, or (at your option) any later version.
17 # Etalage is distributed in the hope that it will be useful,
18 # but WITHOUT ANY WARRANTY; without even the implied warranty of
19 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 # GNU Affero General Public License for more details.
22 # You should have received a copy of the GNU Affero General Public License
23 # along with this program. If not, see <http://www.gnu.org/licenses/>.
26 """Environment configuration"""
35 from suq import monpyjama
36 from etalage import ramdb
39 from . import conv, model, templates
42 app_dir = os.path.dirname(os.path.abspath(__file__))
45 def load_environment(global_conf, app_conf):
46 """Configure the application environment."""
47 conf = etalage.conf # Empty dictionary
51 'cache_dir': os.path.join(os.path.dirname(app_dir), 'cache'),
52 'categories_collection': 'categories',
53 'data_updates_collection': 'data_updates',
56 'global_conf': global_conf,
57 'i18n_dir': os.path.join(app_dir, 'i18n'),
58 'log_level': 'WARNING',
59 'organism_types_collection': 'organism_types',
60 'pois_collection': 'pois',
61 'package_name': 'etalage',
62 'static_files': True, # Whether this application serves its own static files
63 'static_files_dir': os.path.join(app_dir, 'static'),
64 'territories_collection': 'territories',
66 conf.update(global_conf)
68 conf['debug'] = conv.check(conv.pipe(conv.guess_bool, conv.default(False)))(conf['debug'])
69 conf['log_level'] = getattr(logging, conf['log_level'].upper())
70 conf['static_files'] = conv.check(conv.pipe(conv.guess_bool, conv.default(False)))(conf['static_files'])
73 logging.basicConfig(level = conf['log_level'], stream = sys.stdout)
75 errorware = conf.setdefault('errorware', {})
76 errorware['debug'] = conf['debug']
77 if not errorware['debug']:
78 errorware['error_email'] = conf['email_to']
79 errorware['error_log'] = conf.get('error_log', None)
80 errorware['error_message'] = conf.get('error_message', 'An internal server error occurred')
81 errorware['error_subject_prefix'] = conf.get('error_subject_prefix', 'Etalage Error: ')
82 errorware['from_address'] = conf['from_address']
83 errorware['smtp_server'] = conf.get('smtp_server', 'localhost')
85 # Connect to MongoDB database.
86 monpyjama.Wrapper.db = model.db = pymongo.Connection()[conf['database']]
87 # Initialize ramdb database from MongoDB.
90 # Create the Mako TemplateLookup, with the default auto-escaping.
91 templates.lookup = mako.lookup.TemplateLookup(
92 default_filters = ['h'],
93 directories = [os.path.join(app_dir, 'templates')],
94 # error_handler = handle_mako_error,
95 input_encoding = 'utf-8',
96 module_directory = os.path.join(conf['cache_dir'], 'templates'),
97 # strict_undefined = True,