mirror of
https://github.com/Unidata/python-awips.git
synced 2025-02-23 22:57:56 -05:00
39 lines
No EOL
973 B
Python
39 lines
No EOL
973 B
Python
##
|
|
##
|
|
|
|
#
|
|
# A set of utility functions for dealing with configuration files.
|
|
#
|
|
#
|
|
#
|
|
# SOFTWARE HISTORY
|
|
#
|
|
# Date Ticket# Engineer Description
|
|
# ------------ ---------- ----------- --------------------------
|
|
# 09/27/10 dgilling Initial Creation.
|
|
#
|
|
#
|
|
#
|
|
|
|
|
|
def parseKeyValueFile(fileName):
|
|
propDict= dict()
|
|
|
|
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
|
|
|
|
return propDict |