Author: poeml Date: Thu Jul 30 04:25:49 2009 New Revision: 64 URL: http://svn.mirrorbrain.org/viewvc/mod_asn?view=revision&revision=64 Log: asn_import script: - Now pprevents deletion of existing entries, if not at least one entry has been imported. Fixing deletion of the routing data table if the script was called with no input. Modified: trunk/asn_import.py Modified: trunk/asn_import.py ============================================================================== --- trunk/asn_import.py Tue Jul 28 20:30:10 2009 (r63) +++ trunk/asn_import.py Thu Jul 30 04:25:49 2009 (r64) _at_@ -58,10 +58,12 @@ cursor.execute("begin") cursor.execute("delete from %s" % tablename) + inserted = 0 for line in fileinput.input(): pfx, asnb, asn = line.split() try: cursor.execute("INSERT INTO %s VALUES ( %%s, %%s )" % tablename, [pfx, asn]) + inserted += 1 except psycopg2.IntegrityError, e: print e if hasattr(psycopg2, 'errorcodes'): _at_@ -75,8 +77,11 @@ raise sys.exit('insert failed for %s, %s' % (pfx, asn)) - cursor.execute("commit") - cursor.execute("vacuum analyze %s" % tablename) + if inserted > 0: + cursor.execute("commit") + cursor.execute("vacuum analyze %s" % tablename) + else: + sys.exit('nothing imported, no change comitted to the database') import_raw() _______________________________________________ mirrorbrain-commits mailing list Archive: http://mirrorbrain.org/archive/mirrorbrain-commits/ Note: To remove yourself from this list, send a mail with the content unsubscribe to the address mirrorbrain-commits-request_at_mirrorbrain.orgReceived on Thu Jul 30 2009 - 02:25:51 GMT
This archive was generated by hypermail 2.3.0 : Mon Feb 20 2012 - 23:47:04 GMT