config.py 1.2 KB

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