[et-mgmt-tools] Re: Cheetah raw/endraw (was: Templating...)

Aaron Lippold lippold at gmail.com
Wed Jun 13 08:49:48 UTC 2007


Hi,

This looks perfect, since, if I was going to use placeholders, it
would most likely be before the post section, and if I do need to use
them I can use them at the top of %post, like MYVAR=$myvar .... then
use #raw and I can still access ${MYVAR}

... I am thinking paths for /usr/sbin/,/sbin/, etc.... although my
guess is they won't move stuff again from RHEL5 -> RHEL6.

Thanks again,

Aaron

On 6/11/07, Michael DeHaan <mdehaan at redhat.com> wrote:
> Aaron Lippold wrote:
> > /s/When cheetah naturally/When I don't escape the ${var} cheetah/g
> >
> ... snip ...
>
> If you have large blocks of shell in %pre and %post, rather than
> escaping them in Cheetah, I just discovered you can exclose them in #raw
> ... #endraw blocks.
>
> http://www.cheetahtemplate.org/docs/users_guide_html/users_guide.html#SECTION000850000000000000000
>
> If you have template variables (--ksmeta) that you want to access from
> shell, you can assign them to shell variables in your %pre or %post
> sections and
> then use them from inside the raw sections.
>
> See example:
>
> ===
>
> #!/usr/bin/python
>
> from Cheetah.Template import *
>
> # notice how I am setting foo and bar such that they'll be available in
> the raw section...
> data = """#errorCatcher Echo
> \$foo = $foo
> \$bar = $bar
> #raw
> if [ $(grep \" /home \" #echo "${FSTAB} | grep -c \"nosuid\") -eq 0 ];
> then"
> # use $foo
> # use $bar
> #endraw
>
>
> """
>
> search = {
>   "foo" : "gleep",
>   "bar" : "gloop"
> }
>
> t = Template(source=data, searchList=[search])
>
>
> print str(t)
>
> ===
>
> This seems to me a lot cleaner than doing the escaping or needing to
> understand the escaping rules.
>
> --Michael
>
>




More information about the et-mgmt-tools mailing list