From 8aa01967a4ed3dd567f0ab4ab1ca290e3d04a302 Mon Sep 17 00:00:00 2001 From: Aleksander Mistewicz Date: Thu, 13 Oct 2016 15:00:36 +0200 Subject: [PATCH] Alternate row colors in html results Change-Id: Ia95bc0578628bbd2da4eaee3c07b201983f326b4 Signed-off-by: Aleksander Mistewicz --- tsp/scripts/publish.py | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/tsp/scripts/publish.py b/tsp/scripts/publish.py index 0577c6a..62f3232 100755 --- a/tsp/scripts/publish.py +++ b/tsp/scripts/publish.py @@ -31,19 +31,21 @@ USAGE = "%prog " AGENT = "%s/%s" % (__name__, __version__) +COLORS = ["#fff", "#ddd"] + def print_head(row): template = jinja2.Template('\n\ {% for item in row %}{{ item }}\n{% endfor %}\ \n') print template.render(row=row) -def print_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('\n\ + template = jinja2.Template('\n\ {{ sr }} \n\ {% for item in row %}\ {{ item }} \n\ @@ -60,15 +62,23 @@ def print_row(row): \n\ \n') print template.render(build_nr=build_nr, sr=sr, row=[date, build_nr, target],\ - status=status, target=target) + status=status, target=target, color=color) def print_view(dbpath): + 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) testresults = conn.execute("SELECT " + ', '.join(column_names) + " FROM currentstatus;") + col = COLORS[0] + prev_sr = '' for row in testresults: - print_row(row) + sr=row[0] + if not sr == prev_sr: + prev_sr = sr + col = next_color(col) + print_row(row, col) conn.close() def parse_arguments(): -- 2.7.4