[Collab-qa-commits] r1616 - in udd: . sql

Lucas Nussbaum lucas at alioth.debian.org
Tue Nov 3 07:01:14 UTC 2009


Author: lucas
Date: 2009-11-03 07:01:12 +0000 (Tue, 03 Nov 2009)
New Revision: 1616

Modified:
   udd/sql/setup.sql
   udd/udd.py
Log:
apply patch to store timestamps in a table

Modified: udd/sql/setup.sql
===================================================================
--- udd/sql/setup.sql	2009-11-03 06:18:26 UTC (rev 1615)
+++ udd/sql/setup.sql	2009-11-03 07:01:12 UTC (rev 1616)
@@ -535,6 +535,16 @@
 );
 GRANT SELECT ON wannabuild TO public;
 
+-- timings of data operations
+CREATE TABLE timestamps (
+  id serial,
+  source text,
+  command text,
+  start_time timestamp,
+  end_time timestamp,
+  PRIMARY KEY (id)
+);
+GRANT SELECT ON timestamps TO public;
 
 -- views
 -- bugs_count

Modified: udd/udd.py
===================================================================
--- udd/udd.py	2009-11-03 06:18:26 UTC (rev 1615)
+++ udd/udd.py	2009-11-03 07:01:12 UTC (rev 1616)
@@ -8,7 +8,7 @@
 import string
 import sys
 from os import system
-from time import asctime
+import time
 import udd.aux
 import os.path
 
@@ -20,6 +20,23 @@
   for cmd in available_commands:
     print '  %s' % cmd
 
+def insert_timestamps(config, source, command, start_time, end_time):
+    connection = udd.aux.open_connection(config)
+    cur = connection.cursor()
+    values = { 'source' : source,
+               'command' : command,
+               'start_time' : start_time,
+               'end_time' : end_time }
+    cur.execute("""INSERT INTO timestamps
+                            (source, command, start_time, end_time)
+                     VALUES (%(source)s, %(command)s, %(start_time)s,
+                             %(end_time)s)
+                """, values)
+    connection.commit()
+
+def get_timestamp():
+    return time.strftime('%Y-%m-%d %H:%M:%S')
+
 if __name__ == '__main__':
   if len(sys.argv) < 4:
     print_help()
@@ -44,27 +61,14 @@
     try:
       # If the command is update, we need a special case. Otherwise we
       # can just use the gatherer's methods
+      start_time = get_timestamp()
       if command == 'update':
 	if "update-command" in src_config:
-	  if 'timestamp-dir' in config['general']:
-	    f = open(os.path.join(config['general']['timestamp-dir'],
-                                  src+".update-start"), "w")
-	    f.write(asctime())
-	    f.close()
 	  result = system(src_config['update-command']) 
 	  if result != 0:
 	    sys.exit(result)
-	  if 'timestamp-dir' in config['general']:
-	    f = open(os.path.join(config['general']['timestamp-dir'],
-                                  src+".update-end"), "w")
-	    f.write(asctime())
-	    f.close()
+        end_time = get_timestamp()
       else:
-	if 'timestamp-dir' in config['general']:
-	  f = open(os.path.join(config['general']['timestamp-dir'],
-                                src+".insert-start"), "w")
-	  f.write(asctime())
-	  f.close()
 	(src_command,rest) = types[type].split(None, 1)
 	if src_command == "exec":
 	  system(rest + " " + sys.argv[1] + " " + sys.argv[2] + " " + src)
@@ -83,11 +87,8 @@
 	  else:
 	    exec "gatherer.%s()" % command
 	  connection.commit()
-	if 'timestamp-dir' in config['general']:
-	  f = open(os.path.join(config['general']['timestamp-dir'],
-                                src+".insert-end"), "w")
-	  f.write(asctime())
-	  f.close()
+	end_time = get_timestamp()
+      insert_timestamps(config, src, command, start_time, end_time)
     except:
       udd.aux.unlock(config, src)
       raise




More information about the Collab-qa-commits mailing list