# HG changeset patch # User Daniele Nicolodi # Date 1313260044 -7200 # Node ID 99db71455ec2cb23d06690c148ecd9250b3966ec # Parent ea3867a3c634ce6e25a7f0757ca98c42ddaf119e Create valid 'tsdata' test objects when populating the database. diff -r ea3867a3c634 -r 99db71455ec2 src/ltpdarepo/admin.py --- 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)