2019-07-05 09:20:54 +00:00
|
|
|
__filename__ = "config.py"
|
|
|
|
__author__ = "Bob Mottram"
|
|
|
|
__license__ = "AGPL3+"
|
2019-08-29 13:35:29 +00:00
|
|
|
__version__ = "1.0.0"
|
2019-07-05 09:20:54 +00:00
|
|
|
__maintainer__ = "Bob Mottram"
|
|
|
|
__email__ = "bob@freedombone.net"
|
|
|
|
__status__ = "Production"
|
|
|
|
|
|
|
|
import os
|
|
|
|
import json
|
|
|
|
import commentjson
|
|
|
|
|
|
|
|
def createConfig(baseDir: str) -> None:
|
|
|
|
"""Creates a configuration file
|
|
|
|
"""
|
|
|
|
configFilename=baseDir+'/config.json'
|
|
|
|
if os.path.isfile(configFilename):
|
|
|
|
return
|
|
|
|
configJson = {
|
|
|
|
}
|
|
|
|
with open(configFilename, 'w') as fp:
|
2019-09-11 16:12:26 +00:00
|
|
|
commentjson.dump(configJson, fp, indent=4, sort_keys=False)
|
2019-07-05 09:20:54 +00:00
|
|
|
|
|
|
|
def setConfigParam(baseDir: str, variableName: str, variableValue) -> None:
|
|
|
|
"""Sets a configuration value
|
|
|
|
"""
|
|
|
|
createConfig(baseDir)
|
|
|
|
configFilename=baseDir+'/config.json'
|
|
|
|
with open(configFilename, 'r') as fp:
|
|
|
|
configJson=commentjson.load(fp)
|
|
|
|
configJson[variableName]=variableValue
|
|
|
|
with open(configFilename, 'w') as fp:
|
2019-09-11 16:12:26 +00:00
|
|
|
commentjson.dump(configJson, fp, indent=4, sort_keys=False)
|
2019-07-05 09:20:54 +00:00
|
|
|
|
|
|
|
def getConfigParam(baseDir: str, variableName: str):
|
|
|
|
"""Gets a configuration value
|
|
|
|
"""
|
|
|
|
createConfig(baseDir)
|
|
|
|
configFilename=baseDir+'/config.json'
|
|
|
|
with open(configFilename, 'r') as fp:
|
|
|
|
configJson=commentjson.load(fp)
|
|
|
|
if configJson.get(variableName):
|
|
|
|
return configJson[variableName]
|
|
|
|
return None
|