Alternate row colors in html results 92/95292/6
authorAleksander Mistewicz <a.mistewicz@samsung.com>
Thu, 13 Oct 2016 13:00:36 +0000 (15:00 +0200)
committerAleksander Mistewicz <a.mistewicz@samsung.com>
Tue, 10 Jan 2017 09:48:48 +0000 (10:48 +0100)
Change-Id: Ia95bc0578628bbd2da4eaee3c07b201983f326b4
Signed-off-by: Aleksander Mistewicz <a.mistewicz@samsung.com>
tsp/scripts/publish.py

index 0577c6a..62f3232 100755 (executable)
@@ -31,19 +31,21 @@ USAGE = "%prog <db>"
 
 AGENT = "%s/%s" % (__name__, __version__)
 
+COLORS = ["#fff", "#ddd"]
+
 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):
+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>\n\
+    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\
@@ -60,15 +62,23 @@ def print_row(row):
 </td>\n\
 </tr>\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():