hcra/server/parse_config.py
Samuel Sloniker 4d5ce06eb6
Configuration file (#15)
* Add support for config file

Closes #1

* Support changing config path

The path to the config file is accepted as an argument

* Remove old code

Remove the code for the old backend selection method
2021-06-20 16:37:04 -07:00

32 lines
633 B
Python

import shlex
class ConfigSyntaxError(BaseException):
pass
def loadl(lines):
output = {}
for line in [ i.strip() for i in lines ]:
words = shlex.split(line, comments=True)
if len(words) == 0:
pass
elif len(words) == 2:
if words[0] in output:
raise ConfigSyntaxError('keys cannot be redefined')
output[words[0]] = words[1]
else:
raise ConfigSyntaxError('lines must consist of exactly two tokens')
return output
def loads(string):
return loadl(string.split('\n'))
def load(f):
return loadl(f.readlines())