diff --git a/.gitignore b/.gitignore index 42e565b5e..e2ae38d70 100644 --- a/.gitignore +++ b/.gitignore @@ -5,6 +5,7 @@ commands_topic.txt .vscode .DS_Store IoTuring/Configurator/configurations.json* +IoTuring/Configurator/dontmoveconf.itg* .venv build *.egg-info \ No newline at end of file diff --git a/IoTuring/Configurator/Configurator.py b/IoTuring/Configurator/Configurator.py index 3ba4a11a9..436c764cb 100644 --- a/IoTuring/Configurator/Configurator.py +++ b/IoTuring/Configurator/Configurator.py @@ -8,10 +8,10 @@ from IoTuring.Configurator.MenuPreset import MenuPreset -from IoTuring.Configurator.ConfiguratorIO import ConfiguratorIO +import IoTuring.Configurator.ConfiguratorIO as ConfiguratorIO # TODO Find new location for this message -HELP_MESSAGE = "\nYou can find the configuration file in the following path: \n\tmacOS\t~/Application Support/IoTuring/configurations.json \n\tLinux\t~/.config/IoTuring/configurations.json \n\tWindows\t%APPDATA%/IoTuring/configurations.json \n\nYou can also set you preferred path that will contain the configuration file by setting the environment variable IOTURING_CONFIG_PATH (file will be stored in $IOTURING_CONFIG_PATH/configurations.json).\n" +HELP_MESSAGE = "\nYou can find the configuration file in the following path: \n\tmacOS\t\t~/Library/Application Support/IoTuring/configurations.json \n\tLinux\t\t~/.config/IoTuring/configurations.json \n\tWindows\t\t%APPDATA%/IoTuring/configurations.json\n\tFallback\t[ioturing_install_path]/Configurator/configurations.json \n\nYou can also set you preferred path that will contain the configuration file by setting the environment variable " + ConfiguratorIO.CONFIG_PATH_ENV_VAR + " (file will be stored in $" + ConfiguratorIO.CONFIG_PATH_ENV_VAR + "/configurations.json).\n" BLANK_CONFIGURATION = {'active_entities': [ @@ -31,7 +31,7 @@ class Configurator(LogObject): def __init__(self) -> None: self.config = None - self.configuratorIO = ConfiguratorIO() + self.configuratorIO = ConfiguratorIO.ConfiguratorIO() self.LoadConfigurations() def GetConfigurations(self): diff --git a/IoTuring/Configurator/ConfiguratorIO.py b/IoTuring/Configurator/ConfiguratorIO.py index e56eb1c92..c956ee147 100644 --- a/IoTuring/Configurator/ConfiguratorIO.py +++ b/IoTuring/Configurator/ConfiguratorIO.py @@ -15,6 +15,7 @@ except: macos_support = False +CONFIG_PATH_ENV_VAR = "IOTURING_CONFIG_DIR" CONFIGURATION_FILE_NAME = "configurations.json" @@ -61,22 +62,28 @@ def getFolderPath(self): folderPath = self.defaultFolderPath() try: - _os = platform.system() - if _os == 'Darwin' and macos_support: - folderPath = self.macOSFolderPath() - folderPath = os.path.join(folderPath, self.directoryName) - elif _os == "Windows": - folderPath = self.windowsFolderPath() - folderPath = os.path.join(folderPath, self.directoryName) - elif _os == "Linux": - folderPath = self.linuxFolderPath() - folderPath = os.path.join(folderPath, self.directoryName) + # Use path from environment variable if present, otherwise os specific folders, otherwise use default path + envvarPath = self.envvarFolderPath() + if envvarPath is not None: + folderPath = envvarPath + else: + _os = platform.system() + if _os == 'Darwin' and macos_support: + folderPath = self.macOSFolderPath() + folderPath = os.path.join(folderPath, self.directoryName) + elif _os == "Windows": + folderPath = self.windowsFolderPath() + folderPath = os.path.join(folderPath, self.directoryName) + elif _os == "Linux": + folderPath = self.linuxFolderPath() + folderPath = os.path.join(folderPath, self.directoryName) except: pass # default folder path will be used # add slash if missing (for log reasons) if not folderPath.endswith(os.sep): folderPath += os.sep + return folderPath def defaultFolderPath(self): @@ -96,6 +103,9 @@ def windowsFolderPath(self): def linuxFolderPath(self): return os.environ["XDG_CONFIG_HOME"] if "XDG_CONFIG_HOME" in os.environ else os.path.join(os.environ["HOME"], ".config") + def envvarFolderPath(self): + return os.environ[CONFIG_PATH_ENV_VAR] if CONFIG_PATH_ENV_VAR in os.environ else None + # In versions prior to 2022.12.2, the configurations file was stored in the same folder as this file def oldFolderPath(self): return os.path.dirname(inspect.getfile(ConfiguratorIO))