diff options
author | Simo Sorce <simo@redhat.com> | 2014-09-25 15:59:07 -0400 |
---|---|---|
committer | Patrick Uiterwijk <puiterwijk@redhat.com> | 2014-10-06 20:25:14 +0200 |
commit | fec439b3d8d3d636388fa4a72bb48adfe51520f2 (patch) | |
tree | 53b613a20bcdbc73b93f6394d42b53f1b199987c /ipsilon/util/data.py | |
parent | cc0237a0ada6b6c2ec74d698391f47a38dee59a9 (diff) | |
download | ipsilon.git-fec439b3d8d3d636388fa4a72bb48adfe51520f2.tar.gz ipsilon.git-fec439b3d8d3d636388fa4a72bb48adfe51520f2.tar.xz ipsilon.git-fec439b3d8d3d636388fa4a72bb48adfe51520f2.zip |
Move wipe_data into Store() as reset_data
Signed-off-by: Simo Sorce <simo@redhat.com>
Reviewed-by: Patrick Uiterwijk <puiterwijk@redhat.com>
Diffstat (limited to 'ipsilon/util/data.py')
-rwxr-xr-x | ipsilon/util/data.py | 34 |
1 files changed, 19 insertions, 15 deletions
diff --git a/ipsilon/util/data.py b/ipsilon/util/data.py index 1f34860..e6bca10 100755 --- a/ipsilon/util/data.py +++ b/ipsilon/util/data.py @@ -66,6 +66,9 @@ class Store(Log): create = CREATE % {'table': table, 'cols': cols} cursor.execute(create) + def _drop(self, cursor, table): + cursor.execute("DROP TABLE IF EXISTS " + table) + def _update(self, cursor, table, values, kvfilter): UPDATE = "UPDATE %(table)s SET %(setval)s %(where)s" kv = dict() @@ -285,6 +288,21 @@ class Store(Log): if con: con.close() + def reset_data(self, table): + try: + con = sqlite3.connect(self._dbname) + cur = con.cursor() + self._drop(cur, table) + self._create(cur, table, UNIQUE_DATA_COLUMNS) + con.commit() + except sqlite3.Error, e: + if con: + con.rollback() + self.error("Failed to erase all data from %s: [%s]" % (table, e)) + finally: + if con: + con.close() + class AdminStore(Store): @@ -307,21 +325,7 @@ class AdminStore(Store): def wipe_data(self, plugin): table = plugin+"_data" - # Try to backup old data first, just in case - try: - con = sqlite3.connect(self._dbname) - cur = con.cursor() - cur.execute("DROP TABLE IF EXISTS " + table) - self._create(cur, table, UNIQUE_DATA_COLUMNS) - 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() + self.reset_data(table) class UserStore(Store): |