From 46245ab4aa79254b398d7c00ae1c7a47dc7e1a13 Mon Sep 17 00:00:00 2001 From: ibuler Date: Thu, 26 Nov 2015 13:21:05 +0800 Subject: [PATCH] fix record bug --- connect.py | 4 +--- jlog/log_api.py | 8 ++++++-- run_websocket.py | 3 +-- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/connect.py b/connect.py index a9c15f750..28617cc31 100644 --- a/connect.py +++ b/connect.py @@ -204,7 +204,6 @@ class Tty(object): log.save() log_file_f.write('Start at %s\n' % datetime.datetime.now()) - log_time_f.write('0.0000 ') return log_file_f, log_time_f, log def get_connect_info(self): @@ -326,7 +325,7 @@ class SshTty(Tty): sys.stdout.write(x) sys.stdout.flush() now_timestamp = time.time() - log_time_f.write('%s\n%s ' % (len(x), round(now_timestamp-pre_timestamp, 4))) + log_time_f.write('%s %s\n' % (round(now_timestamp-pre_timestamp, 4), len(x))) log_file_f.write(x) pre_timestamp = now_timestamp log_file_f.flush() @@ -363,7 +362,6 @@ class SshTty(Tty): finally: termios.tcsetattr(sys.stdin, termios.TCSADRAIN, old_tty) - log_time_f.write('0') log_file_f.write('End time is %s' % datetime.datetime.now()) log_file_f.close() log_time_f.close() diff --git a/jlog/log_api.py b/jlog/log_api.py index 5ef484777..1537b1614 100644 --- a/jlog/log_api.py +++ b/jlog/log_api.py @@ -43,14 +43,18 @@ def scriptToJSON(scriptf, timing=None): scriptf.readline() # ignore first header line from script file offset = 0 for t in timing: - data = escapeString(scriptf.read(t[1])) + dt = scriptf.read(t[1]) + print "## %s: %s" % (t, dt) + data = escapeString(dt) offset += t[0] ret.append((data, offset)) + print ret return dumps(ret) def renderTemplate(script_path, time_file_path, dimensions=(24, 80), templatename=DEFAULT_TEMPLATE): - with copen(script_path, encoding='utf-8', errors='replace') as scriptf: + #with copen(script_path, encoding='utf-8', errors='replace') as scriptf: + with open(script_path) as scriptf: with open(time_file_path) as timef: timing = getTiming(timef) json = scriptToJSON(scriptf, timing) diff --git a/run_websocket.py b/run_websocket.py index 77c3f8096..9250dd3a8 100644 --- a/run_websocket.py +++ b/run_websocket.py @@ -312,7 +312,6 @@ class WebTerminalHandler(tornado.websocket.WebSocketHandler): self.log.is_finished = True self.log.end_time = datetime.datetime.now() self.log.save() - self.log_time_f.write('0') self.log_time_f.close() self.close() except AttributeError: @@ -336,7 +335,7 @@ class WebTerminalHandler(tornado.websocket.WebSocketHandler): try: self.write_message(json.dumps({'data': data})) now_timestamp = time.time() - self.log_time_f.write('%s\n%s ' % (len(data), round(now_timestamp-pre_timestamp, 4))) + self.log_time_f.write('%s %s\n' % (round(now_timestamp-pre_timestamp, 4), len(data))) self.log_file_f.write(data) pre_timestamp = now_timestamp self.log_file_f.flush()