summaryrefslogtreecommitdiff
path: root/tsp/scripts/publish.py
blob: b9237d14c4a79d0f5c1a82be5dd714072fad6662 (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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
#!/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
import datetime

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

USAGE = "%prog <db>"

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

COLORS = ["#fff", "#ddd"]
SCREENSHOTABLE = ["odroid", "artik5", "artik10", "artik5"]

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, color):
    sr=row[0]
    date=row[1]
    build_nr=row[2]
    target=row[3]
    status=row[4]
    template = jinja2.Template('<tr bgcolor=\'{{ color }}\'>\n\
<td> <a href=\"../dwn/{{ build_nr }}\">{{ sr }}</a> </td>\n\
{% for item in row %}\
<td> {{ item }} </td>\n\
{% endfor %}\
<td>\
 {{ status }}\
{% if status == \'OK\' or status == \'Unclear\' or status == \'Fail\' or status == \'Snapshot\' %}\
 (<a href=\"../img_test/{{ build_nr }}/sysctl.result\">smoke</a>,\
 <a href=\"../img_test/{{ build_nr }}/avocado-results/latest/html/results.html\">avocado</a>\
{% if target in screenshotable %}\
, <a href=\"../img_test/{{ build_nr }}/screenshot.png\">screenshot</a>\
{% endif %})\
{% endif %}\
</td>\n\
</tr>\n')
    print template.render(build_nr=build_nr, sr=sr, row=[date, build_nr, target],\
            status=status, target=target, color=color, screenshotable=SCREENSHOTABLE)

def print_view(dbpath, tizen3):
    def next_color(col):
        return COLORS[(COLORS.index(col) + 1) % len(COLORS)]
    conn = sqlite3.connect(dbpath)
    column_names = ["SR", "Date", "\"Build nr\"", "Device", "Status"]
    print_head(column_names)
    if tizen3:
        testresults = conn.execute("SELECT " + ', '.join(column_names) + " FROM currentstatus3;")
    else:
        testresults = conn.execute("SELECT " + ', '.join(column_names) + " FROM currentstatus;")
    col = COLORS[0]
    prev_sr = ''
    for row in testresults:
        sr=row[0]
        if not sr == prev_sr:
            prev_sr = sr
            col = next_color(col)
        m_date = datetime.datetime.strptime(row[1], "%Y-%m-%d %H:%M:%S")
        timedelta = datetime.datetime.utcnow() - m_date
        if ( row[4] == 'In test queue' or row[4] == 'Testing' or row[4] == 'Downloading' ) and timedelta < datetime.timedelta(days=2):
            if timedelta > datetime.timedelta(hours=6):
                print_row(row, "red")
                continue
            elif timedelta > datetime.timedelta(hours=2):
                print_row(row, "yellow")
                continue
        print_row(row, col)
    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')

    parser.add_argument("-3", "--tizen3",
            action="store_true", dest="tizen3",
            help='Print results for Tizen 3.0-common only')

    args = parser.parse_args()

    return args

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

if __name__ == '__main__':
    main()