From bc18074ab8d9061626544d95ce095104f94b7158 Mon Sep 17 00:00:00 2001 From: Anthony Scopatz Date: Sat, 8 Aug 2015 19:46:27 -0400 Subject: [PATCH] some minor changes --- xonsh/base_shell.py | 14 +++++++++++--- xonsh/history.py | 5 +---- 2 files changed, 12 insertions(+), 7 deletions(-) diff --git a/xonsh/base_shell.py b/xonsh/base_shell.py index e32405c99..276528e6c 100644 --- a/xonsh/base_shell.py +++ b/xonsh/base_shell.py @@ -1,6 +1,7 @@ """The base class for xonsh shell""" import os import sys +import time import builtins import traceback @@ -38,12 +39,20 @@ class BaseShell(object): code = self.push(line) if code is None: return + ts1 = None + #outstart = sys.stdout.tell() try: + ts0 = time.time() self.execer.exec(code, mode='single', glbs=self.ctx) # no locals + ts1 = time.time() except XonshError as e: print(e.args[0], file=sys.stderr) except: _print_exception() + finally: + ts1 = ts1 or time.time() + hist = builtins.__xonsh_history__ + hist.append({'inp': line, 'ts': [ts0, ts1]}) if builtins.__xonsh_exit__: return True @@ -72,9 +81,6 @@ class BaseShell(object): self.reset_buffer() _print_exception() return None - finally: - hist = builtins.__xonsh_history__ - hist.append({'inp': src}) return code def reset_buffer(self): @@ -135,3 +141,5 @@ def _print_exception(): exc_type, exc_value, exc_traceback = sys.exc_info() exception_only = traceback.format_exception_only(exc_type, exc_value) sys.stderr.write(''.join(exception_only)) + + diff --git a/xonsh/history.py b/xonsh/history.py index a0ef583b2..869643573 100644 --- a/xonsh/history.py +++ b/xonsh/history.py @@ -1,6 +1,5 @@ """Implements the xonsh history object""" import os -import time import uuid import builtins from threading import Thread, Condition @@ -76,15 +75,13 @@ class History(object): lazyjson.dump(meta, f, sort_keys=True) def append(self, cmd): - """Adds command with current timestamp to ordered history. Will periodically - flush the history to file. + """Appends command to history. Will periodically flush the history to file. Parameters ---------- cmd : dict Command dictionary that should be added to the ordered history. """ - cmd['timestamp'] = time.time() self.buffer.append(cmd) if len(self.buffer) >= self.buffersize: self.flush()