Refactor config path logic
This commit is contained in:
parent
89c1f2089a
commit
62d49f53eb
@ -322,21 +322,22 @@ class ConfigurationGetter(object):
|
|||||||
|
|
||||||
def _getConfigurationFilePath(self):
|
def _getConfigurationFilePath(self):
|
||||||
configFile = self._checkForPortableFile()
|
configFile = self._checkForPortableFile()
|
||||||
if not configFile:
|
if configFile:
|
||||||
for name in constants.CONFIG_NAMES:
|
return configFile
|
||||||
if configFile and os.path.isfile(configFile):
|
for name in constants.CONFIG_NAMES:
|
||||||
break
|
configFile = self._expandConfigPath(name)
|
||||||
if os.name <> 'nt':
|
if os.path.isfile(configFile):
|
||||||
configFile = os.path.join(os.getenv('HOME', '.'), name)
|
return configFile
|
||||||
else:
|
return self._expandConfigPath()
|
||||||
configFile = os.path.join(os.getenv('APPDATA', '.'), name)
|
|
||||||
if configFile and not os.path.isfile(configFile):
|
|
||||||
if os.name <> 'nt':
|
|
||||||
configFile = os.path.join(os.getenv('HOME', '.'), constants.DEFAULT_CONFIG_NAME_LINUX)
|
|
||||||
else:
|
|
||||||
configFile = os.path.join(os.getenv('APPDATA', '.'), constants.DEFAULT_CONFIG_NAME_WINDOWS)
|
|
||||||
|
|
||||||
return configFile
|
def _expandConfigPath(self, name = None):
|
||||||
|
if os.name != 'nt':
|
||||||
|
prefix = os.getenv('HOME', '.')
|
||||||
|
default_name = constants.DEFAULT_CONFIG_NAME_LINUX
|
||||||
|
else:
|
||||||
|
prefix = os.getenv('APPDATA', '.')
|
||||||
|
default_name = constants.DEFAULT_CONFIG_NAME_WINDOWS
|
||||||
|
return os.path.join(prefix, name or default_name)
|
||||||
|
|
||||||
def _parseConfigFile(self, iniPath, createConfig=True):
|
def _parseConfigFile(self, iniPath, createConfig=True):
|
||||||
parser = SafeConfigParserUnicode()
|
parser = SafeConfigParserUnicode()
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user