在首次安装时创建并填充应用程序的配置。

figg的Python项目详细描述


在首次安装时创建并填充应用程序的配置。

你是否厌倦了编写超级棒的软件包或应用程序 但是,除非你的最终用户仔细阅读你的自述以获得指导,否则不要工作。 如何构造配置文件以及如何在何处实例化它们?

figgy允许您发送代码并安装最终用户开发人员 通过运行你的应用程序或包来配置它。你可以叫它 从setup.py或将其绑定到代码中您喜欢的任何内容,以便 新配置的结果将立即提供给 无论应用程序或包将在什么上下文中使用。


警告

这个软件正在开发中。也就是说,这个包裹应该 工作。请报告错误。

关键注意事项: -将配置数据以 案例。 -只支持json。 -仅适用于Python3。 -您希望此模块从tty提示。 -你是在一个“尼克斯系统”。

它们旨在指导未来版本的特性开发,但是 在这种情况下,它应该是有用的。

安装

pip install figgy

用法

第一次导入figgy

import figgy

然后定义配置模板

template = {
    'username': 'default',
    'password': 'anotherdefault'
}

您只需调用make()

figgy.make(template)

系统将提示最终用户:

Enter value for "username"
(return for default "default")': ▋userinput
Enter value for "username"
(return for default "default")':
Set "username" to "userinput" in ./config.json
Enter value for "password"
(return for default "anotherdefault")': ▋anotheruserinput
Enter value for "password"
(return for default "anotherdefault")':
Set "password" to "anotheruserinput" in ./config.json

并生成一个config.json文件:

{"username": "userinput", "password": "anotheruserinput"}

如果希望在创建应用程序后在其中使用数据 使用

config = figgy.make(template)

以便您可以像这样访问数据

username = config['username']
password = config['password']

默认情况下,figgy假设以下几点:

  • 您希望文件名为config.json
  • 您希望在执行python代码的路径生成文件 它从
  • 您希望函数返回配置数据
  • 用户界面为tty

但你可以改变大部分:

源代码:

template = {
    'PORT': '3000',
    'DEBUG': 'True'
}
figgy.make(data=template, filename='appconfig')

提示:

Enter value for "PORT"
(return for default "3000")': ▋8080
Set "PORT" to "8080" in ./appconfig.json
Enter value for "DEBUG"
(return for default "True")': ▋False

返回:

Set "DEBUG" to "False" in ./appconfig.json
{'./appconfig.json': {'PORT': '3000', 'DEBUG': 'True'}}

源代码:

figgy.make(data=template, get=False)

生成提示:

Enter value for "username"
(return for default "default")': ▋userinput
Set "username" to "userinput" in ./config.json
Enter value for "password"
(return for default "anotherdefault")': ▋anotheruserinput
Set "password" to "anotheruserinput" in ./config.json

返回:

None

贡献

  1. 分叉源存储库https://github.com/dyspop/figgy
  2. 创建新分支
  3. 编写功能部件代码
  4. 确保添加了一些测试
  5. 提交一个请求,其中包含有关您的功能和测试的有用注释

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java通过两个整数数组对正整数和负整数进行排序   java无参数和默认构造函数混淆   java加载文件MD5的最快方法是什么?   java如何在变量声明中使用带“e”的float   java将项目导入到STS iMac   java在使用图像时旋转图像   java Break语句不起作用   java提供了错误类型Spring的id   java如何为多个变量设置相同的函数属性?   JavaMaven:如何添加编译阶段后生成的资源   java HashMap已损坏/性能问题   java Hibernate SQL中间表b/w父表和子表(不同类型)   java PDFbox找不到字体:/Helv   Java:向自实现的双链接列表添加排序函数   为使用Java BouncyCastle生成的X509Certificate提供密钥使用的安全性   java Hibernate在读写方面的性能   C#相当于Java的DataOutputStream?