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, connectionForURI, sqlhub, \
14 StringCol, UnicodeCol, IntCol, BoolCol, dberrors
15 from xsetbg_conf import xsetbg_conf
18 class SqliteSequence(SQLObject):
21 name = StringCol(unique=True)
25 class XSetBg(SQLObject):
26 full_name = UnicodeCol(alternateID=True)
27 last_shown = IntCol(default=None) # timestamp
28 flag = BoolCol(default=None)
33 xsetbg_db_path = xsetbg_conf.get('xsetbg', 'database')
37 if not xsetbg_db_path:
38 if 'XDG_CACHE_HOME' in os.environ:
39 db_dirs.append(os.environ['XDG_CACHE_HOME'])
40 home_cache = os.path.expanduser('~/.cache')
41 if home_cache not in db_dirs:
42 db_dirs.append(home_cache)
43 db_dirs.append(os.path.dirname(os.path.abspath(__file__)))
46 xsetbg_db_path = os.path.join(d, 'xsetbg.sqlite')
47 if os.path.exists(xsetbg_db_path):
51 sqlhub.processConnection = \
52 connectionForURI('sqlite:///%s' % xsetbg_db_path)
56 xsetbg_db = XSetBg # Table exists but is empty
57 except dberrors.Error:
64 if __name__ == '__main__':
65 print "DB dirs:", db_dirs
66 print "DB file:", xsetbg_db_path