From 25dc8e1226eeb7add5fd668ea1679af2c23b6189 Mon Sep 17 00:00:00 2001 From: Ben Kurtovic Date: Sat, 28 Jan 2012 18:50:36 -0500 Subject: [PATCH] EarwigBot Status page, minor CSS cleanup. --- pages/earwigbot.mako | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++++ static/css/main.css | 16 +++++++++++++--- static/js/potd.js | 3 +++ 3 files changed, 69 insertions(+), 3 deletions(-) diff --git a/pages/earwigbot.mako b/pages/earwigbot.mako index 911199d..239b851 100644 --- a/pages/earwigbot.mako +++ b/pages/earwigbot.mako @@ -1,2 +1,55 @@ +<%! + from datetime import datetime + import os + import re + from shlex import split + from subprocess import check_output, CalledProcessError, STDOUT + + os.environ["SGE_ROOT"] = "/sge62" + + def format_date(d): + start = datetime.strptime(d, "%a %b %d %H:%M:%S %Y") + since = start.strftime("%b %d, %Y at %H:%M:%S UTC") + diff = (datetime.utcnow() - start) + if diff.days: + uptime = "{0} days".format(diff.days) + if diff.seconds >= 3600: + uptime += ", {0} hours".format(diff.seconds / 3600) + else: + if diff.seconds > 3600: + uptime = "{0} hours".format(diff.seconds / 3600) + elif diff.seconds > 60: + uptime = "{0} minutes".format(diff.seconds / 60) + else: + uptime = "{0} seconds".format(diff.seconds) + return (since, uptime) + + def collect_status_info(): + try: + result = check_output(["qstat", "-j", "earwigbot"], stderr=STDOUT) + except CalledProcessError as e: + return ["offline"] + + if result.startswith("Following jobs do not exist:"): + return ["offline"] + + lines = result.splitlines()[1:] + re_key = "^(.*?):\s" + re_val = ":\s*(.*?)$" + data = dict((re.search(re_key, line).group(1), re.search(re_val, line).group(1)) for line in lines) + since, uptime = format_date(data["submission_time"]) + host = data["sge_o_host"] + return ["online", since, uptime, host] +%>\ +<%def name="get_status()" filter="trim"> + <% status, since, uptime, host = collect_status_info() %> + ${status} + % if status == "online": + since ${since} (${uptime} uptime) on ${host} + % endif +\ <%include file="/support/header.mako" args="environ=environ, title='EarwigBot Status'"/> +

EarwigBot Status

+

EarwigBot is ${get_status()}.

+

Additional information: status.toolserver.org

<%include file="/support/footer.mako" args="environ=environ"/> diff --git a/static/css/main.css b/static/css/main.css index 331f91c..507fe81 100644 --- a/static/css/main.css +++ b/static/css/main.css @@ -2,8 +2,8 @@ body { font-family: helvetica, arial, clean, sans-serif; font-size: 14px; color: #000; - /*background-color: #E0E0E0;*/ background-color: #000; + margin: 0; } ul, ol { @@ -11,7 +11,7 @@ ul, ol { } div#header { - margin: 20px; + margin: 30px 60px 30px 60px; padding: 2px 15px 2px 15px; border: 1px solid #777; background-color: #FFF; @@ -19,7 +19,7 @@ div#header { div#container { line-height: 1.5; - margin: 0 20px 90px 20px; + margin: 0 60px 100px 60px; padding: 2px 15px 2px 15px; border: 1px solid #777; background-color: #FFF; @@ -81,6 +81,16 @@ p.tooldesc { margin: 6px 0 6px 0; } +span.offline { + color: #900; + font-weight: bold; +} + +span.online { + color: #090; + font-weight: bold; +} + span.light { color: #CCC; } span.medium { color: #AAA; } diff --git a/static/js/potd.js b/static/js/potd.js index b6b24d0..dbaaf0c 100644 --- a/static/js/potd.js +++ b/static/js/potd.js @@ -65,6 +65,9 @@ function parse_file_url(data, filename) { if (imgwidth/imgheight > winwidth/winheight) { width = Math.round((imgwidth/imgheight) * winheight); } + if (width > imgwidth) { + width = imgwidth; + } url += "/" + width + "px-" + filename; document.body.style.backgroundImage="url('" + url + "')";