NEWS entry for r75531.
[python.git] / Demo / scripts / script.py
bloba8aca4ae3597d1f251f314c66261a9b04f4f3cc6
1 #! /usr/bin/env python
3 # script.py -- Make typescript of terminal session.
4 # Usage:
5 # -a Append to typescript.
6 # -p Use Python as shell.
7 # Author: Steen Lumholt.
10 import os, time, sys, getopt
11 import pty
13 def read(fd):
14 data = os.read(fd, 1024)
15 script.write(data)
16 return data
18 shell = 'sh'
19 filename = 'typescript'
20 mode = 'w'
21 if os.environ.has_key('SHELL'):
22 shell = os.environ['SHELL']
24 try:
25 opts, args = getopt.getopt(sys.argv[1:], 'ap')
26 except getopt.error, msg:
27 print '%s: %s' % (sys.argv[0], msg)
28 sys.exit(2)
30 for o, a in opts:
31 if o == '-a':
32 mode = 'a'
33 elif o == '-p':
34 shell = 'python'
36 script = open(filename, mode)
38 sys.stdout.write('Script started, file is %s\n' % filename)
39 script.write('Script started on %s\n' % time.ctime(time.time()))
40 pty.spawn(shell, read)
41 script.write('Script done on %s\n' % time.ctime(time.time()))
42 sys.stdout.write('Script done, file is %s\n' % filename)