From: Thierry Parmentelat Date: Thu, 1 Dec 2011 10:59:19 +0000 (+0100) Subject: cleanup the table creation code; sfa-nuke to clear the table, not drop it X-Git-Tag: sfa-2.1-24~27^2 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=2ca98e9fe9c333b99fa7ba9f8950673d55db8a99;p=sfa.git cleanup the table creation code; sfa-nuke to clear the table, not drop it --- diff --git a/sfa/importer/sfa-import-plc.py b/sfa/importer/sfa-import-plc.py index 45945343..a9915525 100755 --- a/sfa/importer/sfa-import-plc.py +++ b/sfa/importer/sfa-import-plc.py @@ -77,8 +77,6 @@ def main(): # initialize registry db table table = SfaTable() - if not table.exists(): - table.create() # create root authority sfaImporter.create_top_level_auth_records(interface_hrn) diff --git a/sfa/importer/sfa-nuke-plc.py b/sfa/importer/sfa-nuke-plc.py index 5450a20e..bd116c88 100755 --- a/sfa/importer/sfa-nuke-plc.py +++ b/sfa/importer/sfa-nuke-plc.py @@ -28,7 +28,7 @@ def main(): sys.exit(1) logger.info("Purging SFA records from database") table = SfaTable() - table.sfa_records_purge() + table.nuke() if options.clean_certs: # remove the server certificate and all gids found in /var/lib/sfa/authorities diff --git a/sfa/storage/table.py b/sfa/storage/table.py index 3e47f3e9..acd0b3d9 100644 --- a/sfa/storage/table.py +++ b/sfa/storage/table.py @@ -28,14 +28,6 @@ class SfaTable(list): for record in records: self.append(record) - def exists(self): - sql = "SELECT * from pg_tables" - tables = self.db.selectall(sql) - tables = filter(lambda row: row['tablename'].startswith(self.SFA_TABLE_PREFIX), tables) - if tables: - return True - return False - def db_fields(self, obj=None): db_fields = self.db.fields(self.SFA_TABLE_PREFIX) @@ -55,36 +47,14 @@ class SfaTable(list): return False - def create(self): - pass -# querystr = "CREATE TABLE " + self.tablename + " ( \ -# record_id serial PRIMARY KEY , \ -# hrn text NOT NULL, \ -# authority text NOT NULL, \ -# peer_authority text, \ -# gid text, \ -# type text NOT NULL, \ -# pointer integer, \ -# date_created timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP, \ -# last_updated timestamp without time zone NOT NULL DEFAULT CURRENT_TIMESTAMP);" -# template = "CREATE INDEX %s_%s_idx ON %s (%s);" -# indexes = [template % ( self.tablename, field, self.tablename, field) \ -# for field in ['hrn', 'type', 'authority', 'peer_authority', 'pointer']] -# # IF EXISTS doenst exist in postgres < 8.2 -# try: -# self.db.do('DROP TABLE IF EXISTS ' + self.tablename) -# except: -# try: -# self.db.do('DROP TABLE' + self.tablename) -# except: -# pass -# -# self.db.do(querystr) -# for index in indexes: -# self.db.do(index) -# -# self.db.commit() - + def clear (self): + self.db.do("DELETE from %s"%self.tablename) + self.db.commit() + + # what sfa-nuke does + def nuke (self): + self.clear() + def remove(self, record): params = {'record_id': record['record_id']} template = "DELETE FROM %s " % self.tablename @@ -179,16 +149,3 @@ class SfaTable(list): return result_rec_list - def drop(self): - try: - self.db.do('DROP TABLE IF EXISTS ' + self.tablename) - self.db.commit() - except: - try: - self.db.do('DROP TABLE ' + self.tablename) - self.db.commit() - except: - pass - - def sfa_records_purge(self): - self.drop()