/Demo/scripts/script.py
Python | 33 lines | 21 code | 6 blank | 6 comment | 5 complexity | f68b095795044fe2930c721587a82184 MD5 | raw file
1#! /usr/bin/env python 2# script.py -- Make typescript of terminal session. 3# Usage: 4# -a Append to typescript. 5# -p Use Python as shell. 6# Author: Steen Lumholt. 7 8 9import os, time, sys 10import pty 11 12def read(fd): 13 data = os.read(fd, 1024) 14 file.write(data) 15 return data 16 17shell = 'sh' 18filename = 'typescript' 19mode = 'w' 20if os.environ.has_key('SHELL'): 21 shell = os.environ['SHELL'] 22if '-a' in sys.argv: 23 mode = 'a' 24if '-p' in sys.argv: 25 shell = 'python' 26 27file = open(filename, mode) 28 29sys.stdout.write('Script started, file is %s\n' % filename) 30file.write('Script started on %s\n' % time.ctime(time.time())) 31pty.spawn(shell, read) 32file.write('Script done on %s\n' % time.ctime(time.time())) 33sys.stdout.write('Script done, file is %s\n' % filename)