X-Git-Url: https://git.phdru.name/?a=blobdiff_plain;f=lib%2Fpython%2Fpdbrc.py;fp=lib%2Fpython%2Fpdbrc.py;h=0ebe7b513e5cf2cb8b4e0ee738e927ae148111ff;hb=580013920401a783a31124a179d328fc68952d31;hp=0e67e51600fa4938211700f7adac173afc1e3a1a;hpb=a41d9660d2c49abc7ead86794e9f1c3212c7cd92;p=dotfiles.git diff --git a/lib/python/pdbrc.py b/lib/python/pdbrc.py index 0e67e51..0ebe7b5 100644 --- a/lib/python/pdbrc.py +++ b/lib/python/pdbrc.py @@ -1,5 +1,9 @@ +import atexit +import os +import sys +import readline + # Command line history: -import os, readline histfile = os.path.expanduser("~/.pdb-history") try: @@ -7,10 +11,13 @@ try: except IOError: pass + def savehist(histfile=histfile): - import os, readline - histfilesize = os.environ.get('HISTFILESIZE') or \ - os.environ.get('HISTSIZE') + import os + import readline + + histfilesize = os.environ.get('HISTFILESIZE') \ + or os.environ.get('HISTSIZE') if histfilesize: try: histfilesize = int(histfilesize) @@ -20,22 +27,27 @@ def savehist(histfile=histfile): readline.set_history_length(histfilesize) readline.write_history_file(histfile) -import atexit atexit.register(savehist) -# return to debugger after fatal exception (Python cookbook 14.5): -import sys + def info(type, value, tb): + # return to debugger after fatal exception (Python cookbook 14.5): + import pdb + import sys + import traceback + if hasattr(sys, 'ps1') or not sys.stderr.isatty(): sys.__excepthook__(type, value, tb) - import traceback, pdb traceback.print_exception(type, value, tb) print pdb.pm() + sys.excepthook = info + # http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/498182 -import pdb, rlcompleter +import pdb +import rlcompleter pdb.Pdb.complete = rlcompleter.Completer().complete # Cleanup any variables that could otherwise clutter up the namespace.