1996-11-27 15:52:01 -04:00
|
|
|
#! /usr/bin/env python
|
1994-10-03 13:45:35 -03:00
|
|
|
# script.py -- Make typescript of terminal session.
|
|
|
|
# Usage:
|
2004-07-18 02:56:09 -03:00
|
|
|
# -a Append to typescript.
|
|
|
|
# -p Use Python as shell.
|
1994-10-03 13:45:35 -03:00
|
|
|
# Author: Steen Lumholt.
|
|
|
|
|
|
|
|
|
|
|
|
import os, time, sys
|
|
|
|
import pty
|
|
|
|
|
|
|
|
def read(fd):
|
2004-07-18 02:56:09 -03:00
|
|
|
data = os.read(fd, 1024)
|
|
|
|
file.write(data)
|
|
|
|
return data
|
1994-10-03 13:45:35 -03:00
|
|
|
|
|
|
|
shell = 'sh'
|
|
|
|
filename = 'typescript'
|
|
|
|
mode = 'w'
|
|
|
|
if os.environ.has_key('SHELL'):
|
2004-07-18 02:56:09 -03:00
|
|
|
shell = os.environ['SHELL']
|
1994-10-03 13:45:35 -03:00
|
|
|
if '-a' in sys.argv:
|
2004-07-18 02:56:09 -03:00
|
|
|
mode = 'a'
|
1994-10-03 13:45:35 -03:00
|
|
|
if '-p' in sys.argv:
|
2004-07-18 02:56:09 -03:00
|
|
|
shell = 'python'
|
1994-10-03 13:45:35 -03:00
|
|
|
|
|
|
|
file = open(filename, mode)
|
|
|
|
|
|
|
|
sys.stdout.write('Script started, file is %s\n' % filename)
|
|
|
|
file.write('Script started on %s\n' % time.ctime(time.time()))
|
|
|
|
pty.spawn(shell, read)
|
|
|
|
file.write('Script done on %s\n' % time.ctime(time.time()))
|
|
|
|
sys.stdout.write('Script done, file is %s\n' % filename)
|