summaryrefslogtreecommitdiffstats
path: root/src/util
diff options
context:
space:
mode:
authorSimo Sorce <simo@redhat.com>2013-12-12 14:21:41 -0500
committerSimo Sorce <simo@redhat.com>2013-12-18 23:05:57 -0500
commit1e97d03807bd893152bf2cbd0f20102af9c8f80d (patch)
treebd2e6e483d800edc8d9c4db596a46b18e6da2d8b /src/util
parent29d8f5eca90bcca199d7ad84f9934f3f24eed906 (diff)
downloadipsilon.git-1e97d03807bd893152bf2cbd0f20102af9c8f80d.tar.gz
ipsilon.git-1e97d03807bd893152bf2cbd0f20102af9c8f80d.tar.xz
ipsilon.git-1e97d03807bd893152bf2cbd0f20102af9c8f80d.zip
Initial user preferences infrastructure
Signed-off-by: Simo Sorce <simo@redhat.com>
Diffstat (limited to 'src/util')
-rwxr-xr-xsrc/util/data.py49
1 files changed, 48 insertions, 1 deletions
diff --git a/src/util/data.py b/src/util/data.py
index 871f991..ec64588 100755
--- a/src/util/data.py
+++ b/src/util/data.py
@@ -51,7 +51,15 @@ class Store(object):
conf = {}
for row in rows:
- conf[row[0]] = row[1]
+ if row[0] in conf:
+ # multivalued
+ if conf[row[0]] is list:
+ conf[row[0]].append(row[1])
+ else:
+ v = conf[row[0]]
+ conf[row[0]] = [v, row[1]]
+ else:
+ conf[row[0]] = row[1]
return conf
@@ -63,3 +71,42 @@ class Store(object):
path = os.path.join(self._path, 'adminconfig.sqlite')
return self._load_config(path)
+
+ def _load_user_prefs(self, dbname, user):
+ con = None
+ rows = []
+ try:
+ con = sqlite3.connect(dbname)
+ cur = con.cursor()
+ cur.executescript("""
+ CREATE TABLE IF NOT EXISTS users(name TEXT,
+ option TEXT,
+ value TEXT)
+ """)
+ cur.execute("SELECT option, value FROM users "
+ "where name = '%s'" % user)
+ rows = cur.fetchall()
+ con.commit()
+ except sqlite3.Error, e:
+ if con:
+ con.rollback()
+ cherrypy.log.error("Failed to load %s's prefs from "
+ "%s: [%s]" % ( user, dbname, e))
+ finally:
+ if con:
+ con.close()
+
+ conf = {}
+ for row in rows:
+ conf[row[0]] = row[1]
+
+ return conf
+
+ def _get_user_preferences(self, user):
+ path = None
+ if 'user.prefs.db' in cherrypy.config:
+ path = cherrypy.config['user.prefs.db']
+ if not path:
+ path = os.path.join(self._path, 'userprefs.sqlite')
+
+ return self._load_user_prefs(path, user)