if triggered:
print("chooser[%s] - WE ARE TRIGGERED." % utils.timestamp())
- if page != page_history[0] or (swap_page_target - now < 10.0):
+ if page != page_history[0] or (swap_page_target - now) < 10.0:
print(
"chooser[%s] - EMERGENCY PAGE %s LOAD NEEDED"
% (utils.timestamp(), page)
)
- try:
- with open(os.path.join(constants.pages_dir, "current.shtml"), "w") as f:
- emit_wrapped(f, page, override_refresh_sec = 40, command = command)
- page_history.insert(0, page)
- page_history = page_history[0:10]
- swap_page_target = now + 40
- except:
- print("chooser[%s] - page does not exist?!" % (utils.timestamp()))
- continue
+# try:
+ current = os.path.join(constants.pages_dir, "current.shtml")
+ with open(current, "w") as f:
+ emit_wrapped(f, page, override_refresh_sec = 40, command = command)
+ print(f'Wrote {current}')
+
+ page_history.insert(0, page)
+ page_history = page_history[0:10]
+ swap_page_target = now + 40
+# except:
+# print("chooser[%s] - page does not exist?!" % (utils.timestamp()))
+# continue
# Also notify XMLHTTP clients that they need to refresh now.
- path = os.path.join(constants.pages_dir, "reload_immediately.html")
- with open(path, "w") as f:
- f.write("Reload, suckers!")
+ emergency_file = os.path.join(constants.pages_dir, "reload_immediately.html")
+ with open(emergency_file, "w") as f:
+ f.write(f'Reload, suckers... you HAVE to see {page}!')
+ print(f'Causing immediate page reload with {emergency_file}...')
# Fix this hack... maybe read the webserver logs and see if it
# actually was picked up?
- time.sleep(0.75)
- os.remove(path)
+ time.sleep(3.0)
+ os.remove(emergency_file)
+ print(f'...and removed {emergency_file}')
elif now >= swap_page_target:
assert page != page_history[0]
print("chooser[%s] - nominal choice of %s" % (utils.timestamp(), page))
- try:
- with open(os.path.join(constants.pages_dir, "current.shtml"), "w") as f:
- emit_wrapped(f, page)
- page_history.insert(0, page)
- page_history = page_history[0:10]
- swap_page_target = now + constants.refresh_period_sec
- except:
- print("chooser[%s] - page does not exist?!" % (utils.timestamp()))
- continue
+# try:
+ with open(os.path.join(constants.pages_dir, "current.shtml"), "w") as f:
+ emit_wrapped(f, page)
+ page_history.insert(0, page)
+ page_history = page_history[0:10]
+ swap_page_target = now + constants.refresh_period_sec
+# except:
+# print("chooser[%s] - page does not exist?!" % (utils.timestamp()))
+# continue
time.sleep(1)
pageid = f'"{command}" -> {filename}'
f.write(
- """
+"""
<HEAD>
<TITLE>Kitchen Kiosk</TITLE>
<LINK rel="stylesheet" type="text/css" href="style.css">
function zoomScreen() {
z = 285;
do {
- document.getElementById("content").style.zoom = z+"%%";
+ document.getElementById("content").style.zoom = z+"%";
var body = document.body;
var html = document.documentElement;
var height = Math.max(body.scrollHeight,
}
}
}
-
+""")
+ f.write(
+"""
// Operate the clock at the top of the page.
function runClock() {
var today = new Date();
document.getElementById("date").innerHTML = today.toDateString();
var t = setTimeout(function(){runClock()}, 1000);
}
-
+""" % bgcolor)
+ f.write(
+"""
// Helper method for running the clock.
function maybeAddZero(x) {
return (x < 10) ? "0" + x : x;
addLoadEvent(zoomScreen);
addLoadEvent(runClock);
addLoadEvent(lateLoadImages);
+""")
+ f.write(
+"""
// Runs the countdown line at the bottom and is responsible for
// normal page reloads caused by the expiration of a timer.
(function countdown() {
});
}, 50)
})();
-
+""" % get_refresh_period())
+ f.write(
+"""
// Periodically checks for emergency reload events.
(function poll() {
setTimeout(
function() {
var xhr = new XMLHttpRequest();
xhr.open('GET',
- 'http://%s/kiosk/pages/reload_immediately.html');
+ '%s/reload_immediately.html');
xhr.onload =
function() {
if (xhr.status === 200) {
xhr.send();
}, 500);
})();
-</SCRIPT>
+ </SCRIPT>
</HEAD>
-<BODY BGCOLOR="#%s">
- <TABLE style="height:100%%; width:100%%" BORDER=0>
+""" % constants.root_url)
+ f.write(f'<BODY BGCOLOR="#{bgcolor}">')
+ f.write(
+"""
+ <TABLE style="height:100%; width:100%" BORDER=0>
<TR HEIGHT=30>
<TD ALIGN="left">
<DIV id="date"> </DIV>
<TD COLSPAN=3>
<DIV ID="content" STYLE="zoom: 1; visibility: hidden;">
<!-- BEGIN main page contents. -->
-<!--#include virtual=\"%s\"-->
- <!-- END main page contents. -->
+""")
+ f.write(f'<!--#include virtual="{filename}"-->')
+ f.write(
+"""
+ <!-- END main page contents. -->
</DIV>
<BR>
- <DIV STYLE="position: absolute; top:1030px; width:99%%">
+ <DIV STYLE="position: absolute; top:1030px; width:99%">
<P ALIGN="right">
- <FONT SIZE=2 COLOR=#bbbbbb>%s @ %s ago.</FONT>
+""")
+ f.write(f'<FONT SIZE=2 COLOR=#bbbbbb>{pageid} @ {age} ago.</FONT>')
+ f.write(
+"""
</P>
<HR id="countdown" STYLE="width:0px;
text-align:left;
</TD>
</TR>
</TABLE>
-</BODY>"""
- % (
- bgcolor,
- get_refresh_period(),
- constants.hostname,
- bgcolor,
- filename,
- pageid,
- age,
- )
- )
+</BODY>""")
def thread_invoke_renderers() -> None:
with file_writer.file_writer(constants.internal_stats_pagename) as f:
f.write(
f'''
-<TABLE BORDER=0>
+<CENTER>
+<TABLE BORDER=0 WIDTH=95%>
<TR>
- <TH>Renderer Name</TH>
- <TH>Last Run</TH>
- <TH>Num Invocations</TH>
- <TH>Render Latency</TH>
+ <TH><B>Renderer Name</B></TH>
+ <TH><B>Last Run</B></TH>
+ <TH><B>Num Invocations</B></TH>
+ <TH><B>Render Latency</B></TH>
</TR>
''')
for n, r in enumerate(renderer_catalog.get_renderers()):
f.write(
f'''
<TR>
- <TD {style}>{name}</TD>
- <TD {style}>{last}</TD>
- <TD {style}><CENTER>{count}</CENTER></TD>
- <TD {style}>p25={p25:5.2f}, p50={p50:5.2f}, p75={p75:5.2f}, p90={p90:5.2f}, p99={p99:5.2f}</TD>
+ <TD {style}>{name} </TD>
+ <TD {style}> {last} </TD>
+ <TD {style}><CENTER> {count} </CENTER></TD>
+ <TD {style}> p25={p25:5.2f}, p50={p50:5.2f}, p75={p75:5.2f}, p90={p90:5.2f}, p99={p99:5.2f}</TD>
</TR>
''')
f.write('</TABLE>')