3 # Copyright (C) 2013 Simo Sorce <simo@redhat.com>
5 # see file 'COPYING' for use and warranty information
7 # This program is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation, either version 3 of the License, or
10 # (at your option) any later version.
12 # This program is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
26 def __init__(self, path=None):
28 self._path = os.getcwd()
32 def _load_config(self, dbname):
36 con = sqlite3.connect(dbname)
39 CREATE TABLE IF NOT EXISTS config(name TEXT, value TEXT)
41 cur.execute("SELECT * FROM config")
44 except sqlite3.Error, e:
47 cherrypy.log.error("Failed to load config: [%s]" % e)
56 if conf[row[0]] is list:
57 conf[row[0]].append(row[1])
60 conf[row[0]] = [v, row[1]]
66 def get_admin_config(self):
68 if 'admin.config.db' in cherrypy.config:
69 path = cherrypy.config['admin.config.db']
71 path = os.path.join(self._path, 'adminconfig.sqlite')
73 return self._load_config(path)
75 def _load_user_prefs(self, dbname, user):
79 con = sqlite3.connect(dbname)
82 CREATE TABLE IF NOT EXISTS users(name TEXT,
86 cur.execute("SELECT option, value FROM users "
87 "where name = '%s'" % user)
90 except sqlite3.Error, e:
93 cherrypy.log.error("Failed to load %s's prefs from "
94 "%s: [%s]" % ( user, dbname, e))
101 conf[row[0]] = row[1]
105 def _get_user_preferences(self, user):
107 if 'user.prefs.db' in cherrypy.config:
108 path = cherrypy.config['user.prefs.db']
110 path = os.path.join(self._path, 'userprefs.sqlite')
112 return self._load_user_prefs(path, user)