Default to XDG_CONFIG_HOME on non-'nt' platforms

The default config path on Linux becomes `~/.config/syncplay.ini`,
provided the user hasn't changed her $XDG_CONFIG_HOME. Existing
installations continue to read their config from `~/.syncplay`, should
that file exist.
This commit is contained in:
Flisk 2018-06-05 17:52:27 +02:00
parent 3d7c3ff538
commit dbe490a5ee
2 changed files with 14 additions and 8 deletions

View File

@ -8,8 +8,7 @@ MPC_OSD_POSITION = 1 #Right corner, 1 for left
MPLAYER_OSD_LEVEL = 1
UI_TIME_FORMAT = "[%X] "
CONFIG_NAMES = [".syncplay", "syncplay.ini"] #Syncplay searches first to last
DEFAULT_CONFIG_NAME_WINDOWS = "syncplay.ini"
DEFAULT_CONFIG_NAME_LINUX = ".syncplay"
DEFAULT_CONFIG_NAME = "syncplay.ini"
RECENT_CLIENT_THRESHOLD = "1.5.3" #This and higher considered 'recent' clients (no warnings)
WARN_OLD_CLIENTS = True #Use MOTD to inform old clients to upgrade
LIST_RELATIVE_CONFIGS = True # Print list of relative configs loaded

View File

@ -325,19 +325,26 @@ class ConfigurationGetter(object):
if configFile:
return configFile
for name in constants.CONFIG_NAMES:
configFile = self._expandConfigPath(name)
configFile = self._expandConfigPath(name, xdg = False)
if os.path.isfile(configFile):
return configFile
return self._expandConfigPath()
def _expandConfigPath(self, name = None):
def _expandConfigPath(self, name = None, xdg = True):
if os.name != 'nt':
prefix = os.getenv('HOME', '.')
default_name = constants.DEFAULT_CONFIG_NAME_LINUX
if xdg:
prefix = self._getXdgConfigHome()
else:
prefix = os.getenv('HOME', '.')
else:
prefix = os.getenv('APPDATA', '.')
default_name = constants.DEFAULT_CONFIG_NAME_WINDOWS
return os.path.join(prefix, name or default_name)
return os.path.join(prefix, name or constants.DEFAULT_CONFIG_NAME)
def _getXdgConfigHome(self):
path = os.getenv('XDG_CONFIG_HOME', os.path.expanduser('~/.config'))
if not os.path.isdir(path):
os.mkdir(path, 0o755)
return path
def _parseConfigFile(self, iniPath, createConfig=True):
parser = SafeConfigParserUnicode()