跳转到主要内容

将Buildout配置导出到JSON文件的配方。

项目描述

https://travis-ci.org/sirex/exportrecipe.svg https://coveralls.io/repos/sirex/exportrecipe/badge.svg https://pypip.in/d/exportrecipe/badge.svg https://pypip.in/v/exportrecipe/badge.svg https://pypip.in/license/exportrecipe/badge.svg

这是一个Buildout配方,可以将Buildout配置导出到JSON文件。之后,可以导出的文件可用于获取导出设置并在项目中使用。

Buildout提供了丰富的配置管理功能,但没有工具可以将此配置用于Buildout之外的其他地方。这个配方将所有设置导出到JSON文件,允许在Buildout之外使用配置参数。

用法

[buildout]
parts = settings

[settings]
recipe = exportrecipe
website-url = http://example.com/

这将生成您的buildout目录中的settings.json文件,内容如下

{
  "website-url": "http://localhost:8000/"
}

exportrecipe将导出配方部分的除recipe参数之外的所有参数。

现在您可以使用这个文件,例如在您的settings.py文件中

import json

with open('settings.json') as f:
    settings = json.load(f)

WEBSITE_URL = settings['website-url']

您还可以使用一个辅助工具

import exportrecipe

config = exportrecipe.load('settings.json')

WEBSITE_URL = config.website_url

可以通过使用destination选项来更改导出文件的存储位置

[buildout]
parts = settings

[settings]
recipe = exportrecipe
destination = somewhereelse.json
website-url = http://example.com/

这将生成带有以下内容的somewhereelse.json文件

{
  "destination": "somewhereelse.json",
  "website-url": "http://localhost:8000/"
}

变更历史

0.2 (2015-05-17)

  • 首次公开发布。

项目详情


发布历史 发布通知 | RSS源

下载文件

下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于安装软件包的信息。

源分发

exportrecipe-0.2.tar.gz (2.7 kB 查看哈希值)

上传时间: 源代码

构建分布版

exportrecipe-0.2-py2.py3-none-any.whl (4.6 kB 查看哈希值)

上传时间: Python 2 Python 3

由以下提供支持