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