Text replacement for multiple script/config files
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 harde开发者_如何学Pythonr 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.
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.
Any idea if such a tools exists?
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.
$ cpp -include definitions_file input_template output_file
This is simple and has its shortcomings but works often good enough.
精彩评论