aboutsummaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorsienkiew <sienkiew@d34015c8-bcbb-4646-8ac8-8ba5febf221d>2011-10-03 17:51:04 -0400
committersienkiew <sienkiew@d34015c8-bcbb-4646-8ac8-8ba5febf221d>2011-10-03 17:51:04 -0400
commit65e2418d2a82e1ae939dd402052e26ec3572c163 (patch)
treefbfd4cb8cdac54925b58e92063c23902419f9e53 /scripts
parent2f80f0b4916c1776a2d59b25b83bda81d6e623a9 (diff)
downloadsteuermann-65e2418d2a82e1ae939dd402052e26ec3572c163.tar.gz
checkpoint
git-svn-id: https://svn.stsci.edu/svn/ssb/etal/steuermann/trunk@435 d34015c8-bcbb-4646-8ac8-8ba5febf221d
Diffstat (limited to 'scripts')
-rw-r--r--scripts/smc5
-rw-r--r--scripts/smcron7
-rw-r--r--scripts/steuermann_report.cgi186
3 files changed, 184 insertions, 14 deletions
diff --git a/scripts/smc b/scripts/smc
index 3937855..0fc03f7 100644
--- a/scripts/smc
+++ b/scripts/smc
@@ -1,4 +1,7 @@
#! python
-import steuermann.run_all as run_all
+import sys
+STEUERMANN_DIR_HERE
+sys.path.insert(0, addpath)
+import steuermann.run_all as run_all
run_all.main()
diff --git a/scripts/smcron b/scripts/smcron
new file mode 100644
index 0000000..25a43b0
--- /dev/null
+++ b/scripts/smcron
@@ -0,0 +1,7 @@
+#! python
+import sys
+STEUERMANN_DIR_HERE
+sys.path.insert(0, addpath)
+
+import steuermann.run_cron as run_cron
+run_cron.main()
diff --git a/scripts/steuermann_report.cgi b/scripts/steuermann_report.cgi
index abf371b..6953b0d 100644
--- a/scripts/steuermann_report.cgi
+++ b/scripts/steuermann_report.cgi
@@ -6,6 +6,7 @@ import os
import sys
import re
import datetime
+import pandokia.text_table
STEUERMANN_DIR_HERE
@@ -18,6 +19,25 @@ cgitb.enable()
form = cgi.FieldStorage(keep_blank_values=1)
cginame = os.getenv("SCRIPT_NAME")
+permission_modify=1
+
+html_header='''Content-type: text/html
+
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
+<HTML>
+<HEAD>
+<TITLE>%(title)s</TITLE>
+</HEAD>
+<BODY>
+'''
+
+html_trailer='''
+</BODY>
+</HTML>
+'''
+
+##########
+
def sqltime(arg) :
if arg is None :
return None
@@ -36,30 +56,169 @@ def sqltime(arg) :
##########
+
+def normalize_run_name(db, name) :
+
+ if name == 'daily_latest' :
+ c = db.execute("SELECT max(run) FROM sm_runs WHERE run like 'daily_%'")
+ run, = c.fetchone()
+ return run
+
+ return name
+
+##########
# if no action specified, show the list of runs
#
-if not 'action' in form :
- print 'content-type: text/html'
- print ''
+if 'action' in form :
+ action = form['action'].value
+else :
+ action = 'index'
+
+if action == 'index' :
+ print html_header % { 'title' : 'Steuermann' }
+ print "<a href=%s?action=runs>runs</a><br>"%cginame
+ print "<a href=%s?action=crons>crons</a><br>"%cginame
+ print html_trailer
+ sys.exit(0)
+
+
+##########
+# list the runs
+
+elif action == 'crons' :
+ print html_header % { 'title' : 'Steuermann List' }
+ db = steuermann.config.open_db()
+ c = db.cursor()
+
+ c.execute("SELECT host, name, decollision, start_time, end_time, duration, status FROM sm_crons ORDER BY start_time desc")
+
+ tt = pandokia.text_table.text_table()
+ tt.set_html_table_attributes("border=1")
+ tt.define_column('host')
+ tt.define_column('name')
+ tt.define_column('start_time')
+ tt.define_column('end_time')
+ tt.define_column('duration')
+ tt.define_column('status')
+ if permission_modify :
+ tt.define_column('delete')
+
+ link="%s?action=%s&host=%s&name=%s&decol=%s"
+ for host, name, decollision, start_time, end_time, duration, status in c :
+ row = tt.get_row_count()
+ short_name = name.split('--')[0]
+ tt.set_value(row, 'host', host )
+ tt.set_value(row, 'name', text=short_name, link=link%(cginame,'cronlog',host,name,decollision) )
+ tt.set_value(row, 'start_time', start_time)
+ if end_time is None :
+ end_time = ''
+ if end_time.startswith(start_time[0:11]) :
+ tt.set_value(row, 'end_time', end_time[11:])
+ else :
+ tt.set_value(row, 'end_time', end_time)
+ tt.set_value(row, 'duration', duration)
+ tt.set_value(row, 'status', status)
+ if permission_modify :
+ tt.set_value(row, 'delete', 'arf')
+
+ print tt.get_html()
+ print html_trailer
+ sys.exit(0)
+
+elif action == 'runs' :
+ print html_header % { 'title' : 'Steuermann List' }
+ print 'sort: '
+ for x in ( 'name_asc', 'name_desc', 'time_asc', 'time_desc' ) :
+ print "<a href=%s?action=runs&order=%s>%s</a>"%(cginame,x,x)
+ print "<br><br>"
db = steuermann.config.open_db()
c = db.cursor()
- c.execute('SELECT DISTINCT run FROM sm_status ORDER BY run DESC')
- for run, in c :
- print "<a href=%s?action=status&run=%s>%s</a><br>"%(cginame, run, run)
+ order='create_time DESC'
+
+ if 'order' in form :
+ x = form['order'].value
+ if x == 'name_asc' :
+ order = 'run ASC'
+ elif x == 'name_desc' :
+ order = 'run DESC'
+ elif x == 'time_asc' :
+ order ='create_time ASC'
+ elif x == 'time_desc' :
+ order ='create_time DESC'
+
+ c.execute('SELECT DISTINCT run, create_time FROM sm_runs ORDER BY %s'%order)
+ print "<table>"
+ for run, create_time in c :
+ print "<tr>"
+ print "<td>"
+ print "<a href=%s?action=status&run=%s>%s</a>"%(cginame, run, run)
+ print "</td><td>"
+ if permission_modify :
+ print "<a href=%s?action=delete&run=%s>delete</a>"%(cginame, run)
+ print "</td>"
+ print "</tr>"
+ print "</table>"
+ print html_trailer
sys.exit(0)
-action = form['action'].value
##########
# status means show the status of a particular run
#
-if action == 'status' :
+elif action == 'delete' :
+ if permission_modify :
+ print 'content-type: text/plain\n'
+ in_run = form['run'].value
+ db = steuermann.config.open_db()
+ in_run = normalize_run_name(db,in_run)
+ c = db.cursor()
+ c1 = db.cursor()
+ print "RUN=",in_run
+ c.execute("SELECT run FROM sm_runs WHERE run LIKE ?",(in_run,))
+ for run, in c :
+ print "echo run ",run
+ filename = '%s/run/%s'%(steuermann.config.logdir,run)
+ print "rm -rf ",filename
+ c.execute("DELETE FROM sm_runs WHERE run LIKE ?",(in_run,))
+ db.commit()
+ sys.exit(0)
+
+##########
+#
+
+elif action == 'status' :
db = steuermann.config.open_db()
import steuermann.report
steuermann.report.cginame = cginame
- print 'content-type: text/html'
+ print html_header % { 'title' : 'Steuermann Status' }
print ''
run = form['run'].value
+ run = normalize_run_name(db,run)
print steuermann.report.report_html( db, run, info_callback=steuermann.report.info_callback_gui )
+ print html_trailer
+ sys.exit(0)
+
+
+elif action == 'cronlog' :
+ print 'content-type: text/plain'
+ print ''
+ host = form['host'].value
+ name = form['name'].value
+ decol = form['decol'].value
+ db = steuermann.config.open_db()
+ c = db.cursor()
+
+ c.execute("SELECT host, name, decollision, start_time, end_time, status, logfile FROM sm_crons WHERE host = ? AND name = ? and decollision = ?", (host, name, decol) )
+ for host, name, decollision, start_time, end_time, status, logfile in c :
+ print "----------"
+ print "%s: %s\n"%(host,name)
+ print "decol=%s"%decollision
+ print start_time
+ print end_time
+ print "status=",status
+ print "----------"
+ f=open(steuermann.config.logdir + '/cron/' + logfile,"r")
+ sys.stdout.write(f.read())
+ f.close()
sys.exit(0)
##########
@@ -103,7 +262,7 @@ elif action == 'log' :
for x in [ ' ' + x for x in notes.split('\n') ] :
print x
print ""
- filename = '%s/%s/%s:%s.%s.log'%(steuermann.config.logdir,run,host,table,cmd)
+ filename = '%s/run/%s/%s:%s.%s.log'%(steuermann.config.logdir,run,host,table,cmd)
try :
f=open(filename,'r')
except IOError:
@@ -124,7 +283,7 @@ elif action == 'log' :
# info means show information about the system
#
elif action == 'info' :
- print 'content-type: text/html\n'
+ print html_header % { 'title': 'Steuermann Info' }
print 'db credentials: ',steuermann.config.db_creds,'<br>'
print 'logdir: ',steuermann.config.logdir,'<br>'
db = steuermann.config.open_db()
@@ -135,11 +294,12 @@ elif action == 'info' :
cur.execute("select count(*) from sm_runs")
l = cur.fetchone()
print "runs: %s\n"%l[0],'<br>'
+ print html_trailer
sys.exit(0)
##########
-print 'content-type: text/html'
+print html_header
print ''
print 'no recognized action?'
-
+print html_trailer