X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=xsetbg_conf.py;h=368667c9b02e9362dc2d66f9a5e934da1080dca1;hb=62e1582b16651a19a941b7db643fd8771f35c051;hp=ad5125b24b1865f2da5d934f90fd5996e33223cc;hpb=666424147b909d29d979d45990aa967e117f6cec;p=xsetbg.git diff --git a/xsetbg_conf.py b/xsetbg_conf.py old mode 100644 new mode 100755 index ad5125b..368667c --- a/xsetbg_conf.py +++ b/xsetbg_conf.py @@ -1,3 +1,4 @@ +#! /usr/bin/env python """XSetBg config """ @@ -11,7 +12,27 @@ __all__ = ['xsetbg_conf'] import os from ConfigParser import SafeConfigParser +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) + xsetbg_dir = os.path.dirname(os.path.abspath(__file__)) +config_dirs.append(xsetbg_dir) + +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) -xsetbg_conf = SafeConfigParser() -xsetbg_conf.read(os.path.join(xsetbg_dir, 'xsetbg.conf')) +if __name__ == '__main__': + print "Config dirs:", config_dirs + print "Config file:", xsetbg_conf_file