1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-03-20 01:28:56 +00:00

#682: Measure time spent on log reading

This commit is contained in:
Vladimir Iakovlev 2017-09-09 06:07:08 +02:00
parent 4875d75a64
commit 22aa9b701d

View File

@ -7,8 +7,7 @@ except ImportError:
import six import six
import pyte import pyte
from ..exceptions import ScriptNotInLog from ..exceptions import ScriptNotInLog
from ..logs import warn, debug from .. import const, logs
from .. import const
def _group_by_calls(log): def _group_by_calls(log):
@ -68,28 +67,30 @@ def get_output(script):
""" """
if six.PY2: if six.PY2:
warn('Experimental instant mode is Python 3+ only') logs.warn('Experimental instant mode is Python 3+ only')
return None return None
if 'THEFUCK_OUTPUT_LOG' not in os.environ: if 'THEFUCK_OUTPUT_LOG' not in os.environ:
warn("Output log isn't specified") logs.warn("Output log isn't specified")
return None return None
if const.USER_COMMAND_MARK not in os.environ.get('PS1', ''): if const.USER_COMMAND_MARK not in os.environ.get('PS1', ''):
warn("PS1 doesn't contain user command mark, please ensure " logs.warn(
"that PS1 is not changed after The Fuck alias initialization") "PS1 doesn't contain user command mark, please ensure "
"that PS1 is not changed after The Fuck alias initialization")
return None return None
try: try:
with open(os.environ['THEFUCK_OUTPUT_LOG'], 'rb') as log_file: with logs.debug_time(u'Read output from log'), \
open(os.environ['THEFUCK_OUTPUT_LOG'], 'rb') as log_file:
_skip_old_lines(log_file) _skip_old_lines(log_file)
lines = _get_output_lines(script, log_file) lines = _get_output_lines(script, log_file)
output = '\n'.join(lines).strip() output = '\n'.join(lines).strip()
debug(u'Received output: {}'.format(output)) logs.debug(u'Received output: {}'.format(output))
return output return output
except OSError: except OSError:
warn("Can't read output log") logs.warn("Can't read output log")
return None return None
except ScriptNotInLog: except ScriptNotInLog:
warn("Script not found in output log") logs.warn("Script not found in output log")
return None return None