[Python-modules-commits] [ipdb] 03/14: commandline usage consistent with pdb. adds argument commands
Andrey Rahmatullin
wrar at moszumanska.debian.org
Thu Jan 18 17:50:21 UTC 2018
This is an automated email from the git hooks/post-receive script.
wrar pushed a commit to annotated tag 0.10.3
in repository ipdb.
commit 2381b128f5c62a0426e16465bfb9f86295dd7b94
Author: zvodd <zv.odd.101 at gmail.com>
Date: Mon Feb 13 11:20:43 2017 +1100
commandline usage consistent with pdb. adds argument commands
---
ipdb/__main__.py | 39 +++++++++++++++++++++++++++++++++------
1 file changed, 33 insertions(+), 6 deletions(-)
diff --git a/ipdb/__main__.py b/ipdb/__main__.py
index 02344b6..6e65e34 100644
--- a/ipdb/__main__.py
+++ b/ipdb/__main__.py
@@ -72,12 +72,13 @@ else:
def_exec_lines = [line + '\n' for line in ipapp.exec_lines]
-def _init_pdb(context=3):
+def _init_pdb(context=3, commands=[]):
try:
p = debugger_cls(def_colors, context=context)
except TypeError:
p = debugger_cls(def_colors)
p.rcLines += def_exec_lines
+ p.rcLines.extend(commands)
return p
@@ -138,20 +139,46 @@ def launch_ipdb_on_exception():
pass
+_usage = """\
+usage: python -m ipdb [-c command] ... pyfile [arg] ...
+
+Debug the Python program given by pyfile.
+
+Initial commands are read from .pdbrc files in your home directory
+and in the current directory, if they exist. Commands supplied with
+-c are executed after commands from .pdbrc files.
+
+To let the script run until an exception occurs, use "-c continue".
+To let the script run up to a given line X in the debugged file, use
+"-c 'until X'"."""
+
+
def main():
import traceback
import sys
+ import getopt
+
try:
from pdb import Restart
except ImportError:
class Restart(Exception):
pass
+
+ opts, args = getopt.getopt(sys.argv[1:], 'hc:', ['--help', '--command='])
- if not sys.argv[1:] or sys.argv[1] in ("--help", "-h"):
- print("usage: ipdb.py scriptfile [arg] ...")
+ if not args:
+ print(_usage)
sys.exit(2)
-
- mainpyfile = sys.argv[1] # Get script filename
+
+ commands = []
+ for opt, optarg in opts:
+ if opt in ['-h', '--help']:
+ print(_usage)
+ sys.exit()
+ elif opt in ['-c', '--command']:
+ commands.append(optarg)
+
+ mainpyfile = args[0] # Get script filename
if not os.path.exists(mainpyfile):
print('Error:', mainpyfile, 'does not exist')
sys.exit(1)
@@ -165,7 +192,7 @@ def main():
# modified by the script being debugged. It's a bad idea when it was
# changed by the user from the command line. There is a "restart" command
# which allows explicit specification of command line arguments.
- pdb = _init_pdb()
+ pdb = _init_pdb(commands=commands)
while 1:
try:
pdb._runscript(mainpyfile)
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/ipdb.git
More information about the Python-modules-commits
mailing list