Friday, November 28, 2008

understanding python's ConfigParser - sort-of

call these notes to myself: ConfigParser is a python core module that is used to parse a configuration file

ok that was a path issue - my test.py file was higher in the directory structure than wubi.py so it was able to find the data directory (i actually did two things - should have done them one at a time 1. modified pythonpath env variable to exhaustively include every directory being used 2. copied the data directory to the same location as the wubi.py file - i'll step back and see which one worked)

running wubi python code - the code uses a configuration file to both find out what to install and where to get it

the configuration file looks something like this - but with several sections (this shows only one section:
############ config.ini #####################
[mysection1]
arch=i386
name=fedora
packages=fedora-desktop
metalink=http://somewebsite.com/metalink
metalink2=http://someotherwebsite.com/metalink
ordering=1
##############################################

#!/usr/bin/env python
# the file to parse here is the actual .ini file shipped with wubi
import ConfigParser

myfiletoparse = 'c:\python25\scripts\intrepid.python\data\isolist.ini'
print('Parsing myfiletoparse=%s' % myfiletoparse)
configtree = ConfigParser.ConfigParser()
configtree.read(myfiletoparse) #reads file looking for [sections] etc

for distro in configtree.sections():
print('the section=%s' % distro)

##################### no problem parsing the file ###############33
the section=Xubuntu-amd64
the section=Kubuntu-amd64
the section=Ubuntu-amd64
the section=Ubuntu-i386
the section=Kubuntu-i386

current problem is that the file fails to open in the wubi code - exactly the same file, same path and everything. I added a print statement in the ConfigParser.read() function

#### part of Config.Parser.read() ################
read_ok = []
for filename in filenames:
try:
fp = open(filename)
except IOError:
print('cannot seem to open the file=%s' % filename)
continue
self._read(fp, filename)
fp.close()
read_ok.append(filename)
return read_ok
#######################################################################
here is the debugger output - not sure what is going on here unless it is apath issue
so i'll try the same fle in a different location or something

No comments: