env.ini
vantive.conf
envexample.pl
Now i have a python script that does the same thing
envexample.py
#!/usr/bin/python
import os.path
import re
import pprint
def getEnv(ref):
for file in ref['config']:
print( file['env'] )
if os.path.isfile(file['env']):
fh = open(file['env'],"r+")
for line in fh:
matchsec = re.search(r"\s*\[(\w+)\]",line)
if match:
section = matchsec.group(1)
continue
# match on equals
match = re.search(r"=",line)
if match:
# split key value pairs
sp = line.split( "=" , 2)
# Strip the line to remove whitespace.
key = sp[0].strip()
value = sp[1].strip()
# change the key to upper
key = key.upper()
ref[key] = value
if section in ref:
# if there just change value
ref[section][key] = value
ref[key] = value
else:
# if not then add the key and value
ref[section] = {}
ref[section][key] = value
# ref[key] = value
else:
continue
fh.close()
else:
print "file could not be found ", file
# end getEnv
#--- MAIN
# make a dictionary
ref = { }
# add a list with dictionary
ref['config'] = [ {'env':'env.ini'}, {'env':'vantiv.conf'} ]
getEnv(ref)
pp = pprint.PrettyPrinter()
pp.pprint( ref )