I am doing some sort of science with a combination of Python, bash scripts and configuration files with weird syntaxes from old C programs. To run different tests, I have to tune (open text file, edit and save) a number of these files, but it is getting harder and harder to remember which files to edit. Also, the tasks are very repetitive and I end having a bunch of comment lines, switching on and off the settings for a specific run.
我正在使用Python,bash脚本和配置文件以及来自旧C程序的奇怪语法来进行某种科学研究。要运行不同的测试,我必须调整(打开文本文件,编辑和保存)许多这些文件,但要记住要编辑的文件变得越来越难。此外,任务是非常重复的,我结束了一堆注释行,打开和关闭特定运行的设置。
I dream of a tool that can keep a list of files (regardless of the file format) and allow me to centrally choose from a predefined list of "profiles", taking care of editing the script/config files. For example lets say I have a config and script file:
我梦想有一个工具可以保存文件列表(无论文件格式如何),并允许我集中选择预定义的“配置文件”列表,负责编辑脚本/配置文件。例如,假设我有一个配置和脚本文件:
config.cfg
var1 = 1.0
#var1 = 1.5
script.sct
function(200.0)
#function(300.0)
I would like to instead have auxiliary text files:
我想改为有辅助文本文件:
config.cfg.tem
var1 = $$var1$$
script.sct.tem
function($$par1$$)
and in a central script or even better, a GUI, just switch from profile1 (e.g. var1=1.0,par1=200.0) to profile2 (e.g. var1=1.5,par1=300.0), and the tool to automatically update the text files.
在*脚本或甚至更好的GUI中,只需从profile1(例如var1 = 1.0,par1 = 200.0)切换到profile2(例如var1 = 1.5,par1 = 300.0),以及自动更新文本文件的工具。
Any idea if such a tools exists?
知道这样的工具是否存在?
1 个解决方案
#1
0
There are many, many processors which do this. Looking for a "templating system" will yield tons of elaborate tools.
有许多处理器可以做到这一点。寻找“模板系统”将产生大量精心设计的工具。
OTOH, a very straight forward and simple way would be to use the C preprocessor. Define a settings include file were you #define
your settings and then automatically include it when you process your templates.
OTOH,一种非常直接和简单的方法是使用C预处理器。定义设置包含文件是#define您的设置,然后在处理模板时自动包含它。
$ cpp -include definitions_file input_template output_file
This is simple and has its shortcomings but works often good enough.
这很简单并且有其缺点,但通常效果很好。
#1
0
There are many, many processors which do this. Looking for a "templating system" will yield tons of elaborate tools.
有许多处理器可以做到这一点。寻找“模板系统”将产生大量精心设计的工具。
OTOH, a very straight forward and simple way would be to use the C preprocessor. Define a settings include file were you #define
your settings and then automatically include it when you process your templates.
OTOH,一种非常直接和简单的方法是使用C预处理器。定义设置包含文件是#define您的设置,然后在处理模板时自动包含它。
$ cpp -include definitions_file input_template output_file
This is simple and has its shortcomings but works often good enough.
这很简单并且有其缺点,但通常效果很好。