Mercurial > cpython-lru_cache-weakref
annotate Demo/scripts/script.py @ 25838:8540887bcec6 2.2
Backport of 2.183:
Fix memory leak in add_subclass() found by NealN with valgrind.
| author | Guido van Rossum <guido@python.org> |
|---|---|
| date | Fri, 18 Oct 2002 13:42:21 +0000 |
| parents | 73758db2f464 |
| children | 2bc66f1df7cc |
| rev | line source |
|---|---|
|
4573
73758db2f464
/usr/local/bin/python -> /usr/bin/env python
Guido van Rossum <guido@python.org>
parents:
1928
diff
changeset
|
1 #! /usr/bin/env python |
|
1928
a8b7ee0e572d
Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
2 # script.py -- Make typescript of terminal session. |
|
a8b7ee0e572d
Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
3 # Usage: |
|
a8b7ee0e572d
Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
4 # -a Append to typescript. |
|
a8b7ee0e572d
Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
5 # -p Use Python as shell. |
|
a8b7ee0e572d
Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
6 # Author: Steen Lumholt. |
|
a8b7ee0e572d
Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
7 |
|
a8b7ee0e572d
Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
8 |
|
a8b7ee0e572d
Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
9 import os, time, sys |
|
a8b7ee0e572d
Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
10 import pty |
|
a8b7ee0e572d
Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
11 |
|
a8b7ee0e572d
Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
12 def read(fd): |
|
a8b7ee0e572d
Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
13 data = os.read(fd, 1024) |
|
a8b7ee0e572d
Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
14 file.write(data) |
|
a8b7ee0e572d
Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
15 return data |
|
a8b7ee0e572d
Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
16 |
|
a8b7ee0e572d
Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
17 shell = 'sh' |
|
a8b7ee0e572d
Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
18 filename = 'typescript' |
|
a8b7ee0e572d
Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
19 mode = 'w' |
|
a8b7ee0e572d
Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
20 if os.environ.has_key('SHELL'): |
|
a8b7ee0e572d
Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
21 shell = os.environ['SHELL'] |
|
a8b7ee0e572d
Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
22 if '-a' in sys.argv: |
|
a8b7ee0e572d
Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
23 mode = 'a' |
|
a8b7ee0e572d
Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
24 if '-p' in sys.argv: |
|
a8b7ee0e572d
Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
25 shell = 'python' |
|
a8b7ee0e572d
Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
26 |
|
a8b7ee0e572d
Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
27 file = open(filename, mode) |
|
a8b7ee0e572d
Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
28 |
|
a8b7ee0e572d
Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
29 sys.stdout.write('Script started, file is %s\n' % filename) |
|
a8b7ee0e572d
Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
30 file.write('Script started on %s\n' % time.ctime(time.time())) |
|
a8b7ee0e572d
Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
31 pty.spawn(shell, read) |
|
a8b7ee0e572d
Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
32 file.write('Script done on %s\n' % time.ctime(time.time())) |
|
a8b7ee0e572d
Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff
changeset
|
33 sys.stdout.write('Script done, file is %s\n' % filename) |
