1 | n/a | #!/usr/bin/env python3 |
---|
2 | n/a | """Miscellaneous diagnostics for the import system""" |
---|
3 | n/a | |
---|
4 | n/a | import sys |
---|
5 | n/a | import argparse |
---|
6 | n/a | from pprint import pprint |
---|
7 | n/a | |
---|
8 | n/a | def _dump_state(args): |
---|
9 | n/a | print(sys.version) |
---|
10 | n/a | for name in args.attributes: |
---|
11 | n/a | print("sys.{}:".format(name)) |
---|
12 | n/a | pprint(getattr(sys, name)) |
---|
13 | n/a | |
---|
14 | n/a | def _add_dump_args(cmd): |
---|
15 | n/a | cmd.add_argument("attributes", metavar="ATTR", nargs="+", |
---|
16 | n/a | help="sys module attribute to display") |
---|
17 | n/a | |
---|
18 | n/a | COMMANDS = ( |
---|
19 | n/a | ("dump", "Dump import state", _dump_state, _add_dump_args), |
---|
20 | n/a | ) |
---|
21 | n/a | |
---|
22 | n/a | def _make_parser(): |
---|
23 | n/a | parser = argparse.ArgumentParser() |
---|
24 | n/a | sub = parser.add_subparsers(title="Commands") |
---|
25 | n/a | for name, description, implementation, add_args in COMMANDS: |
---|
26 | n/a | cmd = sub.add_parser(name, help=description) |
---|
27 | n/a | cmd.set_defaults(command=implementation) |
---|
28 | n/a | add_args(cmd) |
---|
29 | n/a | return parser |
---|
30 | n/a | |
---|
31 | n/a | def main(args): |
---|
32 | n/a | parser = _make_parser() |
---|
33 | n/a | args = parser.parse_args(args) |
---|
34 | n/a | return args.command(args) |
---|
35 | n/a | |
---|
36 | n/a | if __name__ == "__main__": |
---|
37 | n/a | sys.exit(main(sys.argv[1:])) |
---|