X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=xsetbg_conf.py;h=05777324b9a1b62c8642ba0c4219ded96113cfc9;hb=80c5a31f64e2722657d472191b52589210b7f0d8;hp=a77d678b3e3ff139fcfb8cc2db9134621eb922b5;hpb=a337e26c169baecb75197b50db5fd734c39f6187;p=xsetbg.git diff --git a/xsetbg_conf.py b/xsetbg_conf.py index a77d678..0577732 100755 --- a/xsetbg_conf.py +++ b/xsetbg_conf.py @@ -12,7 +12,25 @@ __all__ = ['xsetbg_conf'] import os from ConfigParser import SafeConfigParser -xsetbg_dir = os.path.dirname(os.path.abspath(__file__)) +config_dirs = [] +if 'XDG_CONFIG_HOME' in os.environ: + config_dirs.append(os.environ['XDG_CONFIG_HOME']) +if 'XDG_CONFIG_DIRS' in os.environ: + config_dirs.extend(os.environ['XDG_CONFIG_DIRS'].split(':')) +home_config = os.path.expanduser('~/.config') +if home_config not in config_dirs: + config_dirs.append(home_config) +config_dirs.append(os.path.dirname(os.path.abspath(__file__))) -xsetbg_conf = SafeConfigParser() -xsetbg_conf.read(os.path.join(xsetbg_dir, 'xsetbg.conf')) +for d in config_dirs: + xsetbg_conf_file = os.path.join(d, 'xsetbg.conf') + if os.path.exists(xsetbg_conf_file): + xsetbg_conf = SafeConfigParser() + xsetbg_conf.read(xsetbg_conf_file) + break +else: + raise RuntimeError("Cannot find xsetbg.conf; searched %s", config_dirs) + +if __name__ == '__main__': + print "Config dirs:", config_dirs + print "Config file:", xsetbg_conf_file