Mercurial > cpython-lru_cache-weakref
annotate Tools/scripts/import_diagnostics.py @ 84007:dbfbdf2b5c19 3.3
Fix #17967: For ftp urls CWD to target instead of hopping to each directory
towards target. This fixes a bug where target is accessible, but parent
directories are restricted.
| author | Senthil Kumaran <senthil@uthcode.com> |
|---|---|
| date | Sat, 01 Jun 2013 08:27:06 -0700 |
| parents | 00221c8b7c86 |
| children |
| rev | line source |
|---|---|
|
76553
e91a8467328b
Start a shared utility script for poking around at the import internals
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff
changeset
|
1 #!/usr/bin/env python3 |
|
e91a8467328b
Start a shared utility script for poking around at the import internals
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff
changeset
|
2 """Miscellaneous diagnostics for the import system""" |
|
e91a8467328b
Start a shared utility script for poking around at the import internals
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff
changeset
|
3 |
|
e91a8467328b
Start a shared utility script for poking around at the import internals
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff
changeset
|
4 import sys |
|
e91a8467328b
Start a shared utility script for poking around at the import internals
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff
changeset
|
5 import argparse |
|
e91a8467328b
Start a shared utility script for poking around at the import internals
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff
changeset
|
6 from pprint import pprint |
|
e91a8467328b
Start a shared utility script for poking around at the import internals
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff
changeset
|
7 |
|
e91a8467328b
Start a shared utility script for poking around at the import internals
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff
changeset
|
8 def _dump_state(args): |
|
e91a8467328b
Start a shared utility script for poking around at the import internals
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff
changeset
|
9 print(sys.version) |
|
76623
00221c8b7c86
Better control when dumping import state
Nick Coghlan <ncoghlan@gmail.com>
parents:
76553
diff
changeset
|
10 for name in args.attributes: |
|
00221c8b7c86
Better control when dumping import state
Nick Coghlan <ncoghlan@gmail.com>
parents:
76553
diff
changeset
|
11 print("sys.{}:".format(name)) |
|
00221c8b7c86
Better control when dumping import state
Nick Coghlan <ncoghlan@gmail.com>
parents:
76553
diff
changeset
|
12 pprint(getattr(sys, name)) |
|
00221c8b7c86
Better control when dumping import state
Nick Coghlan <ncoghlan@gmail.com>
parents:
76553
diff
changeset
|
13 |
|
00221c8b7c86
Better control when dumping import state
Nick Coghlan <ncoghlan@gmail.com>
parents:
76553
diff
changeset
|
14 def _add_dump_args(cmd): |
|
00221c8b7c86
Better control when dumping import state
Nick Coghlan <ncoghlan@gmail.com>
parents:
76553
diff
changeset
|
15 cmd.add_argument("attributes", metavar="ATTR", nargs="+", |
|
00221c8b7c86
Better control when dumping import state
Nick Coghlan <ncoghlan@gmail.com>
parents:
76553
diff
changeset
|
16 help="sys module attribute to display") |
|
76553
e91a8467328b
Start a shared utility script for poking around at the import internals
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff
changeset
|
17 |
|
e91a8467328b
Start a shared utility script for poking around at the import internals
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff
changeset
|
18 COMMANDS = ( |
|
76623
00221c8b7c86
Better control when dumping import state
Nick Coghlan <ncoghlan@gmail.com>
parents:
76553
diff
changeset
|
19 ("dump", "Dump import state", _dump_state, _add_dump_args), |
|
76553
e91a8467328b
Start a shared utility script for poking around at the import internals
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff
changeset
|
20 ) |
|
e91a8467328b
Start a shared utility script for poking around at the import internals
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff
changeset
|
21 |
|
e91a8467328b
Start a shared utility script for poking around at the import internals
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff
changeset
|
22 def _make_parser(): |
|
e91a8467328b
Start a shared utility script for poking around at the import internals
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff
changeset
|
23 parser = argparse.ArgumentParser() |
|
e91a8467328b
Start a shared utility script for poking around at the import internals
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff
changeset
|
24 sub = parser.add_subparsers(title="Commands") |
|
76623
00221c8b7c86
Better control when dumping import state
Nick Coghlan <ncoghlan@gmail.com>
parents:
76553
diff
changeset
|
25 for name, description, implementation, add_args in COMMANDS: |
|
76553
e91a8467328b
Start a shared utility script for poking around at the import internals
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff
changeset
|
26 cmd = sub.add_parser(name, help=description) |
|
e91a8467328b
Start a shared utility script for poking around at the import internals
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff
changeset
|
27 cmd.set_defaults(command=implementation) |
|
76623
00221c8b7c86
Better control when dumping import state
Nick Coghlan <ncoghlan@gmail.com>
parents:
76553
diff
changeset
|
28 add_args(cmd) |
|
76553
e91a8467328b
Start a shared utility script for poking around at the import internals
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff
changeset
|
29 return parser |
|
e91a8467328b
Start a shared utility script for poking around at the import internals
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff
changeset
|
30 |
|
e91a8467328b
Start a shared utility script for poking around at the import internals
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff
changeset
|
31 def main(args): |
|
e91a8467328b
Start a shared utility script for poking around at the import internals
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff
changeset
|
32 parser = _make_parser() |
|
e91a8467328b
Start a shared utility script for poking around at the import internals
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff
changeset
|
33 args = parser.parse_args(args) |
|
e91a8467328b
Start a shared utility script for poking around at the import internals
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff
changeset
|
34 return args.command(args) |
|
e91a8467328b
Start a shared utility script for poking around at the import internals
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff
changeset
|
35 |
|
e91a8467328b
Start a shared utility script for poking around at the import internals
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff
changeset
|
36 if __name__ == "__main__": |
|
e91a8467328b
Start a shared utility script for poking around at the import internals
Nick Coghlan <ncoghlan@gmail.com>
parents:
diff
changeset
|
37 sys.exit(main(sys.argv[1:])) |
