From 2bb986132e429b57104dc9cf4949d6e38f8fc053 Mon Sep 17 00:00:00 2001 From: Martin Poirier Date: Tue, 22 Mar 2011 01:42:06 +0000 Subject: Moving netrender to addons --- netrender/master_html.py | 315 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 315 insertions(+) create mode 100644 netrender/master_html.py (limited to 'netrender/master_html.py') diff --git a/netrender/master_html.py b/netrender/master_html.py new file mode 100644 index 00000000..87727320 --- /dev/null +++ b/netrender/master_html.py @@ -0,0 +1,315 @@ +# ##### 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. +# +# ##### END GPL LICENSE BLOCK ##### + +import os +import re +import shutil +from netrender.utils import * +import netrender.model + +src_folder = os.path.split(__file__)[0] + +def get(handler): + def output(text): + handler.wfile.write(bytes(text, encoding='utf8')) + + def head(title, refresh = False): + output("") + if refresh: + output("") + output("") +# output("") + output("") + output(title) + output("") + output("") + + + def link(text, url, script=""): + return "%s" % (url, script, text) + + def tag(name, text, attr=""): + return "<%s %s>%s" % (name, attr, text, name) + + def startTable(border=1, class_style = None, caption = None): + output("") + + if caption: + output("" % caption) + + def headerTable(*headers): + output("") + + for c in headers: + output("") + + output("") + + def rowTable(*data, id = None, class_style = None, extra = None): + output("") + + for c in data: + output("") + + output("") + + def endTable(): + output("
%s
" + c + "
" + str(c) + "
") + + def checkbox(title, value, script=""): + return """""" % (title, "checked" if value else "", ("onclick=\"%s\"" % script) if script else "") + + if handler.path == "/html/netrender.js": + f = open(os.path.join(src_folder, "netrender.js"), 'rb') + + handler.send_head(content = "text/javascript") + shutil.copyfileobj(f, handler.wfile) + + f.close() + elif handler.path == "/html/netrender.css": + f = open(os.path.join(src_folder, "netrender.css"), 'rb') + + handler.send_head(content = "text/css") + shutil.copyfileobj(f, handler.wfile) + + f.close() + elif handler.path == "/html" or handler.path == "/": + handler.send_head(content = "text/html") + head("NetRender", refresh = True) + + output("

Jobs

") + + startTable() + headerTable( + " ", + "id", + "name", + "category", + "type", + "chunks", + "priority", + "usage", + "wait", + "status", + "length", + "done", + "dispatched", + "error", + "priority", + "exception" + ) + + handler.server.balance() + + for job in handler.server.jobs: + results = job.framesStatus() + rowTable( + """""" % job.id + + """""" % job.id + + """""" % job.id, + job.id, + link(job.name, "/html/job" + job.id), + job.category if job.category else "None", + netrender.model.JOB_TYPES[job.type], + str(job.chunks) + + """""" % (job.id, job.chunks + 1) + + """""" % (job.id, job.chunks - 1, "disabled=True" if job.chunks == 1 else ""), + str(job.priority) + + """""" % (job.id, job.priority + 1) + + """""" % (job.id, job.priority - 1, "disabled=True" if job.priority == 1 else ""), + "%0.1f%%" % (job.usage * 100), + "%is" % int(time.time() - job.last_dispatched), + job.statusText(), + len(job), + results[DONE], + results[DISPATCHED], + str(results[ERROR]) + + """""" % (job.id, "disabled=True" if not results[ERROR] else ""), + "yes" if handler.server.balancer.applyPriorities(job) else "no", + "yes" if handler.server.balancer.applyExceptions(job) else "no" + ) + + endTable() + + output("

Slaves

") + + startTable() + headerTable("name", "address", "last seen", "stats", "job") + + for slave in handler.server.slaves: + 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") + + endTable() + + output("

Configuration

") + + output("""""") + + startTable(caption = "Rules", class_style = "rules") + + headerTable("type", "enabled", "description", "limit") + + for rule in handler.server.balancer.rules: + rowTable( + "rating", + checkbox("", rule.enabled, "balance_enable('%s', '%s')" % (rule.id(), str(not rule.enabled).lower())), + rule, + rule.str_limit() + + """""" % (rule.id(), str(rule.limit)) if hasattr(rule, "limit") else " " + ) + + for rule in handler.server.balancer.priorities: + rowTable( + "priority", + checkbox("", rule.enabled, "balance_enable('%s', '%s')" % (rule.id(), str(not rule.enabled).lower())), + rule, + rule.str_limit() + + """""" % (rule.id(), str(rule.limit)) if hasattr(rule, "limit") else " " + ) + + for rule in handler.server.balancer.exceptions: + rowTable( + "exception", + checkbox("", rule.enabled, "balance_enable('%s', '%s')" % (rule.id(), str(not rule.enabled).lower())), + rule, + rule.str_limit() + + """""" % (rule.id(), str(rule.limit)) if hasattr(rule, "limit") else " " + ) + + endTable() + + output("") + + elif handler.path.startswith("/html/job"): + handler.send_head(content = "text/html") + job_id = handler.path[9:] + + head("NetRender") + + job = handler.server.getJobID(job_id) + + if job: + output("

Render Information

") + + job.initInfo() + + startTable() + + rowTable("resolution", "%ix%i at %i%%" % job.resolution) + + endTable() + + + if job.type == netrender.model.JOB_BLENDER: + output("

Files

") + + startTable() + headerTable("path") + + tot_cache = 0 + tot_fluid = 0 + + rowTable(job.files[0].filepath) + rowTable("Other Files", class_style = "toggle", extra = "onclick='toggleDisplay(".other", "none", "table-row")'") + + for file in job.files: + if file.filepath.endswith(".bphys"): + tot_cache += 1 + elif file.filepath.endswith(".bobj.gz") or file.filepath.endswith(".bvel.gz"): + tot_fluid += 1 + else: + if file != job.files[0]: + rowTable(file.filepath, class_style = "other") + + if tot_cache > 0: + rowTable("%i physic cache files" % tot_cache, class_style = "toggle", extra = "onclick='toggleDisplay(".cache", "none", "table-row")'") + for file in job.files: + if file.filepath.endswith(".bphys"): + rowTable(os.path.split(file.filepath)[1], class_style = "cache") + + if tot_fluid > 0: + rowTable("%i fluid bake files" % tot_fluid, class_style = "toggle", extra = "onclick='toggleDisplay(".fluid", "none", "table-row")'") + for file in job.files: + if file.filepath.endswith(".bobj.gz") or file.filepath.endswith(".bvel.gz"): + rowTable(os.path.split(file.filepath)[1], class_style = "fluid") + + endTable() + elif job.type == netrender.model.JOB_VCS: + output("

Versioning

") + + startTable() + + rowTable("System", job.version_info.system.name) + rowTable("Remote Path", job.version_info.rpath) + rowTable("Working Path", job.version_info.wpath) + rowTable("Revision", job.version_info.revision) + rowTable("Render File", job.files[0].filepath) + + endTable() + + if job.blacklist: + output("

Blacklist

") + + startTable() + headerTable("name", "address") + + for slave_id in job.blacklist: + slave = handler.server.slaves_map[slave_id] + rowTable(slave.name, slave.address[0]) + + endTable() + + output("

Frames

") + + startTable() + headerTable("no", "status", "render time", "slave", "log", "result", "") + + for frame in job.frames: + rowTable( + frame.number, + frame.statusText(), + "%.1fs" % frame.time, + frame.slave.name if frame.slave else " ", + link("view log", logURL(job_id, frame.number)) if frame.log_path else " ", + link("view result", renderURL(job_id, frame.number)) + " [" + + tag("span", "show", attr="class='thumb' onclick='showThumb(%s, %i)'" % (job.id, frame.number)) + "]" if frame.status == DONE else " ", + "" % (frame.number, job.id, frame.number) + ) + + endTable() + else: + output("no such job") + + output("") + -- cgit v1.2.3