diff options
author | Simo Sorce <simo@redhat.com> | 2014-03-19 18:41:56 -0400 |
---|---|---|
committer | Simo Sorce <simo@redhat.com> | 2014-03-20 17:28:03 -0400 |
commit | 90dabd2d3e2509b20b2df104d73157ba02128bbe (patch) | |
tree | 04691c4a7727a09e893c896172c9aa5c4719ad0c /ipsilon | |
parent | 7a9858c4c93aecde396910607821487513a84191 (diff) | |
download | ipsilon-90dabd2d3e2509b20b2df104d73157ba02128bbe.tar.gz ipsilon-90dabd2d3e2509b20b2df104d73157ba02128bbe.tar.xz ipsilon-90dabd2d3e2509b20b2df104d73157ba02128bbe.zip |
Add functions to wipe and save plugin config data
This way all is needed is to instantiate a proper PluginObject from
any provider and just call its functions
Signed-off-by: Simo Sorce <simo@redhat.com>
Diffstat (limited to 'ipsilon')
-rwxr-xr-x | ipsilon/util/data.py | 37 | ||||
-rwxr-xr-x | ipsilon/util/plugin.py | 9 |
2 files changed, 46 insertions, 0 deletions
diff --git a/ipsilon/util/data.py b/ipsilon/util/data.py index 2a55bb2..70e7d74 100755 --- a/ipsilon/util/data.py +++ b/ipsilon/util/data.py @@ -189,6 +189,25 @@ class Store(object): if con: con.close() + def wipe_plugin_config(self, facility, plugin): + # Try to backup old data first, just in case ? + 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("DELETE FROM " + facility + " WHERE name=?", + (plugin,)) + con.commit() + except sqlite3.Error, e: + if con: + con.rollback() + cherrypy.log.error("Failed to wipe %s config: [%s]" % (plugin, e)) + raise + finally: + if con: + con.close() + def get_data(self, plugin, idval=None, name=None, value=None): con = None rows = [] @@ -276,3 +295,21 @@ class Store(object): finally: if con: con.close() + + def wipe_data(self, plugin): + # Try to backup old data first, just in case + try: + con = sqlite3.connect(self._admin_dbname) + cur = con.cursor() + cur.execute("DROP TABLE IF EXISTS " + plugin + "_data") + cur.execute("CREATE TABLE " + plugin + "_data" + "(id INTEGER, name TEXT, value TEXT)") + con.commit() + except sqlite3.Error, e: + if con: + con.rollback() + cherrypy.log.error("Failed to wipe %s data: [%s]" % (plugin, e)) + raise + finally: + if con: + con.close() diff --git a/ipsilon/util/plugin.py b/ipsilon/util/plugin.py index fce058d..9ffa131 100755 --- a/ipsilon/util/plugin.py +++ b/ipsilon/util/plugin.py @@ -144,9 +144,18 @@ class PluginObject(object): self._config = dict() self._config[option] = value + def save_plugin_config(self, facility): + self._data.save_plugin_config(facility, self.name, self._config) + def get_data(self, idval=None, name=None, value=None): return self._data.get_data(self.name, idval=idval, name=name, value=value) def save_data(self, data): self._data.save_data(self.name, data) + + def wipe_config_values(self, facility): + self._data.wipe_plugin_config(facility, self.name) + + def wipe_data(self): + self._data.wipe_data(self.name) |