config.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. __filename__ = "config.py"
  2. __author__ = "Bob Mottram"
  3. __license__ = "AGPL3+"
  4. __version__ = "1.0.0"
  5. __maintainer__ = "Bob Mottram"
  6. __email__ = "bob@freedombone.net"
  7. __status__ = "Production"
  8. import os
  9. import time
  10. import json
  11. import commentjson
  12. from utils import loadJson
  13. from utils import saveJson
  14. def createConfig(baseDir: str) -> None:
  15. """Creates a configuration file
  16. """
  17. configFilename=baseDir+'/config.json'
  18. if os.path.isfile(configFilename):
  19. return
  20. configJson = {
  21. }
  22. saveJson(configJson,configFilename)
  23. def setConfigParam(baseDir: str, variableName: str, variableValue) -> None:
  24. """Sets a configuration value
  25. """
  26. createConfig(baseDir)
  27. configFilename=baseDir+'/config.json'
  28. configJson={}
  29. if os.path.isfile(configFilename):
  30. configJson=loadJson(configFilename)
  31. configJson[variableName]=variableValue
  32. saveJson(configJson,configFilename)
  33. def getConfigParam(baseDir: str, variableName: str):
  34. """Gets a configuration value
  35. """
  36. createConfig(baseDir)
  37. configFilename=baseDir+'/config.json'
  38. configJson=loadJson(configFilename)
  39. if configJson:
  40. if configJson.get(variableName):
  41. return configJson[variableName]
  42. return None