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/>.
27 def __init__(self, path=None):
29 self._path = os.getcwd()
33 def _load_config(self, dbname):
37 con = sqlite3.connect(dbname)
40 CREATE TABLE IF NOT EXISTS config(name TEXT, value TEXT)
42 cur.execute("SELECT * FROM config")
45 except sqlite3.Error, e:
48 cherrypy.log.error("Failed to load config: [%s]" % e)
57 if conf[row[0]] is list:
58 conf[row[0]].append(row[1])
61 conf[row[0]] = [v, row[1]]
67 def get_admin_config(self):
69 if 'admin.config.db' in cherrypy.config:
70 path = cherrypy.config['admin.config.db']
72 path = os.path.join(self._path, 'adminconfig.sqlite')
74 return self._load_config(path)
76 def _load_user_prefs(self, dbname, user):
80 con = sqlite3.connect(dbname)
83 CREATE TABLE IF NOT EXISTS users(name TEXT,
87 cur.execute("SELECT option, value FROM users "
88 "where name = '%s'" % user)
91 except sqlite3.Error, e:
94 cherrypy.log.error("Failed to load %s's prefs from "
95 "%s: [%s]" % (user, dbname, e))
102 conf[row[0]] = row[1]
106 def get_user_preferences(self, user):
108 if 'user.prefs.db' in cherrypy.config:
109 path = cherrypy.config['user.prefs.db']
111 path = os.path.join(self._path, 'userprefs.sqlite')
113 return self._load_user_prefs(path, user)