Get duration from Stdout object

This commit is contained in:
Marcin Kulik
2016-07-01 19:55:30 +02:00
parent d665ebf556
commit 6ebb2094d4
5 changed files with 8 additions and 35 deletions

View File

@@ -132,3 +132,4 @@ class PtyRecorder:
signal.signal(signal.SIGCHLD, old_sigchld_handler)
os.waitpid(pid, 0)
output.close()

View File

@@ -1,6 +1,5 @@
import os
import subprocess
from . import timer
from .asciicast import Asciicast
from .pty_recorder import PtyRecorder
@@ -17,7 +16,9 @@ class Recorder:
command = user_command or self.env.get('SHELL') or 'sh'
full_command = ['env', 'ASCIINEMA_REC=1', 'sh', '-c', command]
stdout = Stdout(max_wait)
duration, _ = timer.timeit(self.pty_recorder.record_command, full_command, stdout)
self.pty_recorder.record_command(full_command, stdout)
width = int(get_command_output(['tput', 'cols']))
height = int(get_command_output(['tput', 'lines']))
@@ -25,7 +26,7 @@ class Recorder:
stdout,
width,
height,
duration,
stdout.duration,
command=user_command,
title=title,
term=self.env.get('TERM'),

View File

@@ -8,6 +8,7 @@ class Stdout:
self.frames = []
self.max_wait = max_wait
self.last_write_time = time.time()
self.duration = 0
self.decoder = codecs.getincrementaldecoder('UTF-8')('replace')
def write(self, data):
@@ -19,7 +20,7 @@ class Stdout:
return len(data)
def close(self):
pass
self._increment_elapsed_time()
def _increment_elapsed_time(self):
# delay = int(delay * 1000000) / 1000000.0 # millisecond precission
@@ -29,6 +30,7 @@ class Stdout:
if self.max_wait and delay > self.max_wait:
delay = self.max_wait
self.duration += delay
self.last_write_time = now
return delay

View File

@@ -1,10 +0,0 @@
import time
def timeit(callable, *args):
start_time = time.time()
ret = callable(*args)
end_time = time.time()
duration = end_time - start_time
return (duration, ret)

View File

@@ -1,21 +0,0 @@
import time
from nose.tools import assert_equal
from .test_helper import Test, FakeClock
from asciinema.timer import timeit
class TestTimer(Test):
def setUp(self):
self.real_time = time.time
time.time = FakeClock([10.0, 24.57]).time
def tearDown(self):
time.time = self.real_time
def test_timeit(self):
duration, return_value = timeit(lambda *args: args, 1, 'two', True)
assert_equal(14.57, duration)
assert_equal((1, 'two', True), return_value)