有没有办法使用 Paste Deploy 共享通用配置? [英] Is there a way to share common configuration using Paste Deploy?

查看:58
本文介绍了有没有办法使用 Paste Deploy 共享通用配置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

从概念上讲,这是一个非常简单的想法.就细节而言,我正在使用一个非常通用的 Kotti 安装,我正在自定义一些页面/模板.

This is a pretty simple idea conceptually. In terms of specifics, I'm working with a pretty generic Kotti installation, where I'm customizing some pages / templates.

我的大部分配置在生产服务器和开发服务器之间共享.目前,这些设置包含在两个单独的 ini 文件中.干掉这个配置会很好,在一个地方有通用设置.

Much of my configuration is shared between a production and development server. Currently, these settings are included in two separate ini files. It would be nice to DRY this configuration, with common settings in one place.

我对在 python 或 ini 文件/部分(或者可能是第三个尚未考虑的地方)中发生的这种情况持开放态度.我认为这相当于使用 [DEFAULT] 部分,或通过 global_conf 将字典传递给 loadapp,但这似乎以一种松散的方式处理.例如,Kotti 认为我已经正确设置了 sqlalchemy.url,但是 sqlalchemy iteself 在 url = opts.pop('url') 上失败.此外,由于 Kotti 定义了一些默认设置,Paste 最终不会在 global_conf 中搜索它们(例如,kotti_configurators).

I'm quite open to this happening in python or an an ini file / section (or perhaps a third, yet-to-be-considered place). I think it's equivalent to use a [DEFAULT] section, or pass dictionaries to loadapp via global_conf, but that seems to be processed in a squirrelly way. For example, Kotti thinks I've properly set sqlalchemy.url, but sqlalchemy iteself fails on url = opts.pop('url'). Moreover, since Kotti defines some default settings, Paste doesn't end up searching for them in the global_conf (e.g., kotti_configurators).

喜欢为%(var)s替换传入一个大字典的想法,因为它需要有效地重命名所有共享变量.

I don't like the idea of passing in a large dict for %(var)s substitution, as it requires effectively renaming all of the shared variables.

在我对 Paste Deploy 的初始实验中,它要求每个 ini 文件中有一个main"部分.所以,我认为我不能只使用 use = config:shared.ini 行.但这在概念上与我想做的很接近.

In my initial experiments with Paste Deploy, it demands a "main" section in each ini file. So, I don't think I can just use a use = config:shared.ini line. But that's conceptually close to what I'd like to do.

有没有办法明确(并正确)包含来自 DEFAULT 或 global_conf 的设置?或者也许用 python 在 loadapp 的结果上以编程方式执行此操作?

Is there a way to explicitly (and properly) include settings from DEFAULT or global_conf? Or perhaps do this programmatically with python on the results of loadapp?

推荐答案

例如,Kotti 认为我已经正确设置了 sqlalchemy.url,但是 sqlalchemy iteself 在 url = opts.pop('url') 上失败.

For example, Kotti thinks I've properly set sqlalchemy.url, but sqlalchemy iteself fails on url = opts.pop('url').

如果您认为某些事情很奇怪并且您正在询问 SO,最好显示堆栈跟踪和您尝试做的事情的示例.

If you think something is odd and you're asking on SO it'd be wise to show a stacktrace and an example of what you tried to do.

Kotti 的设置与任何金字塔应用程序相同.您的入口点(通常为 def main(global_conf, **settings))通过 global_confsettings 字典.然后,您负责修复它并将其拖入配置器.

Kotti gets its settings the same as any pyramid app. Your entry point (def main(global_conf, **settings) usually) is passed the global_conf and settings dictionary. You're then responsible for fixing that up and shuffling it off into the configurator.

出于各种原因,PasteDeploy 将 global_conf 与设置分开,因此您有责任根据需要合并它们.

For various reasons PasteDeploy keeps the global_conf separate from the settings, thus you're responsible for merging them if you wish.

[DEFAULT]
foo = bar

[app:main]
use = egg:myapp#main
baz = xyz

def main(global_conf, **app_settings):
    settings = global_conf
    settings.update(app_settings)
    config = Configurator(settings=settings)
    config.include('kotti')
    return config.make_wsgi_app()

这篇关于有没有办法使用 Paste Deploy 共享通用配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆