本文整理汇总了Python中pylons.configuration.PylonsConfig.setdefault方法的典型用法代码示例。如果您正苦于以下问题:Python PylonsConfig.setdefault方法的具体用法?Python PylonsConfig.setdefault怎么用?Python PylonsConfig.setdefault使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类pylons.configuration.PylonsConfig
的用法示例。
在下文中一共展示了PylonsConfig.setdefault方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_environment
# 需要导入模块: from pylons.configuration import PylonsConfig [as 别名]
# 或者: from pylons.configuration.PylonsConfig import setdefault [as 别名]
def load_environment(global_conf, app_conf):
"""Configure the Pylons environment via the ``pylons.config`` object"""
config = PylonsConfig()
# 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='mediadrop', paths=paths)
env_dir = os.path.normpath(os.path.join(config['media_dir'], '..'))
config.setdefault('env_dir', env_dir)
# Initialize the plugin manager to load all active plugins
plugin_mgr = PluginManager(config)
mapper = create_mapper(config, plugin_mgr.controller_scan)
events.Environment.before_route_setup(mapper)
add_routes(mapper)
events.Environment.after_route_setup(mapper)
config['routes.map'] = mapper
config['pylons.app_globals'] = app_globals.Globals(config)
config['pylons.app_globals'].plugin_mgr = plugin_mgr
config['pylons.app_globals'].events = events
config['pylons.h'] = mediadrop.lib.helpers
# Setup cache object as early as possible
pylons.cache._push_object(config['pylons.app_globals'].cache)
i18n_env_dir = os.path.join(config['env_dir'], 'i18n')
config['locale_dirs'] = plugin_mgr.locale_dirs()
config['locale_dirs'].update({
'mediadrop': (os.path.join(root, 'i18n'), i18n_env_dir),
'FormEncode': (get_formencode_localedir(), i18n_env_dir),
})
def enable_i18n_for_template(template):
translations = Translator(translator)
translations.setup(template)
# Create the Genshi TemplateLoader
config['pylons.app_globals'].genshi_loader = TemplateLoader(
search_path=paths['templates'] + plugin_mgr.template_loaders(),
auto_reload=True,
max_cache_size=100,
callback=enable_i18n_for_template,
)
# Setup the SQLAlchemy database engine
engine = engine_from_config(config, 'sqlalchemy.')
init_model(engine, config.get('db_table_prefix', None))
events.Environment.init_model()
# CONFIGURATION OPTIONS HERE (note: all config options will override
# any Pylons config options)
# TODO: Move as many of these custom options into an .ini file, or at least
# to somewhere more friendly.
# TODO: Rework templates not to rely on this line:
# See docstring in pylons.configuration.PylonsConfig for details.
config['pylons.strict_tmpl_context'] = False
config['thumb_sizes'] = { # the dimensions (in pixels) to scale thumbnails
Media._thumb_dir: {
's': (128, 72),
'm': (160, 90),
'l': (560, 315),
},
Podcast._thumb_dir: {
's': (128, 128),
'm': (160, 160),
'l': (600, 600),
},
}
# END CUSTOM CONFIGURATION OPTIONS
events.Environment.loaded(config)
return config