Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixes to handle 'repeat' command output in graphterm

  • Loading branch information...
commit 6808e50a2772af940d5f0a6e5603f097ca5b8d5c 1 parent cb41e02
@mitotic authored
View
2  graphterm/gtermhost.py
@@ -467,7 +467,7 @@ def logmessage(self, log_level, msg, exc_info=None, logtype="", plaintext=""):
if self.oshell_client and (log_level is None or log_level >= self.log_level):
self.oshell_client.remote_response(OSHELL_NAME, "", [["log", "", [logtype, log_level, msg]]])
- if logtype or log_level is None:
+ if not logtype.startswith("web") and (logtype or log_level is None):
sys.stderr.write((plaintext or msg)+"\n")
def editback(self, content, filepath="", filetype="", editor="", modify=False):
View
15 graphterm/gtermserver.py
@@ -505,10 +505,10 @@ def on_message(self, message):
try:
for msg in msg_list:
if msg[0] == "osh_stdout":
- TraceInterface.receive_output("stdout", from_user or self.websocket_id, msg[1])
+ TraceInterface.receive_output("stdout", msg[1], from_user or self.websocket_id, msg[2])
elif msg[0] == "osh_stderr":
- TraceInterface.receive_output("stderr", from_user or self.websocket_id, msg[1])
+ TraceInterface.receive_output("stderr", msg[1], from_user or self.websocket_id, msg[2])
elif msg[0] == "reconnect_host":
if conn:
@@ -614,7 +614,7 @@ def send_command(cls, path_comps, command):
websocket_id = path_comps[0]
websocket = GTSocket._all_websockets.get(websocket_id)
if not websocket:
- cls.receive_output("stderr", "", "No such socket: %s" % path_comps[0])
+ cls.receive_output("stderr", False, "", "No such socket: %s" % path_comps[0])
return
# Schedules callback in event loop
@@ -622,11 +622,11 @@ def send_command(cls, path_comps, command):
json.dumps([["osh_stdin", command]])))
@classmethod
- def receive_output(cls, channel, username, message):
+ def receive_output(cls, channel, repeat, username, message):
"""Receive channel="stdout"/"stderr" output from browser via websocket and forward to oshell
"""
path_comps = [username] if username else []
- cls.trace_hook(channel, path_comps, message)
+ cls.trace_hook(channel, repeat, path_comps, message)
def xterm(command="", name=None, host="localhost", port=gtermhost.DEFAULT_HTTP_PORT):
@@ -1085,6 +1085,7 @@ def get(self):
(gtermhost.DEFAULT_HTTP_PORT-2 if options.widgets else 0)},
oshell_globals=oshell_globals,
oshell_unsafe=True,
+ oshell_thread=(not options.oshell_input),
oshell_no_input=(not options.oshell_input),
oshell_web_interface=TraceInterface,
io_loop=IO_loop)
@@ -1127,9 +1128,9 @@ def sigterm(signal, frame):
print >> sys.stderr, "GraphTerm server (v%s) listening on %s:%s" % (about.version, http_host, http_port)
print >> sys.stderr, "\nType ^C to stop server"
- if Trace_shell and options.oshell_input:
+ if Trace_shell:
Trace_shell.loop()
- else:
+ if not Trace_shell or not options.oshell_input:
while Http_server:
time.sleep(1)
except KeyboardInterrupt:
View
32 graphterm/otrace.py
@@ -2103,7 +2103,7 @@ def parse(self, line, batch=False, here_doc=None):
return ("", "Shutting down...")
return "", ""
- if line.lstrip().startswith("repeat "):
+ if not batch and line.lstrip().startswith("repeat "):
line = line.lstrip()[len("repeat "):]
if line:
self.set_repeat(line)
@@ -3886,7 +3886,7 @@ class DefaultCallback(TraceCallback):
"""
def logmessage(self, log_level, msg, exc_info=None, logtype="", plaintext=""):
# If log_level is None, always display message
- if log_level is None or log_level >= self.log_level:
+ if not logtype.startswith("web") and (log_level is None or log_level >= self.log_level):
super(DefaultCallback, self).logmessage(None, msg, exc_info=exc_info, logtype=logtype, plaintext=plaintext)
class CallbackLogHandler(logging.Handler):
@@ -5129,7 +5129,7 @@ def trace_entity(cls, entity, exclude=[], include=[], modulename="", unwrap=Fals
return trace_list
@classmethod
- def web_hook(cls, op_type, path, data):
+ def web_hook(cls, op_type, repeat, path, data):
# Must be thread-safe (OK if output only)
if not OShell.instance:
return
@@ -5138,25 +5138,29 @@ def web_hook(cls, op_type, path, data):
if op_type == "stderr":
if oshell.repeat_interval:
oshell.set_repeat(None)
- msg = data+"\n"
- oshell.std_output(msg)
+ if not oshell.no_input:
+ oshell.std_output(data+"\n")
if OTrace.callback_handler:
- OTrace.callback_handler.logmessage(None, msg)
+ OTrace.callback_handler.logmessage(None, data, logtype="weberr")
if op_type == "stdout":
- if oshell.repeat_interval:
- data = CLEAR_SCREEN_SEQUENCE + data
+ outdata = data
+ logtype = "webout"
+ if oshell.repeat_interval or repeat:
+ outdata = CLEAR_SCREEN_SEQUENCE + outdata
+ logtype = "webrepeat"
if oshell.repeat_alt_screen == 1:
oshell.repeat_alt_screen = 2
- data = ALT_SCREEN_ONSEQ + data
+ outdata = ALT_SCREEN_ONSEQ + outdata
else:
if oshell.repeat_alt_screen == 2:
oshell.repeat_alt_screen = 0
- data = ALT_SCREEN_OFFSEQ + data
- data = data+"\n"+oshell.prompt1
- oshell.std_output(data, flush=True)
- if OTrace.callback_handler:
- OTrace.callback_handler.logmessage(None, data)
+ outdata = ALT_SCREEN_OFFSEQ + outdata
+ outdata = outdata+"\n"+oshell.prompt1
+ if not oshell.no_input:
+ oshell.std_output(outdata, flush=True)
+ if OTrace.callback_handler and data:
+ OTrace.callback_handler.logmessage(None, data, logtype=logtype)
except Exception:
pass
View
88 graphterm/www/graphterm.js
@@ -24,6 +24,8 @@ var gDefaultEditor = gMobileDisplay ? "ckeditor" : "ace";
var MAX_LINE_BUFFER = 500;
var MAX_COMMAND_BUFFER = 100;
+var REPEAT_MILLISEC = 500;
+
var RELEASE_NOTES_URL = "http://info.mindmeldr.com/code/graphterm/graphterm-release-notes";
var PYPI_URL = "http://pypi.python.org/pypi/graphterm";
var PYPI_JSON_URL = PYPI_URL + "/json?callback=?";
@@ -527,6 +529,9 @@ function GTWebSocket(auth_user, auth_code) {
this.theme = "default";
this.alt_mode = false;
+ this.repeat_command = "";
+ this.repeat_intervalID = null;
+
var protocol = (window.location.protocol.indexOf("https") == 0) ? "wss" : "ws";
var ws_url = protocol+":/"+"/"+window.location.host+"/_websocket"+window.location.pathname; // Split the double slash to avoid confusing the JS minifier
if (this.auth_user || this.auth_code)
@@ -594,6 +599,48 @@ function GTAutosizeIFrame(elem) {
$(this).height($(this).contents().find('body').height() + 20);} ) }, 500 );
}
+function GTRepeatCommand() {
+ if (gWebSocket && gWebSocket.repeat_command)
+ gWebSocket.evalCommand(gWebSocket.repeat_command, true);
+}
+
+GTWebSocket.prototype.repeatCommand = function(command) {
+ if (this.repeat_intervalID) {
+ window.clearInterval(this.repeat_intervalID);
+ this.repeat_intervalID = null;
+ }
+
+ if (command) {
+ this.repeat_command = command;
+ this.repeat_intervalID = window.setInterval(GTRepeatCommand, REPEAT_MILLISEC);
+ } else {
+ this.repeat_command = "";
+ }
+}
+
+GTWebSocket.prototype.evalCommand = function(command, repeat) {
+ var stdout = "";
+ var stderr = "";
+ try {
+ if (OSH_ECHO && !repeat)
+ console.log(command);
+ var evalout = eval(command);
+ stdout = evalout ? evalout+"" : "";
+ if (OSH_ECHO && stdout && !repeat)
+ console.log(stdout);
+ } catch (err) {
+ stderr = err+"";
+ if (OSH_ECHO && stderr)
+ console.log(stderr);
+ }
+
+ var osh_send = [];
+ if (stderr)
+ osh_send.push(["osh_stderr", !!this.repeat_intervalID, stderr]);
+ osh_send.push(["osh_stdout", !!this.repeat_intervalID, stdout]);
+ gWebSocket.write(osh_send);
+}
+
GTWebSocket.prototype.onmessage = function(evt) {
if (this.closed)
return;
@@ -615,25 +662,14 @@ GTWebSocket.prototype.onmessage = function(evt) {
if (action == "osh_stdin") {
// Execute JS "command" from otrace console
- var stdout = "";
- var stderr = "";
- try {
- if (OSH_ECHO)
- console.log(command[1]);
- var evalout = eval(command[1]);
- stdout = evalout ? evalout+"" : "";
- if (OSH_ECHO && stdout)
- console.log(stdout);
- } catch (err) {
- stderr = err+"";
- if (OSH_ECHO && stderr)
- console.log(stderr);
+ if (command[1] == "repeat") {
+ this.repeatCommand();
+ } else if (command[1].substr(0,7) == "repeat ") {
+ this.repeatCommand(command[1].substr(7));
+ } else {
+ this.repeatCommand();
+ this.evalCommand(command[1]);
}
- var osh_send = [];
- if (stderr)
- osh_send.push(["osh_stderr", stderr]);
- osh_send.push(["osh_stdout", stdout]);
- gWebSocket.write(osh_send);
} else if (action == "abort") {
alert(command[1]);
@@ -707,10 +743,18 @@ GTWebSocket.prototype.onmessage = function(evt) {
var logPrefix = command[1];
var logArgs = command[2];
var logtype = logArgs[0] || "log";
- var prefix = logtype.toUpperCase()+": ";
- console.log(prefix+logArgs[2]);
- $(logPrefix+'<pre class="gterm-log">'+prefix+logArgs[2]+'</pre>').appendTo("#session-log .curentry");
- $("#session-log .curentry .gterm-log .gterm-link").bindclick(otraceClickHandler);
+ var prefix = (logtype.substr(0,3) != "web") ? logtype.toUpperCase()+": " : "";
+ if (logtype != "webrepeat") {
+ this.repeatCommand(); // Cancel any repeats, if not repeat web command output
+ }
+ //console.log(prefix+logArgs[2]);
+ var logclasses = "gterm-log"
+ if (logtype == "webrepeat") {
+ logclasses += " gterm-logrepeat";
+ $("#session-log .preventry .gterm-logrepeat").remove();
+ }
+ $(logPrefix+'<pre class="'+logclasses+'">'+prefix+logArgs[2]+'</pre>').appendTo("#session-log .preventry");
+ $("#session-log .preventry .gterm-log .gterm-link").bindclick(otraceClickHandler);
} else if (action == "receive_msg") {
var fromUser = command[1];
Please sign in to comment.
Something went wrong with that request. Please try again.