基于Jinja2+Yaml的配置模板器。
zenbu的Python项目详细描述
与设置无关的级联主题引擎。使用jinja2作为模板和yaml 对于变量定义。
上面的gif是由wzb-utils带给您的。
安装
pip install zenbu
或者把zenbu.py移到$PATH中的某个位置。 如果执行后者,则必须在 手动执行以下部分。
依赖关系
- Python(2或3)
下面是应该通过pip安装的python库。 或者,如果你做了pip install zenbu,这些应该是 自动安装。
- argcomplete
- 彩色日志
- Jinja2
- 皮亚姆
- 术语颜色
- 看门狗
制表符完成
sudo activate-global-python-argcomplete
如果通过PIP安装,则在自动完成之前,可能需要运行以下命令:
grep 'PYTHON_ARGCOMPLETE_OK' "$(which zenbu)" &>/dev/null || sudo sed -i "1a # PYTHON_ARGCOMPLETE_OK" "$(which zenbu)"
用法
检查example文件夹中的一些示例用法!
有关更详细的说明,请查看wiki homepage。
有关常见问题,请检查common gotchas wiki page。
对于一些整洁的工具(包括自动重新加载桌面),请检查 tools wiki page。
usage: zenbu [-h] [-l] [-t TEMPLATE_DIR] [-d DEST_DIR] [-s VAR_SET_DIR] [-f FILTERS_FILE] [-i IGNORES_FILE] [-e] [-w] [--watch-command WATCH_COMMAND] [--watch-dirs WATCH_DIRS] [--diff] [--dry] [variable_files [variable_files ...]] A Jinja2 + YAML based config templater. Searches for an optional yaml file with a variable mapping in ~/.config/zenbu/defaults.yaml, an optional python file with filters in (by default) ~/.config/zenbu/filters.py, an optional yaml file with an ignore scalar of regexes in (by default) ~/.config/zenbu/ignores.yaml, and uses the Jinja2 templates in (by default) ~/.config/zenbu/templates/ to render into your home directory (by default). Additional variable files can be applied by supplying them as arguments, in order of application. They can either be paths or, if located in (by default) ~/.config/zenbu/variable_sets/, extension-less filenames. Environment variable support is available; simply run with the `-e` flag and put the name of the variable in Jinja2 brackets. The default Jinja2 globals and filters are available. Order of precedence is: last YAML variable defined > first YAML variable defined > environment variables. Variables are shallowly resolved once. Thus, for example you may have the following in your defaults.yaml for convenience: n_primary: "{{ colors[colors.primary].normal }}" Autocomplete support available, but only for the default variable set directory. A file watcher is available via the -w flag. Whenever a variable file in use, the filters file, the ignores file, or a template file changes, the templates are rendered if there are any differences. This can be overridden with a custom list of directories via the --watch-dirs flag. Diffs between the current destination files and template renderings are available via the --diff flag. For help on designing templates, refer to http://jinja.pocoo.org/docs/dev/templates/ For help on creating filters, refer to http://jinja.pocoo.org/docs/dev/api/#custom-filters positional arguments: variable_files additional variable files optional arguments: -h, --help show this help message and exit -l list variable sets. -t TEMPLATE_DIR template directory. Default: /Users/echan/.config/zenbu/templates -d DEST_DIR destination directory. Default: /Users/echan -s VAR_SET_DIR variable set directory. Default: /Users/echan/.config/zenbu/variable_sets -f FILTERS_FILE filters file. Default: /Users/echan/.config/zenbu/filters.py -i IGNORES_FILE ignores file. Default: /Users/echan/.config/zenbu/ignores.yaml -e whether or not to use environment variables. Default: don't use environment variables -w start file watcher. --watch-command WATCH_COMMAND what to execute when a change occurs. Default: Nothing --watch-dirs WATCH_DIRS override what directories to watch, colon-separated. Default: Nothing --diff show diff between template renderings and current destination files --dry do a dry run
惠茨克家怎么了?
这个项目看起来与whizkers非常相似;实际上,这是一个fork 与Jinja2交换胡子的惠茨克人。我在保留 因为兼容性的原因到处闲逛。那么为什么 切换?
- 全面的文档:请参见 Jinja2 Template Designer Documentation。
- 更好的逻辑:从if/else到宏的一切。我最初称赞 为它的逻辑少了哲学的胡子,但后来我意识到 除了变量集之外,没有其他地方可以放置逻辑,这是一个噩梦。
- 表达式:现在可以执行{{ ':bold' if use_bold else '' }}。你可以 即使是{{ colors[colors.primary]['normal'] }},也会导致 不赞成使用{` ... `}eval语法。
- 过滤器:现在可以执行{{ colors.black.bold | to_rgb }}。好多了 而不是胡子的语法。
- 更好的空白控制:这意味着增加可读性。
为了帮助您轻松过渡到Zenbu,在 migration wiki page。
感谢
- https://gist.github.com/coleifer/33484bff21c34644dae1
- http://jinja.pocoo.org/
- http://pyyaml.org/
- fullsalvo对于想法、观点、自述文件gif、文档贡献, 先令,总的来说是个好人