]> git.phdru.name Git - xsetbg.git/commitdiff
Search xsetbg.conf in XDG directories
authorOleg Broytman <phd@phdru.name>
Sat, 8 Mar 2014 23:10:28 +0000 (03:10 +0400)
committerOleg Broytman <phd@phdru.name>
Sat, 8 Mar 2014 23:10:28 +0000 (03:10 +0400)
Search xsetbg.conf in $XDG_CONFIG_HOME or $XDG_CONFIG_DIRS or $HOME/.config.

TODO
xsetbg_conf.py [changed mode: 0644->0755]

diff --git a/TODO b/TODO
index 8f5ff64dc6a1091a0cec4929626339e30829f5e9..55e0360e02a459a8cf36a0ccf29df3d6256c5103 100644 (file)
--- a/TODO
+++ b/TODO
@@ -1,4 +1,3 @@
-Move xsetbg.conf to $XDG_CONFIG_HOME or $XDG_CONFIG_DIRS or $HOME/.config.
 Move xsetbg.db to $XDG_CACHE_HOME or $HOME/.cache.
 
 
old mode 100644 (file)
new mode 100755 (executable)
index ad5125b..0577732
@@ -1,3 +1,4 @@
+#! /usr/bin/env python
 """XSetBg config
 
 """
@@ -11,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