some minor changes

This commit is contained in:
Anthony Scopatz 2015-08-08 19:46:27 -04:00
parent d2cd3388bd
commit bc18074ab8
2 changed files with 12 additions and 7 deletions

View file

@ -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))

View file

@ -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()