Browse Source
* 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 methodmaster
4 changed files with 48 additions and 9 deletions
@ -0,0 +1,31 @@ |
|||||||
|
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()) |
Loading…
Reference in new issue