epicyon/config.py

47 lines
1.2 KiB
Python
Raw Normal View History

2020-04-02 09:05:40 +00:00
__filename__ = "config.py"
__author__ = "Bob Mottram"
__license__ = "AGPL3+"
__version__ = "1.1.0"
__maintainer__ = "Bob Mottram"
__email__ = "bob@freedombone.net"
__status__ = "Production"
2019-07-05 09:20:54 +00:00
import os
2019-10-22 11:55:06 +00:00
from utils import loadJson
from utils import saveJson
2019-07-05 09:20:54 +00:00
2020-04-02 09:05:40 +00:00
2019-07-05 09:20:54 +00:00
def createConfig(baseDir: str) -> None:
"""Creates a configuration file
"""
2020-04-02 09:05:40 +00:00
configFilename = baseDir + '/config.json'
2019-07-05 09:20:54 +00:00
if os.path.isfile(configFilename):
return
2020-04-02 09:05:40 +00:00
configJson = {
2019-07-05 09:20:54 +00:00
}
2020-04-02 09:05:40 +00:00
saveJson(configJson, configFilename)
2019-07-05 09:20:54 +00:00
def setConfigParam(baseDir: str, variableName: str, variableValue) -> None:
"""Sets a configuration value
"""
createConfig(baseDir)
2020-04-02 09:05:40 +00:00
configFilename = baseDir + '/config.json'
configJson = {}
2019-10-22 11:55:06 +00:00
if os.path.isfile(configFilename):
2020-04-02 09:05:40 +00:00
configJson = loadJson(configFilename)
configJson[variableName] = variableValue
saveJson(configJson, configFilename)
2019-07-05 09:20:54 +00:00
def getConfigParam(baseDir: str, variableName: str):
"""Gets a configuration value
"""
createConfig(baseDir)
2020-04-02 09:05:40 +00:00
configFilename = baseDir + '/config.json'
configJson = loadJson(configFilename)
2019-10-22 11:55:06 +00:00
if configJson:
if configJson.get(variableName):
return configJson[variableName]
2019-07-05 09:20:54 +00:00
return None