Seamlessly handle nonexistent configurations
This commit is contained in:
parent
b3dce50ce4
commit
a61ba7b9e1
12
main.py
12
main.py
|
@ -1,6 +1,7 @@
|
|||
import json
|
||||
import pickle
|
||||
from os import urandom
|
||||
from os.path import exists
|
||||
from string import digits
|
||||
|
||||
from redis import StrictRedis
|
||||
|
@ -9,6 +10,7 @@ from redis import StrictRedis
|
|||
ZNCErrors = ["Error:", "Unable to load", "does not exist", "doesn't exist"]
|
||||
|
||||
configPath = "conf/"
|
||||
exampleConfigPath = "conf/example"
|
||||
certPath = "cert/"
|
||||
|
||||
filemap = {
|
||||
|
@ -80,8 +82,16 @@ def saveConf(var):
|
|||
|
||||
def loadConf(var):
|
||||
if filemap[var][2] == "json":
|
||||
with open(configPath + filemap[var][0], "r") as f:
|
||||
filename = configPath + filemap[var][0]
|
||||
if not exists(filename):
|
||||
if var == "config":
|
||||
filename = exampleConfigPath + filemap[var][0]
|
||||
else:
|
||||
globals()[var] = {}
|
||||
return
|
||||
with open(filename, "r") as f:
|
||||
globals()[var] = json.load(f)
|
||||
return
|
||||
if var == "alias":
|
||||
# This is a workaround to convert all the keys into integers since JSON
|
||||
# turns them into strings...
|
||||
|
|
Loading…
Reference in New Issue