~malept/ubuntu/lucid/python2.6/dev-dependency-fix

« back to all changes in this revision

Viewing changes to Demo/scripts/script.py

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2009-02-13 12:51:00 UTC
  • Revision ID: james.westby@ubuntu.com-20090213125100-uufgcb9yeqzujpqw
Tags: upstream-2.6.1
ImportĀ upstreamĀ versionĀ 2.6.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
9
import os, time, sys
 
10
import pty
 
11
 
 
12
def read(fd):
 
13
    data = os.read(fd, 1024)
 
14
    file.write(data)
 
15
    return data
 
16
 
 
17
shell = 'sh'
 
18
filename = 'typescript'
 
19
mode = 'w'
 
20
if os.environ.has_key('SHELL'):
 
21
    shell = os.environ['SHELL']
 
22
if '-a' in sys.argv:
 
23
    mode = 'a'
 
24
if '-p' in sys.argv:
 
25
    shell = 'python'
 
26
 
 
27
file = open(filename, mode)
 
28
 
 
29
sys.stdout.write('Script started, file is %s\n' % filename)
 
30
file.write('Script started on %s\n' % time.ctime(time.time()))
 
31
pty.spawn(shell, read)
 
32
file.write('Script done on %s\n' % time.ctime(time.time()))
 
33
sys.stdout.write('Script done, file is %s\n' % filename)