annotate Demo/comparisons/systemtest.py @ 79675:c0a2294de787 2.7

Issue #16199: Backport 2to3 typo fix from 3.2.
author Chris Jerdonek <chris.jerdonek@gmail.com>
date Thu, 11 Oct 2012 16:15:46 -0700
parents 558689b6d7f0
children 6b18a095c2e7
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: 2651
diff changeset
1 #! /usr/bin/env python
2651
84e2260db179 commit -- why not...
Guido van Rossum <guido@python.org>
parents:
diff changeset
2
84e2260db179 commit -- why not...
Guido van Rossum <guido@python.org>
parents:
diff changeset
3 # 3) System Test
28788
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
4 #
2651
84e2260db179 commit -- why not...
Guido van Rossum <guido@python.org>
parents:
diff changeset
5 # Given a list of directories, report any bogus symbolic links contained
84e2260db179 commit -- why not...
Guido van Rossum <guido@python.org>
parents:
diff changeset
6 # anywhere in those subtrees. A bogus symbolic link is one that cannot
84e2260db179 commit -- why not...
Guido van Rossum <guido@python.org>
parents:
diff changeset
7 # be resolved because it points to a nonexistent or otherwise
84e2260db179 commit -- why not...
Guido van Rossum <guido@python.org>
parents:
diff changeset
8 # unresolvable file. Do *not* use an external find executable.
84e2260db179 commit -- why not...
Guido van Rossum <guido@python.org>
parents:
diff changeset
9 # Directories may be very very deep. Print a warning immediately if the
84e2260db179 commit -- why not...
Guido van Rossum <guido@python.org>
parents:
diff changeset
10 # system you're running on doesn't support symbolic links.
84e2260db179 commit -- why not...
Guido van Rossum <guido@python.org>
parents:
diff changeset
11
84e2260db179 commit -- why not...
Guido van Rossum <guido@python.org>
parents:
diff changeset
12 # This implementation:
84e2260db179 commit -- why not...
Guido van Rossum <guido@python.org>
parents:
diff changeset
13 # - takes one optional argument, using the current directory as default
84e2260db179 commit -- why not...
Guido van Rossum <guido@python.org>
parents:
diff changeset
14 # - uses chdir to increase performance
84e2260db179 commit -- why not...
Guido van Rossum <guido@python.org>
parents:
diff changeset
15 # - sorts the names per directory
84e2260db179 commit -- why not...
Guido van Rossum <guido@python.org>
parents:
diff changeset
16 # - prints output lines of the form "path1 -> path2" as it goes
84e2260db179 commit -- why not...
Guido van Rossum <guido@python.org>
parents:
diff changeset
17 # - prints error messages about directories it can't list or chdir into
84e2260db179 commit -- why not...
Guido van Rossum <guido@python.org>
parents:
diff changeset
18
84e2260db179 commit -- why not...
Guido van Rossum <guido@python.org>
parents:
diff changeset
19 import os
84e2260db179 commit -- why not...
Guido van Rossum <guido@python.org>
parents:
diff changeset
20 import sys
84e2260db179 commit -- why not...
Guido van Rossum <guido@python.org>
parents:
diff changeset
21 from stat import *
84e2260db179 commit -- why not...
Guido van Rossum <guido@python.org>
parents:
diff changeset
22
84e2260db179 commit -- why not...
Guido van Rossum <guido@python.org>
parents:
diff changeset
23 def main():
28788
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
24 try:
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
25 # Note: can't test for presence of lstat -- it's always there
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
26 dummy = os.readlink
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
27 except AttributeError:
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
28 print "This system doesn't have symbolic links"
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
29 sys.exit(0)
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
30 if sys.argv[1:]:
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
31 prefix = sys.argv[1]
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
32 else:
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
33 prefix = ''
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
34 if prefix:
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
35 os.chdir(prefix)
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
36 if prefix[-1:] != '/': prefix = prefix + '/'
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
37 reportboguslinks(prefix)
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
38 else:
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
39 reportboguslinks('')
2651
84e2260db179 commit -- why not...
Guido van Rossum <guido@python.org>
parents:
diff changeset
40
84e2260db179 commit -- why not...
Guido van Rossum <guido@python.org>
parents:
diff changeset
41 def reportboguslinks(prefix):
28788
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
42 try:
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
43 names = os.listdir('.')
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
44 except os.error, msg:
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
45 print "%s%s: can't list: %s" % (prefix, '.', msg)
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
46 return
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
47 names.sort()
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
48 for name in names:
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
49 if name == os.curdir or name == os.pardir:
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
50 continue
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
51 try:
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
52 mode = os.lstat(name)[ST_MODE]
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
53 except os.error:
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
54 print "%s%s: can't stat: %s" % (prefix, name, msg)
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
55 continue
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
56 if S_ISLNK(mode):
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
57 try:
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
58 os.stat(name)
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
59 except os.error:
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
60 print "%s%s -> %s" % \
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
61 (prefix, name, os.readlink(name))
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
62 elif S_ISDIR(mode):
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
63 try:
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
64 os.chdir(name)
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
65 except os.error, msg:
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
66 print "%s%s: can't chdir: %s" % \
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
67 (prefix, name, msg)
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
68 continue
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
69 try:
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
70 reportboguslinks(prefix + name + '/')
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
71 finally:
558689b6d7f0 Run these demo scripts through reindent.py to give them 4-space indents. I've verified that their output is unchanged.
Andrew M. Kuchling <amk@amk.ca>
parents: 4573
diff changeset
72 os.chdir('..')
2651
84e2260db179 commit -- why not...
Guido van Rossum <guido@python.org>
parents:
diff changeset
73
84e2260db179 commit -- why not...
Guido van Rossum <guido@python.org>
parents:
diff changeset
74 main()