You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.9 KiB
Python
49 lines
1.9 KiB
Python
import os, json
|
|
|
|
class ConfigurationController():
|
|
|
|
CONFIG_FILENAME = 'ffx.json'
|
|
DATABASE_FILENAME = 'ffx.db'
|
|
LOG_FILENAME = 'ffx.log'
|
|
|
|
DATABASE_PATH_CONFIG_KEY = 'databasePath'
|
|
LOG_DIRECTORY_CONFIG_KEY = 'logDirectory'
|
|
|
|
def __init__(self):
|
|
|
|
self.__homeDir = os.path.expanduser("~")
|
|
self.__localVarDir = os.path.join(self.__homeDir, '.local', 'var')
|
|
self.__localEtcDir = os.path.join(self.__homeDir, '.local', 'etc')
|
|
|
|
self.__configurationData = {}
|
|
|
|
# .local/etc/ffx.json
|
|
self.__configFilePath = os.path.join(self.__localEtcDir, ConfigurationController.CONFIG_FILENAME)
|
|
if os.path.isfile(self.__configFilePath):
|
|
with open(self.__configFilePath, 'r') as configurationFile:
|
|
self.__configurationData = json.load(configurationFile)
|
|
|
|
if ConfigurationController.DATABASE_PATH_CONFIG_KEY in self.__configurationData.keys():
|
|
self.__databaseFilePath = self.__configurationData[ConfigurationController.DATABASE_PATH_CONFIG_KEY]
|
|
os.makedirs(os.path.dirname(self.__databaseFilePath), exist_ok=True)
|
|
else:
|
|
ffxVarDir = os.path.join(self.__localVarDir, 'ffx')
|
|
os.makedirs(ffxVarDir, exist_ok=True)
|
|
self.__databaseFilePath = os.path.join(ffxVarDir, ConfigurationController.DATABASE_FILENAME)
|
|
|
|
if ConfigurationController.LOG_DIRECTORY_CONFIG_KEY in self.__configurationData.keys():
|
|
self.__logDir = self.__configurationData[ConfigurationController.LOG_DIRECTORY_CONFIG_KEY]
|
|
else:
|
|
self.__logDir = os.path.join(self.__localVarDir, 'log')
|
|
os.makedirs(self.__logDir, exist_ok=True)
|
|
|
|
|
|
def getHomeDirectory(self):
|
|
return self.__homeDir
|
|
|
|
def getLogFilePath(self):
|
|
return os.path.join(self.__logDir, ConfigurationController.LOG_FILENAME)
|
|
|
|
def getDatabaseFilePath(self):
|
|
return self.__databaseFilePath
|