]> git.phdru.name Git - xsetbg.git/blob - xsetbg_conf.py
Rename db_file to xsetbg_db_path
[xsetbg.git] / xsetbg_conf.py
1 #! /usr/bin/env python
2 """XSetBg config
3
4 """
5
6 __author__ = "Oleg Broytman <phd@phdru.name>"
7 __copyright__ = "Copyright (C) 2014 PhiloSoft Design"
8 __license__ = "GNU GPL"
9
10 __all__ = ['xsetbg_conf']
11
12 import os
13 from ConfigParser import SafeConfigParser
14
15 config_dirs = []
16 if 'XDG_CONFIG_HOME' in os.environ:
17     config_dirs.append(os.environ['XDG_CONFIG_HOME'])
18 if 'XDG_CONFIG_DIRS' in os.environ:
19     config_dirs.extend(os.environ['XDG_CONFIG_DIRS'].split(':'))
20 home_config = os.path.expanduser('~/.config')
21 if home_config not in config_dirs:
22     config_dirs.append(home_config)
23 config_dirs.append(os.path.dirname(os.path.abspath(__file__)))
24
25 for d in config_dirs:
26     xsetbg_conf_file = os.path.join(d, 'xsetbg.conf')
27     if os.path.exists(xsetbg_conf_file):
28         xsetbg_conf = SafeConfigParser()
29         xsetbg_conf.read(xsetbg_conf_file)
30         break
31 else:
32     raise RuntimeError("Cannot find xsetbg.conf; searched %s", config_dirs)
33
34 if __name__ == '__main__':
35     print "Config dirs:", config_dirs
36     print "Config file:", xsetbg_conf_file