私はテンプレート設定ファイルを実装しようとしています。 私はPythonを好むだろうが、私はperlでも答えをとるだろう。 私は私の例としてperlを使用しました。pythonまたはperlのテンプレート構成ですか?
私は少しを検索し、 見つけた - python single configuration file - ConfigObj - python configuration file generator - ePerl を私はそれらからの私の問題を解決することができませんでした。
私は(さえないセクションで)ほとんどINI形式の設定ファイルを生成しようとしている:
# Comments
VAR1 = value1
EDITOR = vi
をし、私は、テキスト内のスクリプト言語を埋め込むんだテンプレートから生成することを必要とします:
# Config:
MYPWD = <: `pwd` :>
間でテキスト '<:' と '>' スクリプト言語(PythonやPerlの)であろう。テンプレートと同様に、その標準出力がキャプチャされ、結果のテキストに挿入されます。この例で使用されているテンプレートは基本的にはeperlですが、使用できる場合はPythonを使用したいと考えています。
、最終的には、定義された変数は再利用可能でなければなりません:
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# platform.cfg
# This one variable
VAR =value
# this is a templated variable. The langage is perl, but could be python.
HELLO= <: print 'World' :>
# This is a multi-line code which should resolve to a single line value.
LONGER = <:
if (1) {
print "abc ";
}
$pwd = `/bin/pwd`;
chomp($pwd);
print $pwd;
:>
# Another one to test the carriage returns.
MULTIPLE = /<: print "proj" :>/<: print "tahiti":>/<:
print "pd/1/";
$system = `grep -w VAR platform.cfg | egrep -v 'print|platform.cfg' | cut -d = -f 2-`;
chomp($system);
print $system;
:>
# variables dependent from the previous variable definition
VAR1 = <: print $VAR :>1
# variables dependent from the previous variable definition
VAR2 = <: print $VAR1 :>2
# variables dependent from the previous variable definition
VAR3 = <: print $VAR2 :>3
# variables dependent from the previous variable definition
VAR4 = <: print $VAR3 :>4
# BTW, multi-line comments are significant
# and should be preserved as the documentation for the
# variable just below:
VAR5 = <: print $VAR4 :>5
VAR6 = <: print $VAR5 :>6
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
そして、私は外にこの結果を得るために探しています:
# Config:
CODE_HOME = /some/path
CODE_BIN = <:=$CODE_HOME:>/bin
ここで私が読んテストソースファイルですスクリプト。 設定ファイルに定義されている変数をインタプリタの一部にする方法を理解できませんでしたか?
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
# platform.cfg
# This one variable
VAR =value
# this is a templated variable. The langage is perl, but could be python.
HELLO= World
# This is a multi-line code which should resolve to a single line value.
LONGER = abc /src/byop/CODE
# Another one to test the carriage returns.
MULTIPLE = /proj/tahiti/pd/1/value
# variables dependent from the previous variable definition
VAR1 = value1
# variables dependent from the previous variable definition
VAR2 = value12
# variables dependent from the previous variable definition
VAR3 = value123
# variables dependent from the previous variable definition
VAR4 = value1234
# BTW, multi-line comments are significant
# and should be preserved as the documentation for the
# variable just below:
VAR5 = value12345
VAR6 = value123456
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
お寄せいただきありがとうございます。
これは非常に具体的で独特なテンプレートの方言のようです。これがどのような形式になるのか分かりますか? – SingleNegationElimination
@TokenMacGuy:コメントをいただきありがとうございます。私は設定とテンプレートをマージすることをよりよく説明するために私の質問を編集しました。あなたの質問に答えようとしています:着信ファイルのフォーマットは、ブラケット付きの設定ファイルです: '<:' and ':>'。これらの区切り文字の間にあるものは、スクリプティング言語(Python、またはperl、pick one)にあり、テンプレートで以前に定義された変数にスクリプト言語がアクセスできるようにするという制約が追加されています。 (それはもっと明確ですか?) – GED
これは現場で構成しているテンプレート言語ですか? – SingleNegationElimination