通用模块化配置文件管理器
update-dotdee的Python项目详细描述
更新dotdee程序使管理配置文件变得容易 以Debian和dotdee样式的模块化内容。该程序将 配置文件的路径名,并基于 目录中与文件同名但以.d结尾的文件。 它目前在cpython 2.6、2.7、3.4、3.5、3.6和pypy(2.7)上测试。
Installation
update dotdee包在PyPI上可用,这意味着安装 应该简单到:
$ pip install update-dotdee
实际上,安装python包的方法有很多(例如,per user site-packages directory,virtual environments),或者只是安装 我不打算在这里讨论,所以 如果这让你感到害怕,那么在回到这些之前,先阅读一下你的选项 说明;-)。
Usage
有两种方法可以使用update dotdee包:作为命令行 程序update-dotdee,并作为python api。有关python api的详细信息 请参阅Read the Docs上提供的api文档。这个 命令行界面如下所述。
用法:更新dotdee文件名
根据中文件的内容生成(配置)文件 与文件名同名但以“.d”结尾的目录。
如果文件名存在,但相应的目录还不存在, 创建目录并将文件名移到目录中,以便 保存现有内容。
支持的选项:
Option | Description |
---|---|
^{tt3}$, ^{tt4}$ | Update FILENAME even if it contains local modifications, instead of aborting with an error message. |
^{tt5}$, ^{tt6}$ | Enable the use of “sudo” to update configuration files that are not readable and/or writable for the current user (or the user logged in to a remote system over SSH). |
^{tt7}$, ^{tt8}$ | Operate on a remote system instead of the local system. The ^{tt9}$ argument gives the SSH alias of the remote host. |
^{tt10}$, ^{tt11}$ | Increase logging verbosity (can be repeated). |
^{tt12}$, ^{tt13}$ | Decrease logging verbosity (can be repeated). |
^{tt14}$, ^{tt15}$ | Show this message and exit. |
Example
/etc/hosts文件是一个简单的配置文件示例,可以是 使用更新dotdee进行管理。/etc/hosts.d目录中的单个文件 包含每次运行时添加到配置文件的代码段。为了 示例:
peter@macbook> sudo update-dotdee /etc/hosts 2013-07-06 19:32:03 macbook INFO Reading file: /etc/hosts.d/1-local 2013-07-06 19:32:03 macbook INFO Reading file: /etc/hosts.d/2-work 2013-07-06 19:32:03 macbook INFO Reading file: /etc/hosts.d/3-ipv6 2013-07-06 20:59:24 macbook INFO Checking for local changes to /etc/hosts 2013-07-06 19:32:03 macbook INFO Writing file: /etc/hosts
How it works
关于update dotdee工作原理的一些注释:
- 如果给定文件存在,但相应的目录还不存在, 创建目录并将文件移动到目录中(和 重命名为{tT1717}$,以使其现有内容得以保留。
- 如果生成的文件自上次运行以来已被修改,请更新dotdee 将拒绝覆盖其内容(除非使用-f或 --force选项)。
- .d目录中的文件在自然排序中连接起来 文件名的顺序(由naturalsort包实现)。
- 执行.d目录中的可执行文件及其标准 输出被合并到生成的内容中(从版本4.0开始)。
Use cases
下面是更新dotdee的一些用例示例:
- ssh客户端配置
- 2013年创建了更新dotdee程序,以提供模块化ssh客户端 配置。它用于从 ~/.ssh/config.d目录中文件的内容。这个功能 因为我开发了一个ssh客户端配置生成器 一个服务器元数据数据库,我正在寻找一种方法来更新用户的 {TT22}$不破坏现有的(精心手工制作) 目录。
- 系统范围配置文件
- Linux系统配置文件,如/etc/crypttab、/etc/fstab和 /etc/hosts缺乏模块性并使用命令行工具操作它们 比如awk和sed可能很脆弱和/或变得很笨拙:-)。但是如果你 可以获取配置源(例如ansible playbooks、debian 软件包和手动配置)同意使用更新dotdee,然后 您有一个优雅、可靠和可预测的选择。
Read only alternative
有时美国更新dotdee的se或类似的机制是 让多个配置源协作,但是 重量级解决方案。对于我发布的python包,我希望 更轻量级的替代方案,只需搜索并加载*.ini 配置文件。这就是在5.0版中添加ConfigLoader的原因。
Contact
最新版本的update dotdee可在PyPI和GitHub上获得。对于Bug 报告请在GitHub上创建问题。如果你有问题,建议, 等等,请随时给我发一封电子邮件peter@peterodding.com。