[Collab-qa-commits] r2159 - udd/udd

Andreas Tille tille at alioth.debian.org
Sun Feb 19 12:17:55 UTC 2012


Author: tille
Date: 2012-02-19 12:17:55 +0000 (Sun, 19 Feb 2012)
New Revision: 2159

Modified:
   udd/udd/bibref_gatherer.py
Log:
Only try to import bibref table if there are really data available.  In case the input file contains zero bytes interupt without cleaning up the data table


Modified: udd/udd/bibref_gatherer.py
===================================================================
--- udd/udd/bibref_gatherer.py	2012-02-19 11:37:21 UTC (rev 2158)
+++ udd/udd/bibref_gatherer.py	2012-02-19 12:17:55 UTC (rev 2159)
@@ -21,19 +21,7 @@
   def __init__(self, connection, config, source):
     gatherer.__init__(self, connection, config, source)
     self.assert_my_config('table')
-    my_config = self.my_config
 
-    cur = self.cursor()
-    query = "DELETE FROM %s" % my_config['table']
-    cur.execute(query)
-    query = """PREPARE bibref_insert (text, text, text) AS
-                   INSERT INTO %s
-                   (package, key, value)
-                    VALUES ($1, $2, $3)""" % (my_config['table'])
-    cur.execute(query)
-
-    pkg = None
-
   def run(self):
     my_config = self.my_config
     #start harassing the DB, preparing the final inserts and making place
@@ -45,6 +33,16 @@
     result = fp.read()
     fp.close()
 
+    if not len(result) > 0:
+      print >>stderr, "BibRef input file does not contain data.  Leave table %s unchanged and stop processing here" % (my_config['table'])
+      exit(1)
+    cur.execute("TRUNCATE %s" % (my_config['table']))
+    query = """PREPARE bibref_insert (text, text, text) AS
+                   INSERT INTO %s
+                   (package, key, value)
+                    VALUES ($1, $2, $3)""" % (my_config['table'])
+    cur.execute(query)
+
     for res in safe_load_all(result):
       package, key, value = res
       value = unicode(value)




More information about the Collab-qa-commits mailing list