ansible-tools/siteconf.py
2022-09-07 02:35:53 +02:00

30 lines
813 B
Python
Executable File

import os
import re
#from pprint import pprint
configuration = "{}/../site.conf".format(os.path.dirname(__file__))
site_conf = {}
def read():
with open(configuration, "r") as cf:
for line in cf:
line = line.rstrip();
if r := re.match('#', line):
continue
if r := re.match('\s*$', line):
continue
if r := re.match('\[([A-Za-z0-9_-]+)\]', line):
site = r[1]
site_conf[site] = {}
elif r := re.match('([A-Za-z0-9_-]+)\s+(.+)', line):
site_conf[site][r[1]] = r[2]
else:
print(f"invalid line in site_conf: {line}")
exit(1)
cf.close()
return site_conf
# vim: set tabstop=4 shiftwidth=4 expandtab smarttab: