summaryrefslogtreecommitdiffstats
path: root/database/scripts/updatetestcaseids.py
blob: d11cb80746a00b3db4cfab1d4854a8eecf1cd8d7 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#!/usr/bin/env python

"""
This script updates the testCaseId attribute of all rows in the benchmark table.
"""

import sys
from dbaccess import setDatabase, execQuery, commit
from misc import findOrInsertId, getOptions, benchmarkToComponents

# --- BEGIN Global functions ----------------------------------------------
def printUsage():
    sys.stderr.write(
        "usage: " + sys.argv[0] + " [--dbhost H] [--dbport P] --db D\n")
# --- END Global functions ----------------------------------------------


# --- BEGIN Main program ----------------------------------------------

options, http_get = getOptions()

if not ("db" in options):
    printUsage()
    sys.exit(1)

setDatabase(
    options["dbhost"] if "dbhost" in options else None,
    options["dbport"] if "dbport" in options else None,
    options["db"])

for benchmark_id, benchmark in execQuery(
    "SELECT id, value FROM benchmark;", ()):

    test_case, test_function, data_tag = (
        benchmarkToComponents(benchmark))
    test_case_id = findOrInsertId("testCase", test_case)

    execQuery(
        "UPDATE benchmark"
        " SET testCaseId = %s"
        " WHERE id = %s", (test_case_id, benchmark_id), False)

commit()

# --- END Main program ----------------------------------------------