2009-11-01 15:21:20 +00:00
|
|
|
# ##### BEGIN GPL LICENSE BLOCK #####
|
|
|
|
#
|
|
|
|
# This program is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU General Public License
|
|
|
|
# as published by the Free Software Foundation; either version 2
|
|
|
|
# of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# This program is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
# GNU General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program; if not, write to the Free Software Foundation,
|
|
|
|
# Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
|
|
|
|
#
|
|
|
|
# ##### END GPL LICENSE BLOCK #####
|
|
|
|
|
2009-09-23 01:59:57 +00:00
|
|
|
import re
|
|
|
|
|
|
|
|
from netrender.utils import *
|
|
|
|
|
|
|
|
|
|
|
|
def get(handler):
|
|
|
|
def output(text):
|
|
|
|
handler.wfile.write(bytes(text, encoding='utf8'))
|
|
|
|
|
|
|
|
def link(text, url):
|
|
|
|
return "<a href='%s'>%s</a>" % (url, text)
|
|
|
|
|
|
|
|
def startTable(border=1):
|
|
|
|
output("<table border='%i'>" % border)
|
|
|
|
|
|
|
|
def headerTable(*headers):
|
|
|
|
output("<thead><tr>")
|
|
|
|
|
|
|
|
for c in headers:
|
|
|
|
output("<td>" + c + "</td>")
|
|
|
|
|
|
|
|
output("</tr></thead>")
|
|
|
|
|
|
|
|
def rowTable(*data):
|
|
|
|
output("<tr>")
|
|
|
|
|
|
|
|
for c in data:
|
|
|
|
output("<td>" + str(c) + "</td>")
|
|
|
|
|
|
|
|
output("</tr>")
|
|
|
|
|
|
|
|
def endTable():
|
|
|
|
output("</table>")
|
|
|
|
|
|
|
|
if handler.path == "/html" or handler.path == "/":
|
2009-10-01 18:57:22 +00:00
|
|
|
handler.send_head(content = "text/html")
|
2009-09-23 01:59:57 +00:00
|
|
|
output("<html><head><title>NetRender</title></head><body>")
|
|
|
|
|
|
|
|
output("<h2>Master</h2>")
|
|
|
|
|
|
|
|
output("<h2>Slaves</h2>")
|
|
|
|
|
|
|
|
startTable()
|
2009-09-24 19:52:32 +00:00
|
|
|
headerTable("name", "address", "last seen", "stats", "job")
|
2009-09-23 01:59:57 +00:00
|
|
|
|
|
|
|
for slave in handler.server.slaves:
|
2009-09-24 19:52:32 +00:00
|
|
|
rowTable(slave.name, slave.address[0], time.ctime(slave.last_seen), slave.stats, link(slave.job.name, "/html/job" + slave.job.id) if slave.job else "None")
|
2009-09-23 01:59:57 +00:00
|
|
|
|
|
|
|
endTable()
|
|
|
|
|
|
|
|
output("<h2>Jobs</h2>")
|
|
|
|
|
|
|
|
startTable()
|
2009-09-24 21:05:54 +00:00
|
|
|
headerTable(
|
|
|
|
"name",
|
|
|
|
"priority",
|
|
|
|
"usage",
|
|
|
|
"wait",
|
|
|
|
"length",
|
|
|
|
"done",
|
|
|
|
"dispatched",
|
|
|
|
"error",
|
|
|
|
"first",
|
|
|
|
"exception"
|
|
|
|
)
|
2009-09-23 21:46:29 +00:00
|
|
|
|
2009-09-26 16:22:52 +00:00
|
|
|
handler.server.balance()
|
2009-09-23 01:59:57 +00:00
|
|
|
|
|
|
|
for job in handler.server.jobs:
|
|
|
|
results = job.framesStatus()
|
2009-09-24 21:05:54 +00:00
|
|
|
rowTable(
|
|
|
|
link(job.name, "/html/job" + job.id),
|
|
|
|
job.priority,
|
2009-09-24 19:52:32 +00:00
|
|
|
"%0.1f%%" % (job.usage * 100),
|
2009-09-24 21:05:54 +00:00
|
|
|
"%is" % int(time.time() - job.last_dispatched),
|
2009-09-24 19:52:32 +00:00
|
|
|
len(job),
|
|
|
|
results[DONE],
|
|
|
|
results[DISPATCHED],
|
|
|
|
results[ERROR],
|
|
|
|
handler.server.balancer.applyPriorities(job), handler.server.balancer.applyExceptions(job)
|
2009-09-24 21:05:54 +00:00
|
|
|
)
|
2009-09-23 01:59:57 +00:00
|
|
|
|
|
|
|
endTable()
|
|
|
|
|
|
|
|
output("</body></html>")
|
|
|
|
|
|
|
|
elif handler.path.startswith("/html/job"):
|
2009-10-01 18:57:22 +00:00
|
|
|
handler.send_head(content = "text/html")
|
2009-09-23 01:59:57 +00:00
|
|
|
job_id = handler.path[9:]
|
|
|
|
|
|
|
|
output("<html><head><title>NetRender</title></head><body>")
|
|
|
|
|
2009-09-26 16:22:52 +00:00
|
|
|
job = handler.server.getJobID(job_id)
|
2009-09-23 01:59:57 +00:00
|
|
|
|
|
|
|
if job:
|
|
|
|
output("<h2>Frames</h2>")
|
|
|
|
|
|
|
|
startTable()
|
|
|
|
headerTable("no", "status", "render time", "slave", "log")
|
|
|
|
|
|
|
|
for frame in job.frames:
|
|
|
|
rowTable(frame.number, frame.statusText(), "%.1fs" % frame.time, frame.slave.name if frame.slave else " ", link("view log", "/html/log%s_%i" % (job_id, frame.number)) if frame.log_path else " ")
|
|
|
|
|
|
|
|
endTable()
|
|
|
|
else:
|
|
|
|
output("no such job")
|
|
|
|
|
|
|
|
output("</body></html>")
|
|
|
|
|
|
|
|
elif handler.path.startswith("/html/log"):
|
2009-10-01 18:57:22 +00:00
|
|
|
handler.send_head(content = "text/plain")
|
2009-09-23 01:59:57 +00:00
|
|
|
pattern = re.compile("([a-zA-Z0-9]+)_([0-9]+)")
|
|
|
|
|
|
|
|
match = pattern.match(handler.path[9:])
|
|
|
|
if match:
|
|
|
|
job_id = match.groups()[0]
|
|
|
|
frame_number = int(match.groups()[1])
|
|
|
|
|
2009-09-26 16:22:52 +00:00
|
|
|
job = handler.server.getJobID(job_id)
|
2009-09-23 01:59:57 +00:00
|
|
|
|
|
|
|
if job:
|
|
|
|
frame = job[frame_number]
|
|
|
|
|
|
|
|
if frame:
|
|
|
|
f = open(frame.log_path, 'rb')
|
|
|
|
|
|
|
|
shutil.copyfileobj(f, handler.wfile)
|
|
|
|
|
|
|
|
f.close()
|
|
|
|
else:
|
|
|
|
output("no such frame")
|
|
|
|
else:
|
|
|
|
output("no such job")
|
|
|
|
else:
|
|
|
|
output("malformed url")
|