changeset 54:99db71455ec2

Create valid 'tsdata' test objects when populating the database.
author Daniele Nicolodi <daniele@grinta.net>
date Sat, 13 Aug 2011 20:27:24 +0200
parents ea3867a3c634
children 018599af92f5
files src/ltpdarepo/admin.py
diffstat 1 files changed, 10 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/src/ltpdarepo/admin.py	Sat Aug 13 20:27:24 2011 +0200
+++ b/src/ltpdarepo/admin.py	Sat Aug 13 20:27:24 2011 +0200
@@ -243,7 +243,7 @@
     conn = mysql.connect(host=HOSTNAME, db=database, user=USERNAME, passwd=PASSWORD, charset='utf8')
     curs = conn.cursor()
 
-    from datetime import datetime
+    from datetime import datetime, timedelta
     import uuid
     import random
     import re
@@ -251,6 +251,9 @@
     words = re.split('\W+', lorem)
     sentences = [s + '.' for s in [s.strip() for s in lorem.split('.')] if s]
 
+    t0 = datetime(1970, 1, 1, 0, 0, 0)
+    nsecs = 100
+
     for i in range(nobjs):
 
         name = random.choice(words)
@@ -259,6 +262,7 @@
         analysis = random.choice(sentences)
 
         curs.execute("""INSERT INTO objs (uuid) VALUES (%s)""", (str(uuid.uuid4())))
+        objid = curs.lastrowid
         curs.execute("""INSERT INTO objmeta (obj_id, obj_type, name, created,
                         version, ip, hostname, os, submitted,
                         experiment_title, experiment_desc, analysis_desc,
@@ -266,11 +270,13 @@
                         keywords, reference_ids, validated, vdate, author)
                         VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s,
                         %s, %s, %s, %s, %s, %s, %s, %s, %s)""",
-                     (curs.lastrowid, 'ao', name, datetime.now(),
-                      '0.1', '127.0.0.1', 'localhost', 'any', datetime.now(),
+                     (objid, 'ao', name, datetime.utcnow(),
+                      '0.1', '127.0.0.1', 'localhost', 'any', datetime.utcnow(),
                       title, description, analysis, 'FOO', '', '',
                       'testing', '', None, None, None))
-
+        curs.execute("""INSERT INTO tsdata (obj_id, fs, t0, nsecs)
+                        VALUES (%s, %s, %s, %s)""", (objid, 10, t0, nsecs))
+        t0 += timedelta(seconds=nsecs)
     conn.commit()
 
 cmd = commands.add(populate)