python-awips/awips/ConfigFileUtil.py

39 lines
973 B
Python
Raw Normal View History

2015-06-12 11:57:06 -06:00
##
##
#
# A set of utility functions for dealing with configuration files.
#
2016-03-16 16:32:17 -05:00
#
#
2015-06-12 11:57:06 -06:00
# SOFTWARE HISTORY
2016-03-16 16:32:17 -05:00
#
2015-06-12 11:57:06 -06:00
# Date Ticket# Engineer Description
# ------------ ---------- ----------- --------------------------
# 09/27/10 dgilling Initial Creation.
#
2016-03-16 16:32:17 -05:00
#
#
2015-06-12 11:57:06 -06:00
def parseKeyValueFile(fileName):
propDict= dict()
2016-03-16 16:32:17 -05:00
2015-06-12 11:57:06 -06:00
try:
propFile= open(fileName, "rU")
for propLine in propFile:
propDef= propLine.strip()
if len(propDef) == 0:
continue
if propDef[0] in ( '#' ):
continue
punctuation= [ propDef.find(c) for c in ':= ' ] + [ len(propDef) ]
found= min( [ pos for pos in punctuation if pos != -1 ] )
name= propDef[:found].rstrip()
value= propDef[found:].lstrip(":= ").rstrip()
propDict[name]= value
propFile.close()
except:
pass
2016-03-16 16:32:17 -05:00
return propDict