Home | History | Annotate | Download | only in scripts
      1 #!/usr/bin/env python3
      2 """Miscellaneous diagnostics for the import system"""
      3 
      4 import sys
      5 import argparse
      6 from pprint import pprint
      7 
      8 def _dump_state(args):
      9     print(sys.version)
     10     for name in args.attributes:
     11         print("sys.{}:".format(name))
     12         pprint(getattr(sys, name))
     13 
     14 def _add_dump_args(cmd):
     15     cmd.add_argument("attributes", metavar="ATTR", nargs="+",
     16                      help="sys module attribute to display")
     17 
     18 COMMANDS = (
     19   ("dump", "Dump import state", _dump_state, _add_dump_args),
     20 )
     21 
     22 def _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 
     31 def main(args):
     32     parser = _make_parser()
     33     args = parser.parse_args(args)
     34     return args.command(args)
     35 
     36 if __name__ == "__main__":
     37     sys.exit(main(sys.argv[1:]))
     38