summaryrefslogtreecommitdiff
path: root/tsp/scripts/publish.py
blob: 529e60321d35a2d8f2a649dd928749585c72fc55 (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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
#!/usr/bin/env python
# -*- coding: utf-8 -*-

# Copyright (c) 2016 Samsung Electronics Co., Ltd All Rights Reserved
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

##
# @author Aleksander Mistewicz <a.mistewicz@samsung.com>

import argparse
import sqlite3
import jinja2

__version__ = "0.0.2"
__license__ = "APACHE-2.0"
__author__ = "Aleksander Mistewicz"
__author_email__ = "a.mistewicz@samsung.com"

USAGE = "%prog <db>"

AGENT = "%s/%s" % (__name__, __version__)

def print_head(row):
    template = jinja2.Template('<tr>\n\
{% for item in row %}<th>{{ item }}</th>\n{% endfor %}\
</tr>\n')
    print template.render(row=row)

def print_row(row):
    build_nr=str(row[2])
    template = jinja2.Template('<tr>\n\
<td> <a href=\"../dwn/{{ build_nr }}\">{{ sr }}</a> </td>\n\
{% for item in row %}\
<td> {{ item }} </td>\n\
{% endfor %}\
<td>\
 {{ status }}\
{% if status != \'Identical\' %}\
 (<a href=\"../img_test/{{ build_nr }}/sysctl.result\">smoke</a>,\
 <a href=\"../img_test/{{ build_nr }}/avocado-results/latest/html/results.html\">avocado</a>)\
{% endif %}\
</td>\n\
</tr>\n')
    print template.render(build_nr=build_nr, sr=row[0], row=[row[1], build_nr, row[3]], status=row[4])

def print_view(dbpath):
    conn = sqlite3.connect(dbpath)
    column_names = ["SR", "Date", "\"Build nr\"", "Device", "Status"]
    print_head(column_names)
    testresults = conn.execute("SELECT " + ', '.join(column_names) + " FROM currentstatus;")
    for row in testresults:
        print_row(row)
    conn.close()

def parse_arguments():
    parser = argparse.ArgumentParser(description="HTML view generatator for results.db3")

    parser.add_argument("db3", metavar='<db>', type=str,
            help='database path')

    args = parser.parse_args()

    return args

def main():
    args = parse_arguments()
    if args.db3:
        print_view(args.db3)

if __name__ == '__main__':
    main()