I need some help building snippets
Dan White
ygor at comcast.net
Fri Jul 29 13:53:04 UTC 2011
I have some python code that does what I want to do in a snippet, but I cannot translate it into something that will get past the cheetah compile/conversion.
Just a few lines - here they are:
<python code>
import sys, ConfigParser
cf=ConfigParser.ConfigParser()
sys.stdout.write("cf=")
print cf
list=cf.read ( 'mysettings.cfg' )
sys.stdout.write("cfg file=")
print list
sys.stdout.write("sections=")
print cf.sections()
print cf.get ( 'MySection', 'field1' )
print cf.get ( 'MySection', 'field2' )
</python code>
The file (mysettings.cfg) contains:
[MySection]
field1 = this
field2 = that
When I execute this python script, I get this output:
cf=<ConfigParser.ConfigParser instance at (address)>
cfg file=['mysettings.cfg']
sections=[MySection]
this
that
Now to the cobbler/cheetah snippet:
<snippet>
#import ConfigParser
#set $cf=$ConfigParser.ConfigParser()
#echo 'cf=>'
#echo $cf
#echo '\n'
#set $list=$cf.read ( 'mysettings.cfg' )
#echo 'cfg file=>'
#echo $list
#echo '\n'
#set $sec = $cf.sections()
#echo 'sections=>'
#echo $sec
#echo '\n'
#set $one = $cf.get ( 'MySection', 'field1' )
#echo $one
#set $two = $cf.get ( 'MySection', 'field2' )
#echo $two
</snippet>
But the cheetah fails in an odd (to me) way.
First of all, the line:
#set $list=$cf.read ( 'mysettings.cfg' )
fails unless I change it to :
#set $list= cf.read ( 'mysettings.cfg' )
and then I get the following output:
cf=<ConfigParser.ConfigParser instance at (address)>
cfg file=[]
sections=[]
and then the script will fail on the "get" method calls
Any suggestions / clues out there ?
“Sometimes I think the surest sign that intelligent life exists elsewhere in the universe is that none of it has tried to contact us.”
Bill Waterson (Calvin & Hobbes)
More information about the cobbler
mailing list