Pass through configuration directories to compose
This commit is contained in:
18
main.py
18
main.py
@@ -5,13 +5,14 @@ from os.path import exists
|
||||
from string import digits
|
||||
|
||||
from redis import StrictRedis
|
||||
from os import getenv
|
||||
|
||||
# List of errors ZNC can give us
|
||||
ZNCErrors = ["Error:", "Unable to load", "does not exist", "doesn't exist"]
|
||||
|
||||
configPath = "conf/"
|
||||
exampleConfigPath = "conf/example/"
|
||||
certPath = "cert/"
|
||||
configPath = getenv("THRESHOLD_CONFIG_DIR", "conf/live/")
|
||||
templateConfigPath = getenv("THRESHOLD_TEMPLATE_DIR", "conf/templates/")
|
||||
certPath = getenv("THRESHOLD_CERT_DIR", "conf/cert/")
|
||||
|
||||
filemap = {
|
||||
# JSON configs
|
||||
@@ -70,6 +71,8 @@ def liveNets():
|
||||
|
||||
|
||||
def saveConf(var):
|
||||
if var in ("help", "aliasdata"):
|
||||
return # no need to save this
|
||||
if filemap[var][2] == "json":
|
||||
with open(configPath + filemap[var][0], "w") as f:
|
||||
json.dump(globals()[var], f, indent=4)
|
||||
@@ -83,21 +86,26 @@ def saveConf(var):
|
||||
def loadConf(var):
|
||||
if filemap[var][2] == "json":
|
||||
filename = configPath + filemap[var][0]
|
||||
# Only take the help from the templates
|
||||
if var in ("help", "aliasdata"):
|
||||
filename = templateConfigPath + filemap[var][0]
|
||||
if not exists(filename):
|
||||
# Load the template config
|
||||
if var == "config":
|
||||
filename = exampleConfigPath + filemap[var][0]
|
||||
filename = templateConfigPath + filemap[var][0]
|
||||
else:
|
||||
# Everything else should be blank
|
||||
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...
|
||||
# Dammit Jason!
|
||||
global alias
|
||||
alias = {int(x): y for x, y in alias.items()}
|
||||
|
||||
elif filemap[var][2] == "pickle":
|
||||
try:
|
||||
with open(configPath + filemap[var][0], "rb") as f:
|
||||
|
||||
Reference in New Issue
Block a user