+ xsetbg_db_path = xsetbg_conf.get('xsetbg', 'database')
+except Exception:
+ xsetbg_db_path = None
+
+if not xsetbg_db_path:
+ if 'XDG_CACHE_HOME' in os.environ:
+ db_dirs.append(os.environ['XDG_CACHE_HOME'])
+ home_cache = os.path.expanduser('~/.cache')
+ if home_cache not in db_dirs:
+ db_dirs.append(home_cache)
+ db_dirs.append(os.path.dirname(os.path.abspath(__file__)))
+
+ for d in db_dirs:
+ xsetbg_db_path = os.path.join(d, 'xsetbg.sqlite')
+ if os.path.exists(xsetbg_db_path):
+ break
+
+if xsetbg_db_path:
+ sqlhub.processConnection = \
+ connectionForURI('sqlite:///%s' % xsetbg_db_path)
+ try:
+ XSetBg.select()[0]
+ except IndexError:
+ xsetbg_db = XSetBg # Table exists but is empty
+ except dberrors.Error:
+ xsetbg_db = None
+ else:
+ xsetbg_db = XSetBg
+else: