]> git.phdru.name Git - xsetbg.git/blob - xsetbg_db.py
Version 4.1.0
[xsetbg.git] / xsetbg_db.py
1 #! /usr/bin/env python
2 """XSetBg database
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_db_path', 'xsetbg_db']
11
12 import anydbm
13 import os
14 import shelve
15 from xsetbg_conf import xsetbg_conf
16
17 db_dirs = []
18 try:
19     xsetbg_db_path = xsetbg_conf.get('xsetbg', 'database')
20 except:
21     xsetbg_db_path = None
22
23 if not xsetbg_db_path:
24     if 'XDG_CACHE_HOME' in os.environ:
25         db_dirs.append(os.environ['XDG_CACHE_HOME'])
26     home_cache = os.path.expanduser('~/.cache')
27     if home_cache not in db_dirs:
28         db_dirs.append(home_cache)
29     db_dirs.append(os.path.dirname(os.path.abspath(__file__)))
30
31     for d in db_dirs:
32         xsetbg_db_path = os.path.join(d, 'xsetbg.db')
33         if os.path.exists(xsetbg_db_path):
34             break
35
36 try:
37     xsetbg_db = shelve.open(xsetbg_db_path, 'r')
38 except anydbm.error:
39     xsetbg_db = None
40
41 if __name__ == '__main__':
42     print "DB dirs:", db_dirs
43     print "DB file:", xsetbg_db_path