annotate Demo/scripts/script.py @ 80661:94de77bd0b4b 2.7

Issue #16194: document imp.load_dynamic problems when read several extension modules from the same binary object file.
author Andrew Svetlov <andrew.svetlov@gmail.com>
date Thu, 29 Nov 2012 19:51:28 +0200
parents 52d6973cbd94
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
56480
ca018e2bb865 Use getopt in script.py demo.
Georg Brandl <georg@python.org>
parents: 32735
diff changeset
2
1928
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 # 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
4 # Usage:
32735
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
5 # -a Append to typescript.
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
6 # -p Use Python as shell.
1928
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 # Author: Steen Lumholt.
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
56480
ca018e2bb865 Use getopt in script.py demo.
Georg Brandl <georg@python.org>
parents: 32735
diff changeset
10 import os, time, sys, getopt
1928
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
11 import pty
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
12
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 def read(fd):
32735
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
14 data = os.read(fd, 1024)
56481
52d6973cbd94 Fix variable.
Georg Brandl <georg@python.org>
parents: 56480
diff changeset
15 script.write(data)
32735
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
16 return data
1928
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
17
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
18 shell = 'sh'
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 filename = 'typescript'
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 mode = 'w'
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 if os.environ.has_key('SHELL'):
32735
2bc66f1df7cc Whitespace normalization. Ran reindent.py over the entire source tree.
Tim Peters <tim.peters@gmail.com>
parents: 4573
diff changeset
22 shell = os.environ['SHELL']
56480
ca018e2bb865 Use getopt in script.py demo.
Georg Brandl <georg@python.org>
parents: 32735
diff changeset
23
ca018e2bb865 Use getopt in script.py demo.
Georg Brandl <georg@python.org>
parents: 32735
diff changeset
24 try:
ca018e2bb865 Use getopt in script.py demo.
Georg Brandl <georg@python.org>
parents: 32735
diff changeset
25 opts, args = getopt.getopt(sys.argv[1:], 'ap')
ca018e2bb865 Use getopt in script.py demo.
Georg Brandl <georg@python.org>
parents: 32735
diff changeset
26 except getopt.error, msg:
ca018e2bb865 Use getopt in script.py demo.
Georg Brandl <georg@python.org>
parents: 32735
diff changeset
27 print '%s: %s' % (sys.argv[0], msg)
ca018e2bb865 Use getopt in script.py demo.
Georg Brandl <georg@python.org>
parents: 32735
diff changeset
28 sys.exit(2)
1928
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
29
56480
ca018e2bb865 Use getopt in script.py demo.
Georg Brandl <georg@python.org>
parents: 32735
diff changeset
30 for o, a in opts:
ca018e2bb865 Use getopt in script.py demo.
Georg Brandl <georg@python.org>
parents: 32735
diff changeset
31 if o == '-a':
ca018e2bb865 Use getopt in script.py demo.
Georg Brandl <georg@python.org>
parents: 32735
diff changeset
32 mode = 'a'
ca018e2bb865 Use getopt in script.py demo.
Georg Brandl <georg@python.org>
parents: 32735
diff changeset
33 elif o == '-p':
ca018e2bb865 Use getopt in script.py demo.
Georg Brandl <georg@python.org>
parents: 32735
diff changeset
34 shell = 'python'
ca018e2bb865 Use getopt in script.py demo.
Georg Brandl <georg@python.org>
parents: 32735
diff changeset
35
ca018e2bb865 Use getopt in script.py demo.
Georg Brandl <georg@python.org>
parents: 32735
diff changeset
36 script = open(filename, mode)
1928
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
37
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
38 sys.stdout.write('Script started, file is %s\n' % filename)
56480
ca018e2bb865 Use getopt in script.py demo.
Georg Brandl <georg@python.org>
parents: 32735
diff changeset
39 script.write('Script started on %s\n' % time.ctime(time.time()))
1928
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
40 pty.spawn(shell, read)
56480
ca018e2bb865 Use getopt in script.py demo.
Georg Brandl <georg@python.org>
parents: 32735
diff changeset
41 script.write('Script done on %s\n' % time.ctime(time.time()))
1928
a8b7ee0e572d Get rid of freeze (now its own directory).
Guido van Rossum <guido@python.org>
parents:
diff changeset
42 sys.stdout.write('Script done, file is %s\n' % filename)