()
| 1668 | "-c 'until X'".""" |
| 1669 | |
| 1670 | def main(): |
| 1671 | import getopt |
| 1672 | |
| 1673 | opts, args = getopt.getopt(sys.argv[1:], 'mhc:', ['help', 'command=']) |
| 1674 | |
| 1675 | if not args: |
| 1676 | print(_usage) |
| 1677 | sys.exit(2) |
| 1678 | |
| 1679 | commands = [] |
| 1680 | run_as_module = False |
| 1681 | for opt, optarg in opts: |
| 1682 | if opt in ['-h', '--help']: |
| 1683 | print(_usage) |
| 1684 | sys.exit() |
| 1685 | elif opt in ['-c', '--command']: |
| 1686 | commands.append(optarg) |
| 1687 | elif opt in ['-m']: |
| 1688 | run_as_module = True |
| 1689 | |
| 1690 | mainpyfile = args[0] # Get script filename |
| 1691 | if not run_as_module and not os.path.exists(mainpyfile): |
| 1692 | print('Error:', mainpyfile, 'does not exist') |
| 1693 | sys.exit(1) |
| 1694 | |
| 1695 | sys.argv[:] = args # Hide "pdb.py" and pdb options from argument list |
| 1696 | |
| 1697 | # Replace pdb's dir with script's dir in front of module search path. |
| 1698 | if not run_as_module: |
| 1699 | sys.path[0] = os.path.dirname(mainpyfile) |
| 1700 | |
| 1701 | # Note on saving/restoring sys.argv: it's a good idea when sys.argv was |
| 1702 | # modified by the script being debugged. It's a bad idea when it was |
| 1703 | # changed by the user from the command line. There is a "restart" command |
| 1704 | # which allows explicit specification of command line arguments. |
| 1705 | pdb = Pdb() |
| 1706 | pdb.rcLines.extend(commands) |
| 1707 | while True: |
| 1708 | try: |
| 1709 | if run_as_module: |
| 1710 | pdb._runmodule(mainpyfile) |
| 1711 | else: |
| 1712 | pdb._runscript(mainpyfile) |
| 1713 | if pdb._user_requested_quit: |
| 1714 | break |
| 1715 | print("The program finished and will be restarted") |
| 1716 | except Restart: |
| 1717 | print("Restarting", mainpyfile, "with arguments:") |
| 1718 | print("\t" + " ".join(args)) |
| 1719 | except SystemExit: |
| 1720 | # In most cases SystemExit does not warrant a post-mortem session. |
| 1721 | print("The program exited via sys.exit(). Exit status:", end=' ') |
| 1722 | print(sys.exc_info()[1]) |
| 1723 | except SyntaxError: |
| 1724 | traceback.print_exc() |
| 1725 | sys.exit(1) |
| 1726 | except: |
| 1727 | traceback.print_exc() |
nothing calls this directly
no test coverage detected