Skip to content
Permalink
Browse files

The pydb program can now invoke either a module or a script.

  • Loading branch information...
kdart committed Aug 7, 2018
1 parent 6ca6807 commit 1446fabaedf8c6bdd4ab1fc3f0ea731e0ef8da9d
Showing with 19 additions and 2 deletions.
  1. +19 −2 debugger/bin/pydb
@@ -1,6 +1,5 @@
#!/usr/bin/python2.7
# -*- coding: us-ascii -*-
# vim:ts=4:sw=4:softtabstop=4:smarttab:expandtab
#
# Copyright (C) 2009- Keith Dart <keith@dartworks.biz>
#
@@ -14,11 +13,29 @@
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.

"""Use pydb to run a script or module that will enter the debugger if if throws an exception.
"""

import sys
import os
import runpy

import pycopia.autodebug


pytarget = sys.argv[1] if len(sys.argv) > 1 else None

if not pytarget:
print 'Usage: pydb <module or file>'
sys.exit(64) # EX_USAGE

del sys.argv[0]
runpy._run_module_as_main(sys.argv[0])

if os.path.exists(pytarget):
sys.path[0] = os.path.dirname(pytarget)
runpy.run_path(pytarget, run_name="__main__")
else:
# Assume module name if no file.
runpy._run_module_as_main(sys.argv[0])

# vim:ts=4:sw=4:softtabstop=4:smarttab:expandtab

0 comments on commit 1446fab

Please sign in to comment.
You can’t perform that action at this time.