6 __author__ = "Oleg Broytman <phd@phdru.name>"
7 __copyright__ = "Copyright (C) 2014, 2015 PhiloSoft Design"
8 __license__ = "GNU GPL"
10 __all__ = ['xsetbg_db_path', 'xsetbg_db']
13 from sqlobject import SQLObject, StringCol, IntCol, BoolCol, dberrors
14 from xsetbg_conf import xsetbg_conf
17 class XSetbg(SQLObject):
18 path = StringCol(alternateID=True)
19 last_shown = IntCol(default=None) # timestamp
20 flag = BoolCol(default=None)
25 xsetbg_db_path = xsetbg_conf.get('xsetbg', 'database')
29 if not xsetbg_db_path:
30 if 'XDG_CACHE_HOME' in os.environ:
31 db_dirs.append(os.environ['XDG_CACHE_HOME'])
32 home_cache = os.path.expanduser('~/.cache')
33 if home_cache not in db_dirs:
34 db_dirs.append(home_cache)
35 db_dirs.append(os.path.dirname(os.path.abspath(__file__)))
38 xsetbg_db_path = os.path.join(d, 'xsetbg.sqlite')
39 if os.path.exists(xsetbg_db_path):
44 XSetbg.setConnection('sqlite:///' + xsetbg_db_path)
46 except dberrors.Error:
53 if __name__ == '__main__':
54 print "DB dirs:", db_dirs
55 print "DB file:", xsetbg_db_path