From 88a68b11e6b9ddfe0d5a6f492899a51cdc29c32d Mon Sep 17 00:00:00 2001 From: Uriziel Date: Thu, 20 Feb 2014 22:04:17 +0100 Subject: [PATCH] Added syncplay.ini as an optional config name --- syncplay/constants.py | 2 +- syncplay/ui/ConfigurationGetter.py | 29 +++++++++++++++++------------ 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/syncplay/constants.py b/syncplay/constants.py index e5120ba..17ae2ba 100644 --- a/syncplay/constants.py +++ b/syncplay/constants.py @@ -5,7 +5,7 @@ OSD_WARNING_MESSAGE_DURATION = 15 MPC_OSD_POSITION = 2 #Right corner, 1 for left MPLAYER_OSD_LEVEL = 1 UI_TIME_FORMAT = "[%X] " -DEFAULT_CONFIG_NAME = ".syncplay" +DEFAULT_CONFIG_NAMES = [".syncplay", "syncplay.ini"] #Changing these might be ok REWIND_THRESHOLD = 4 diff --git a/syncplay/ui/ConfigurationGetter.py b/syncplay/ui/ConfigurationGetter.py index 97c3401..ffd683e 100644 --- a/syncplay/ui/ConfigurationGetter.py +++ b/syncplay/ui/ConfigurationGetter.py @@ -141,19 +141,23 @@ class ConfigurationGetter(object): if ':' in host: host, port = host.split(':', 1) return host, int(port) - + def _checkForPortableFile(self): path = utils.findWorkingDir() - if(os.path.isfile(os.path.join(path, constants.DEFAULT_CONFIG_NAME))): - return os.path.join(path, constants.DEFAULT_CONFIG_NAME) - + for name in constants.DEFAULT_CONFIG_NAMES: + if(os.path.isfile(os.path.join(path, name))): + return os.path.join(path, name) + def _getConfigurationFilePath(self): configFile = self._checkForPortableFile() - if(not configFile): - if(os.name <> 'nt'): - configFile = os.path.join(os.getenv('HOME', '.'), constants.DEFAULT_CONFIG_NAME) - else: - configFile = os.path.join(os.getenv('APPDATA', '.'), constants.DEFAULT_CONFIG_NAME) + if not configFile: + for name in constants.DEFAULT_CONFIG_NAMES: + if(configFile and os.path.isfile(configFile)): + break + if(os.name <> 'nt'): + configFile = os.path.join(os.getenv('HOME', '.'), name) + else: + configFile = os.path.join(os.getenv('APPDATA', '.'), name) return configFile def _parseConfigFile(self, iniPath, createConfig = True): @@ -242,9 +246,10 @@ class ConfigurationGetter(object): def _loadRelativeConfiguration(self): locations = self.__getRelativeConfigLocations() for location in locations: - path = location + os.path.sep + constants.DEFAULT_CONFIG_NAME - self._parseConfigFile(path, createConfig = False) - self._checkConfig() + for name in constants.DEFAULT_CONFIG_NAMES: + path = location + os.path.sep + name + self._parseConfigFile(path, createConfig = False) + self._checkConfig() def getConfiguration(self): iniPath = self._getConfigurationFilePath()