Re: Using a variable inside another variable name
Oliver Nicholas <[email protected]> Mon, 19 Sep 2011 10:07:17 -0700
| Newsgroups | gmane.comp.python.cheetah |
|---|---|
| Message-ID | <CAMo5GenH+1HPpKHzeMU97fYXbom+U9O6uHZ3iQnBOo8dXLwZrg@mail.gmail.com> |
--===============7590685220975790815==
Content-Type: multipart/alternative; boundary=90e6ba6135b43a33eb04ad4e61f7
--90e6ba6135b43a33eb04ad4e61f7
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
$getVar("sso_host_%s" % $myLanguage)
On Mon, Sep 19, 2011 at 10:04 AM, R=E9mi ALVADO <[email protected]> wro=
te:
> Hi,
>
> I'm new with Cheetah and I'm trying to use it to build a deployment tool
> and replace my old configuration files with brand new cheetah templates.
> I'm working for a company which edit websites all over the world so lots =
of
> our configuration keys are overriden by country.
> With Cheetah, I'm storing my configuration into a YAML data storage files
> and I use a Python script combined with some Bash scripts to find, fill a=
nd
> replace all *.cheetah files.
> Please find below an example of my test configuration file, my YAML data
> storage and the expected result file
>
> --------------- CONF FILE -------------------
> prod:
> sso:
> hosts:
> #for myLanguage in $cultures
> sso_$myLanguage:
> host: $eval("sso_host_" + myLanguage)
> port: $eval("sso_port_" + myLanguage)
> #end for
>
> --------------- YAML DATA STORAGE -------------------
> # Global
> cultures:
> - de
> - en
> - fr
>
> # DE
> sso_host_de: sso-de.example.com
> sso_port_de: 8081
> [...]
>
> # EN
> sso_host_en: sso-en.example.com
> sso_port_en: 8082
> [...]
>
> # FR
> sso_host_fr: sso-fr.example.com
> sso_port_fr: 8083
> [...]
>
> --------------- YAML DATA STORAGE -------------------
> prod:
> sso:
> hosts:
> sso_de:
> host: sso-de.example.com
> port: 8081
> sso_en:
> host: sso-en.example.com
> port: 8082
> sso_fr:
> host: sso-fr.example.com
> port: 8083
>
> -------------------------------------
>
> I know using "eval" is not a good idea (eval =3D evil :) ) but I've tried
> several other solutions ("$sso_public_host_$myLanguage",
> "$(sso_public_host_$myLanguage)", ...) and none of them work.
> I've also tried to change my data storage file to have something like :
> de:
> sso_host_public: ...
> but I've got the exact same issue with
> $self[$myLanguage]['sso_host_public'] and I don't like this representatio=
n
> since it's less natural than a list of <key,value> tuples.
>
> Do you have any idea how I can use a variable inside another variable nam=
e
> ? It seems to be a bit odd but it would be very convenient in a productio=
n
> environnement to have a very simple data storage file with only <key,valu=
e>
> tuples : easy to read and easy to share with a simple copy/paste into
> release note on a mail, a twiki, ...
>
> Thanks and congratulations this templating engine : despite this little
> issue, it's really great and I might consider using it on another project=
s,
> more web oriented :)
>
> R=E9mi
>
>
> -------------------------------------------------------------------------=
-----
> BlackBerry® DevCon Americas, Oct. 18-20, San Francisco, CA
> Learn about the latest advances in developing for the
> BlackBerry® mobile platform with sessions, labs & more.
> See new tools and technologies. Register for BlackBerry® DevCon today=
!
> http://p.sf.net/sfu/rim-devcon-copy1
> _______________________________________________
> Cheetahtemplate-discuss mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
>
>
--=20
oliver phillip nicholas
*computer whisperer*
http://bigo.yelp.com/
--90e6ba6135b43a33eb04ad4e61f7
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
$getVar("sso_host_%s" % $myLanguage)<br><br><div class=3D"gmail_q=
uote">On Mon, Sep 19, 2011 at 10:04 AM, R=E9mi ALVADO <span dir=3D"ltr"><=
;<a href=3D"mailto:[email protected]">[email protected]</a>></sp=
an> wrote:<br>
<blockquote class=3D"gmail_quote" style=3D"margin:0 0 0 .8ex;border-left:1p=
x #ccc solid;padding-left:1ex;">Hi,<div><br></div><div>I'm new with Che=
etah and I'm trying to use it to build a deployment tool and replace my=
old configuration files with brand new cheetah templates.=A0</div>
<div>I'm working for a company which edit websites all over the world s=
o lots of our configuration keys are overriden by country.</div>
<div>With Cheetah, I'm storing my configuration into a YAML data storag=
e files and I use a Python script combined with some Bash scripts to find, =
fill and replace all *.cheetah files.=A0</div><div>Please find below an exa=
mple of my test configuration file, my YAML data storage and the expected r=
esult file</div>
<div><br></div><div><font face=3D"'courier new', monospace">-------=
-------- CONF FILE -------------------</font></div><div><div><font face=3D"=
'courier new', monospace">prod:</font></div>
<div><font face=3D"'courier new', monospace">=A0=A0sso:</font></div=
><div><font face=3D"'courier new', monospace">=A0=A0 =A0hosts:</fon=
t></div><div><font face=3D"'courier new', monospace">#for myLanguag=
e in $cultures</font></div>
<div><font face=3D"'courier new', monospace">=A0=A0 =A0 =A0sso_$myL=
anguage:</font></div><div><font face=3D"'courier new', monospace">=
=A0=A0 =A0 =A0 =A0host: =A0 $eval("sso_host_" + myLanguage)</font=
></div>
<div><font face=3D"'courier new', monospace">=A0=A0 =A0 =A0 =A0</fo=
nt><span style=3D"font-family:'courier new', monospace">port: =A0 $=
eval("sso_port_" + myLanguage)</span></div>
<div><font face=3D"'courier new', monospace">#end for</font></div><=
/div><div><font face=3D"'courier new', monospace"><br></font></div>=
<div><font face=3D"'courier new', monospace">--------------- YAML D=
ATA STORAGE -------------------</font></div>
<div><div><font face=3D"'courier new', monospace"># Global=A0</font=
></div><div><font face=3D"'courier new', monospace">cultures:</font=
></div><div><font face=3D"'courier new', monospace">=A0=A0- de</fon=
t></div>
<div><font face=3D"'courier new', monospace">=A0=A0- en</font></div=
><div><font face=3D"'courier new', monospace">=A0=A0- fr</font></di=
v><div><font face=3D"'courier new', monospace"><br>
</font></div><div><font face=3D"'courier new', monospace"># DE</fon=
t></div><div><font face=3D"'courier new', monospace">sso_host_de: =
=A0 =A0 =A0 =A0 <a href=3D"http://sso-de.example.com" target=3D"_blank">sso=
-de.example.com</a></font></div>
</div><div><font face=3D"'courier new', monospace">sso_port_de: =A0=
=A0 =A0 =A0 8081</font></div><div><font face=3D"'courier new', mon=
ospace">[...]</font></div><div><font face=3D"'courier new', monospa=
ce"><br>
</font></div><div><div><font face=3D"'courier new', monospace"># EN=
</font></div><div><font face=3D"'courier new', monospace">sso_host_=
en: =A0 =A0 =A0 =A0 <a href=3D"http://sso-en.example.com" target=3D"_blank"=
>sso-en.example.com</a></font></div>
</div><div><font face=3D"'courier new', monospace">sso_port_en: =A0=
=A0 =A0 =A0 8082</font></div><div><font face=3D"'courier new', mon=
ospace">[...]</font></div><div><font face=3D"'courier new', monospa=
ce"><br>
</font></div><div><div><font face=3D"'courier new', monospace"># FR=
</font></div><div><font face=3D"'courier new', monospace">sso_host_=
fr: =A0 =A0 =A0 =A0 <a href=3D"http://sso-fr.example.com" target=3D"_blank"=
>sso-fr.example.com</a></font></div>
</div><div><font face=3D"'courier new', monospace">sso_port_fr: =A0=
=A0 =A0 =A0 8083</font></div><div><font face=3D"'courier new', mon=
ospace">[...]</font></div><div><font face=3D"'courier new', monospa=
ce"><br>
</font></div><div><font face=3D"'courier new', monospace">---------=
------ YAML DATA STORAGE -------------------</font></div><div><font face=3D=
"'courier new', monospace"><span style=3D"font-family:arial"><div>
<font face=3D"'courier new', monospace">prod:</font></div><div><fon=
t face=3D"'courier new', monospace">=A0=A0sso:</font></div><div><fo=
nt face=3D"'courier new', monospace">=A0=A0 =A0hosts:</font></div>
<div><font face=3D"'courier new', monospace">=A0=A0 =A0 =A0sso_de:<=
/font></div><div><font face=3D"'courier new', monospace">=A0=A0 =A0=
=A0 =A0host: =A0=A0</font><span style=3D"font-family:'courier new'=
, monospace"><a href=3D"http://sso-de.example.com" target=3D"_blank">sso-de=
.example.com</a></span></div>
<div><span style=3D"font-family:'courier new', monospace">=A0=A0 =
=A0 =A0 =A0port: =A0 8081</span></div><div><span style=3D"font-family:'=
courier new', monospace"><span style=3D"font-family:arial"><div>
<font face=3D"'courier new', monospace">=A0=A0 =A0 =A0sso_en:</font=
></div><div><font face=3D"'courier new', monospace">=A0=A0 =A0 =A0 =
=A0host: =A0=A0</font><span style=3D"font-family:'courier new', mon=
ospace"><a href=3D"http://sso-en.example.com" target=3D"_blank">sso-en.exam=
ple.com</a></span></div>
<div><span style=3D"font-family:'courier new', monospace">=A0=A0 =
=A0 =A0 =A0port: =A0 8082</span></div><div><span style=3D"font-family:'=
courier new', monospace"><span style=3D"font-family:arial"><div>
<font face=3D"'courier new', monospace">=A0=A0 =A0 =A0sso_fr:</font=
></div><div><font face=3D"'courier new', monospace">=A0=A0 =A0 =A0 =
=A0host: =A0=A0</font><span style=3D"font-family:'courier new', mon=
ospace"><a href=3D"http://sso-fr.example.com" target=3D"_blank">sso-fr.exam=
ple.com</a></span></div>
<div><span style=3D"font-family:'courier new', monospace">=A0=A0 =
=A0 =A0 =A0port: =A0 8083</span></div><div><span style=3D"font-family:'=
courier new', monospace"><br>
</span></div><div><span style=3D"font-family:'courier new', monospa=
ce">-------------------------------------</span></div></span></span></div><=
/span></span></div></span></font></div><div>
<br>
</div><div>I know using "eval" is not a good idea (eval =3D evil =
:) ) but I've tried several other =A0solutions ("$sso_public_host_=
$myLanguage", "$(sso_public_host_$myLanguage)", ...) and non=
e of them work.</div>
<div>I've also tried to change my data storage file to have something l=
ike :</div><div><font face=3D"'courier new', monospace">de:=A0</fon=
t></div><div><font face=3D"'courier new', monospace">=A0=A0=A0sso_h=
ost_public: ...</font></div>
<div>but I've got the exact same issue with <font face=3D"'courier =
new', monospace">$self[$myLanguage]['sso_host_public']</font> a=
nd I don't like this representation since it's less natural than a =
list of <key,value> tuples.</div>
<div><br></div><div>Do you have any idea how I can use a variable inside an=
other variable name ? It seems to be a bit odd but it would be very conveni=
ent in a production environnement to have a very simple data storage file w=
ith only <key,value> tuples : easy to read and easy to share with a s=
imple copy/paste into release note on a mail, a twiki, ...</div>
<div><br></div><div>Thanks and congratulations this templating engine : des=
pite this little issue, it's really great and I might consider using it=
on another projects, more web oriented :)</div><div><br></div><font color=
=3D"#888888"><div>
R=E9mi</div>
</font><br>----------------------------------------------------------------=
--------------<br>
BlackBerry&reg; DevCon Americas, Oct. 18-20, San Francisco, CA<br>
Learn about the latest advances in developing for the<br>
BlackBerry&reg; mobile platform with sessions, labs & more.<br>
See new tools and technologies. Register for BlackBerry&reg; DevCon tod=
ay!<br>
<a href=3D"http://p.sf.net/sfu/rim-devcon-copy1" target=3D"_blank">http://p=
.sf.net/sfu/rim-devcon-copy1</a> <br>______________________________________=
_________<br>
Cheetahtemplate-discuss mailing list<br>
<a href=3D"mailto:[email protected]">Cheetahtem=
[email protected]</a><br>
<a href=3D"https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-dis=
cuss" target=3D"_blank">https://lists.sourceforge.net/lists/listinfo/cheeta=
htemplate-discuss</a><br>
<br></blockquote></div><br><br clear=3D"all"><div><br></div>-- <br>oliver p=
hillip nicholas<br><i>computer whisperer</i><br><a href=3D"http://bigo.yelp=
.com/" target=3D"_blank">http://bigo.yelp.com/</a><br><br>
--90e6ba6135b43a33eb04ad4e61f7--
--===============7590685220975790815==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
------------------------------------------------------------------------------
BlackBerry® DevCon Americas, Oct. 18-20, San Francisco, CA
Learn about the latest advances in developing for the
BlackBerry® mobile platform with sessions, labs & more.
See new tools and technologies. Register for BlackBerry® DevCon today!
http://p.sf.net/sfu/rim-devcon-copy1
--===============7590685220975790815==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline
_______________________________________________
Cheetahtemplate-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/cheetahtemplate-discuss
--===============7590685220975790815==--