Add way to add data to the global login config
authorSimo Sorce <simo@redhat.com>
Thu, 20 Mar 2014 17:21:55 +0000 (13:21 -0400)
committerSimo Sorce <simo@redhat.com>
Thu, 20 Mar 2014 21:28:30 +0000 (17:28 -0400)
Signed-off-by: Simo Sorce <simo@redhat.com>
ipsilon/util/data.py
ipsilon/util/plugin.py

index 70e7d74..8d6ae11 100755 (executable)
@@ -161,6 +161,41 @@ class Store(object):
 
         return (lpo, plco)
 
+    def get_plugin_config(self, facility, plugin):
+        con = None
+        rows = []
+        try:
+            con = sqlite3.connect(self._admin_dbname)
+            cur = con.cursor()
+            cur.execute("CREATE TABLE IF NOT EXISTS " +
+                        facility + " (name TEXT,option TEXT,value TEXT)")
+            cur.execute("SELECT option, value FROM " +
+                        facility + " WHERE name=?", (plugin,))
+            rows = cur.fetchall()
+            con.commit()
+        except sqlite3.Error, e:
+            if con:
+                con.rollback()
+            fpe = (facility, plugin, e)
+            cherrypy.log.error("Failed to get %s/%s config: [%s]" % fpe)
+            raise
+        finally:
+            if con:
+                con.close()
+
+        res = dict()
+        for (option, value) in rows:
+            if option in res:
+                if res[option] is list:
+                    res[option].append(value)
+                else:
+                    v = res[option]
+                    res[option] = [v, value]
+            else:
+                res[option] = value
+
+        return res
+
     def save_plugin_config(self, facility, plugin, options):
         SELECT = "SELECT option, value FROM %s WHERE name=?" % facility
         UPDATE = "UPDATE %s SET value=? WHERE name=? AND option=?" % facility
@@ -169,6 +204,8 @@ class Store(object):
         try:
             con = sqlite3.connect(self._admin_dbname)
             cur = con.cursor()
+            cur.execute("CREATE TABLE IF NOT EXISTS " +
+                        facility + " (name TEXT,option TEXT,value TEXT)")
             curvals = dict()
             for row in cur.execute(SELECT, (plugin,)):
                 curvals[row[0]] = row[1]
index 9ffa131..6c329d6 100755 (executable)
@@ -144,6 +144,9 @@ class PluginObject(object):
             self._config = dict()
         self._config[option] = value
 
+    def get_plugin_config(self, facility):
+        return self._data.get_plugin_config(facility, self.name)
+
     def save_plugin_config(self, facility):
         self._data.save_plugin_config(facility, self.name, self._config)