From d711dd20ca577779493e2c7ee3cd4a592adf4b90 Mon Sep 17 00:00:00 2001 From: Tim Laszlo Date: Mon, 4 Jun 2012 16:09:00 -0500 Subject: DBStats: drop database table for ping --- src/lib/Bcfg2/Server/Reports/Updater/Routines.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'src/lib/Bcfg2/Server/Reports/Updater/Routines.py') diff --git a/src/lib/Bcfg2/Server/Reports/Updater/Routines.py b/src/lib/Bcfg2/Server/Reports/Updater/Routines.py index 1d41848e4..b500fd0a6 100644 --- a/src/lib/Bcfg2/Server/Reports/Updater/Routines.py +++ b/src/lib/Bcfg2/Server/Reports/Updater/Routines.py @@ -1,4 +1,5 @@ import logging +import traceback from django.db.models.fields import NOT_PROVIDED from django.db import connection, DatabaseError, backend, models from django.core.management.color import no_style @@ -232,6 +233,26 @@ class RemoveColumns(RebuildTable): raise UpdaterRoutineException +class DropTable(UpdaterRoutine): + """ + Drop a table + """ + def __init__(self, table_name): + self.table_name = table_name + + def __str__(self): + return "Drop table %s" % self.table_name + + def run(self): + try: + cursor = connection.cursor() + cursor.execute('DROP TABLE %s' % _quote(self.table_name)) + except DatabaseError: + logger.error("Failed to drop table: %s" % + traceback.format_exc().splitlines()[-1]) + raise UpdaterRoutineException + + class UpdaterCallable(UpdaterRoutine): """Helper for routines. Basically delays execution""" def __init__(self, fn): -- cgit v1.2.3-1-g7c22