Newer
Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
# ##### 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 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("<html><head>")
if refresh:
output("<meta http-equiv='refresh' content=5>")
output("<script src='/html/netrender.js' type='text/javascript'></script>")
# output("<script src='/html/json2.js' type='text/javascript'></script>")
output("<title>")
output(title)
output("</title></head><body>")
output("<link rel='stylesheet' href='/html/netrender.css' type='text/css'>")
def link(text, url, script=""):
return "<a href='%s' %s>%s</a>" % (url, script, text)
def tag(name, text, attr=""):
return "<%s %s>%s</%s>" % (name, attr, text, name)
def startTable(border=1, class_style = None, caption = None):
output("<table border='%i'" % border)
if class_style:
output(" class='%s'" % class_style)
output(">")
if caption:
output("<caption>%s</caption>" % caption)
def headerTable(*headers):
output("<thead><tr>")
for c in headers:
output("<td>" + c + "</td>")
output("</tr></thead>")
def rowTable(*data, id = None, class_style = None, extra = None):
output("<tr")
if id:
output(" id='%s'" % id)
if class_style:
output(" class='%s'" % class_style)
if extra:
output(" %s" % extra)
output(">")
for c in data:
output("<td>" + str(c) + "</td>")
output("</tr>")
def endTable():
output("</table>")
def checkbox(title, value, script=""):
return """<input type="checkbox" title="%s" %s %s>""" % (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("<h2>Jobs</h2>")
startTable()
headerTable(
" ",
"id",
"name",
"category",
"type",
"chunks",
"priority",
"usage",
"wait",
"status",
"done",
"dispatched",
"error",
"priority",
"exception"
)
handler.server.balance()
for job in handler.server.jobs:
results = job.framesStatus()
rowTable(
"""<button title="cancel job" onclick="cancel_job('%s');">X</button>""" % job.id +
"""<button title="pause job" onclick="request('/pause_%s', null);">P</button>""" % job.id +
"""<button title="reset all frames" onclick="request('/resetall_%s_0', null);">R</button>""" % job.id,
job.id,
link(job.name, "/html/job" + job.id),
job.category if job.category else "<i>None</i>",
";".join(sorted(job.tags)) if job.tags else "<i>None</i>",
"%s [%s]" % (netrender.model.JOB_TYPES[job.type], netrender.model.JOB_SUBTYPES[job.subtype]),
str(job.chunks) +
"""<button title="increase chunks size" onclick="request('/edit_%s', "{'chunks': %i}");">+</button>""" % (job.id, job.chunks + 1) +
"""<button title="decrease chunks size" onclick="request('/edit_%s', "{'chunks': %i}");" %s>-</button>""" % (job.id, job.chunks - 1, "disabled=True" if job.chunks == 1 else ""),
str(job.priority) +
"""<button title="increase priority" onclick="request('/edit_%s', "{'priority': %i}");">+</button>""" % (job.id, job.priority + 1) +
"""<button title="decrease priority" onclick="request('/edit_%s', "{'priority': %i}");" %s>-</button>""" % (job.id, job.priority - 1, "disabled=True" if job.priority == 1 else ""),
"%0.1f%%" % (job.usage * 100),
"%is" % int(time.time() - job.last_dispatched) if job.status != JOB_FINISHED else "N/A",
results[FRAME_DONE],
results[FRAME_DISPATCHED],
str(results[FRAME_ERROR]) +
"""<button title="reset error frames" onclick="request('/reset_%s_0', null);" %s>R</button>""" % (job.id, "disabled=True" if not results[FRAME_ERROR] else ""),
"yes" if handler.server.balancer.applyPriorities(job) else "no",
"yes" if handler.server.balancer.applyExceptions(job) else "no"
)
endTable()
output("<h2>Slaves</h2>")
startTable()
headerTable("name", "address", "tags", "last seen", "stats", "job")
rowTable(slave.name, slave.address[0], ";".join(sorted(slave.tags)) if slave.tags else "<i>All</i>", time.ctime(slave.last_seen), slave.stats, link(slave.job.name, "/html/job" + slave.job.id) if slave.job else "None")
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
endTable()
output("<h2>Configuration</h2>")
output("""<button title="remove all jobs" onclick="clear_jobs();">CLEAR JOB LIST</button>""")
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() +
"""<button title="edit limit" onclick="balance_edit('%s', '%s');">edit</button>""" % (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() +
"""<button title="edit limit" onclick="balance_edit('%s', '%s');">edit</button>""" % (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() +
"""<button title="edit limit" onclick="balance_edit('%s', '%s');">edit</button>""" % (rule.id(), str(rule.limit)) if hasattr(rule, "limit") else " "
)
endTable()
output("</body></html>")
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:
job.initInfo()
startTable()
rowTable("resolution", "%ix%i at %i%%" % job.resolution)
rowTable("tags", ";".join(sorted(job.tags)) if job.tags else "<i>None</i>")
rowTable("results", link("download all", resultURL(job_id)))
endTable()
if job.type == netrender.model.JOB_BLENDER:
output("<h2>Files</h2>")
startTable()
headerTable("path")
tot_cache = 0
tot_fluid = 0
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
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")
if tot_other > 0:
rowTable("%i other files" % tot_other, class_style = "toggle", extra = "onclick='toggleDisplay(".other", "none", "table-row")'")
for file in job.files:
if (
not file.filepath.endswith(".bphys")
and not file.filepath.endswith(".bobj.gz") or file.filepath.endswith(".bvel.gz")
and not file == job.files[0]
):
rowTable(file.filepath, class_style = "other")
endTable()
elif job.type == netrender.model.JOB_VCS:
output("<h2>Versioning</h2>")
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("<h2>Blacklist</h2>")
startTable()
headerTable("name", "address")
for slave_id in job.blacklist:
slave = handler.server.slaves_map.get(slave_id, None)
if slave:
rowTable(slave.name, slave.address[0])
endTable()
output("<h2>Frames</h2>")
startTable()
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
if job.hasRenderResult():
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 == FRAME_DONE else " ",
"<img name='thumb%i' title='hide thumbnails' src='' class='thumb' onclick='showThumb(%s, %i)'>" % (frame.number, job.id, frame.number)
)
else:
headerTable("no", "status", "process 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", logURL(job_id, frame.number)) if frame.log_path else " "
)
endTable()
else:
output("no such job")