# HG changeset patch # User Eero Tamminen # Date 1482447421 -7200 # Node ID 7b3bcc42bc811241b0579d71bca0256b63f0e17c # Parent c95bffdada55bd8cd5b0506aedd34a0cc336b236 PythonUI: Support both Hatari config file locations Hatari v2.0 config file can now be in: - ~/.hatari/hatari.cfg (old) - ~/.config/hatari/hatari.cfg (new) diff -r c95bffdada55 -r 7b3bcc42bc81 python-ui/config.py --- a/python-ui/config.py Mon Dec 19 11:23:27 2016 +0100 +++ b/python-ui/config.py Fri Dec 23 00:57:01 2016 +0200 @@ -67,22 +67,23 @@ # Handle INI style configuration files as used by Hatari class ConfigStore: - def __init__(self, userconfdir, defaults = {}, miss_is_error = True): + def __init__(self, confdirs, defaults = {}, miss_is_error = True): "ConfigStore(userconfdir, fgfile[,defaults,miss_is_error])" self.defaults = defaults - self.userpath = self._get_full_userpath(userconfdir) + self.userpath = self._get_full_userpath(confdirs) self.miss_is_error = miss_is_error - def _get_full_userpath(self, leafdir): + def _get_full_userpath(self, confdirs): "get_userpath(leafdir) -> config file default save path from HOME, CWD or their subdir" # user's hatari.cfg can be in home or current work dir, # current dir is used only if $HOME fails for path in (os.getenv("HOME"), os.getenv("HOMEPATH"), os.getcwd()): if path and os.path.exists(path) and os.path.isdir(path): - if leafdir: - hpath = "%s%c%s" % (path, os.path.sep, leafdir) - if os.path.exists(hpath) and os.path.isdir(hpath): - return hpath + for leafdir in confdirs: + if leafdir: + hpath = "%s%c%s" % (path, os.path.sep, leafdir) + if os.path.exists(hpath) and os.path.isdir(hpath): + return hpath return path return None diff -r c95bffdada55 -r 7b3bcc42bc81 python-ui/hatari.py --- a/python-ui/hatari.py Mon Dec 19 11:23:27 2016 +0100 +++ b/python-ui/hatari.py Fri Dec 23 00:57:01 2016 +0200 @@ -269,8 +269,8 @@ } "access methods to Hatari configuration file variables and command line options" def __init__(self, hatari): - userconfdir = ".hatari" - ConfigStore.__init__(self, userconfdir) + confdirs = [".config/hatari", ".hatari"] + ConfigStore.__init__(self, confdirs) conffilename = "hatari.cfg" self.load(self.get_filepath(conffilename))