All pastes #96544 Raw Edit

Miscellany

public text v1 · immutable
#96544 ·published 2006-07-22 23:29 UTC
rendered paste body
import string

profileFile = open("./file.conf","r")
profileText = profileFile.read()

profilesList = []

profileFileLines = profileText.splitlines()

def makePropDict(propertiesLine):
    fields = propertiesLine.split("|")
    print fields, "****"
    resultDict =    {1: {"name" : fields[0] },
                    2: {"name" : fields[0],"type" : fields[1] },
                    3: {"name" : fields[0],"type" : fields[1],"defval" : fields[-1] } }[len(fields)]
    print "----------", resultDict
    return resultDict

for line in profileFileLines:
    if(line.startswith("#")!=True):
        if(line.startswith("[")):
            thisProfileDict = {"name" : line.strip("[")}
        elif(line.endswith("]") != True):
            thisProfileDict[line.split("|")[0]] = makePropDict(line)
        else:
            profilesList.append(thisProfileDict)
            thisProfileDict={}

print profilesList