]> git.phdru.name Git - xsetbg.git/blobdiff - xsetbg_conf.py
Feat(DB): Add column `is_image`
[xsetbg.git] / xsetbg_conf.py
index a77d678b3e3ff139fcfb8cc2db9134621eb922b5..1066bfa7e8ba8f46577e0044e45270fe831553f4 100755 (executable)
@@ -3,16 +3,32 @@
 
 """
 
-__author__ = "Oleg Broytman <phd@phdru.name>"
-__copyright__ = "Copyright (C) 2014 PhiloSoft Design"
-__license__ = "GNU GPL"
+import os
+from ConfigParser import SafeConfigParser
 
 __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