From fec439b3d8d3d636388fa4a72bb48adfe51520f2 Mon Sep 17 00:00:00 2001 From: Simo Sorce Date: Thu, 25 Sep 2014 15:59:07 -0400 Subject: [PATCH] Move wipe_data into Store() as reset_data Signed-off-by: Simo Sorce Reviewed-by: Patrick Uiterwijk --- ipsilon/util/data.py | 34 +++++++++++++++++++--------------- 1 file 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): -- 2.20.1