Mercurial > cpython-lru_cache-weakref
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 |
| 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 | 2 |
| 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 | 5 # Given a list of directories, report any bogus symbolic links contained |
| 6 # anywhere in those subtrees. A bogus symbolic link is one that cannot | |
| 7 # be resolved because it points to a nonexistent or otherwise | |
| 8 # unresolvable file. Do *not* use an external find executable. | |
| 9 # Directories may be very very deep. Print a warning immediately if the | |
| 10 # system you're running on doesn't support symbolic links. | |
| 11 | |
| 12 # This implementation: | |
| 13 # - takes one optional argument, using the current directory as default | |
| 14 # - uses chdir to increase performance | |
| 15 # - sorts the names per directory | |
| 16 # - prints output lines of the form "path1 -> path2" as it goes | |
| 17 # - prints error messages about directories it can't list or chdir into | |
| 18 | |
| 19 import os | |
| 20 import sys | |
| 21 from stat import * | |
| 22 | |
| 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 | 40 |
| 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 | 73 |
| 74 main() |
