diff options
author | sienkiew <sienkiew@d34015c8-bcbb-4646-8ac8-8ba5febf221d> | 2011-08-31 17:50:22 -0400 |
---|---|---|
committer | sienkiew <sienkiew@d34015c8-bcbb-4646-8ac8-8ba5febf221d> | 2011-08-31 17:50:22 -0400 |
commit | c7651f9727404b1ac6da1714aaeee7d55fe08222 (patch) | |
tree | dc49c3450fa91673e7f7b5b98584af93981e2327 /steuermann/report.py | |
parent | 7adeddaa0f345149d9747596fff9573197c65b10 (diff) | |
download | steuermann-c7651f9727404b1ac6da1714aaeee7d55fe08222.tar.gz |
checkpoint
git-svn-id: https://svn.stsci.edu/svn/ssb/etal/steuermann/trunk@389 d34015c8-bcbb-4646-8ac8-8ba5febf221d
Diffstat (limited to 'steuermann/report.py')
-rw-r--r-- | steuermann/report.py | 81 |
1 files changed, 70 insertions, 11 deletions
diff --git a/steuermann/report.py b/steuermann/report.py index e1df5ce..e1d2971 100644 --- a/steuermann/report.py +++ b/steuermann/report.py @@ -5,10 +5,58 @@ Generate reports from the database import time import sys -import sqlite3 import pandokia.text_table as text_table import StringIO +# this will be reset by the cgi main program if we are in a real cgi +cginame = 'arf.cgi' + +# + +def info_callback_status( db, run, tablename, host, cmd ) : + c = db.cursor() + c.execute("SELECT status FROM status WHERE run = ? AND host = ? AND tablename = ? AND cmd = ?",( + run, host, tablename, cmd ) ) + status, = c.fetchone() + return status + +# + +def info_callback_gui( db, run, tablename, host, cmd ) : + c = db.cursor() + c.execute("SELECT status, start_time, end_time FROM status WHERE run = ? AND host = ? AND tablename = ? AND cmd = ?",( + run, host, tablename, cmd ) ) + x = c.fetchone() + if x is None : + return '' + status, start_time, end_time = x + if start_time is None : + start_time = '' + if end_time is None : + end_time = '' + + # t_result = '%s %s %s'%(status, start_time, end_time ) + t_result = status + + if status != '0' and status != 'N' : + status = '<font color=red>%s</font>'%status + + if status != 'N' and status != 'P' : + link = "<a href='%s?action=log&name=%s/%s:%s/%s'>*</a>"%(cginame, run, host, tablename, cmd ) + else : + link = '' + + # h_result = '%s %s %s %s'%(link, status, start_time, end_time) + h_result = '%s %s'%(link, status ) + + return ( t_result, h_result ) + +# + +def info_callback_debug_table_cell( db, run, tablename, cmd, host ) : + return '%s %s %s %s' % ( run, host, tablename, cmd ) + +# def get_table_list( db, run_name ) : c = db.cursor() @@ -17,39 +65,46 @@ def get_table_list( db, run_name ) : # table_list contains ( depth, tablename ) return table_list -def get_table( db, run_name, tablename, info_callback ) : +def get_table( db, run_name, tablename, info_callback, showdepth=0 ) : t = text_table.text_table() + t.set_html_table_attributes('border=1') - row = 0 - t.define_column('-') # the command name in column 0 + t.define_column('-',html=' ',showname='-') # the command name in column 0 + + if showdepth : + t.define_column('depth') c = db.cursor() c.execute("select distinct host from status where tablename = ? and run = ? order by host asc",(tablename, run_name)) for host, in c : t.define_column(host) - t.set_value(row, host, host) - c.execute("""select cmd, host, depth, status, start_time, end_time, notes from status where tablename = ? and run = ? order by depth, cmd asc """, ( tablename, run_name ) ) + row = -1 prev_cmd = None for x in c : cmd, host, depth, status, start_time, end_time, notes = x if cmd != prev_cmd : row = row + 1 t.set_value(row, 0, cmd) + t.set_value(row, 'depth', depth) prev_cmd = cmd - t.set_value( row, host, info_callback( tablename, cmd, host, status ) ) + + info = info_callback( db, run_name, tablename, host, cmd ) + if isinstance(info, tuple) : + t.set_value( row, host, text=info[0], html=info[1] ) + else : + t.set_value( row, host, info) t.pad() return t -def info_callback_status( tablename, cmd, host, status ) : - return status +# def report_text( db, run_name, info_callback = info_callback_status ) : @@ -68,6 +123,8 @@ def report_text( db, run_name, info_callback = info_callback_status ) : return s.getvalue() +# + def report_html( db, run_name, info_callback = info_callback_status, hlevel=1 ) : s = StringIO.StringIO() s.write('<h%d>%s</h%d>\n'%(hlevel,run_name,hlevel)) @@ -78,13 +135,15 @@ def report_html( db, run_name, info_callback = info_callback_status, hlevel=1 ) for depth, tablename in table_list : s.write('<h%d>%s</h%d>\n'%(hlevel,tablename,hlevel)) - t = get_table( db, run_name, tablename, info_callback ) + t = get_table( db, run_name, tablename, info_callback, showdepth=1 ) s.write(t.get_html()) return s.getvalue() +# def main() : - db = sqlite3.connect('sr.db') + import steuermann.config + db = steuermann.config.open_db() print report_html( db, 'arf2011-08-30 16:52:23.928381' ) if __name__ == '__main__' : |