From 4d216633fca8ca46fc3b51fdf2b382db93e3ade1 Mon Sep 17 00:00:00 2001 From: Chris Jones Date: Thu, 14 Jan 2010 13:15:05 +0000 Subject: [PATCH] -d now automatically infers the Class::method in dbg(), and -d additionally adds a trailing (filename:line) item. debugserver is now moved to -ddd --- terminator | 2 +- terminatorlib/optionparse.py | 2 ++ terminatorlib/util.py | 21 +++++++++++++++++++-- 3 files changed, 22 insertions(+), 3 deletions(-) diff --git a/terminator b/terminator index fa857073..3e766fc1 100755 --- a/terminator +++ b/terminator @@ -58,7 +58,7 @@ if __name__ == '__main__': WINDOW.show() TERMINAL.spawn_child() - if OPTIONS.debug > 1: + if OPTIONS.debug > 2: import terminatorlib.debugserver as debugserver # pylint: disable-msg=W0611 import threading diff --git a/terminatorlib/optionparse.py b/terminatorlib/optionparse.py index c49575ba..08aececb 100755 --- a/terminatorlib/optionparse.py +++ b/terminatorlib/optionparse.py @@ -82,6 +82,8 @@ WM_WINDOW_ROLE property on the window') if options.debug: util.DEBUG = True + if options.debug >1: + util.DEBUGFILES = True if options.working_directory: if os.path.exists(os.path.expanduser(options.working_directory)): diff --git a/terminatorlib/util.py b/terminatorlib/util.py index 971e8c55..ad712b38 100755 --- a/terminatorlib/util.py +++ b/terminatorlib/util.py @@ -20,14 +20,32 @@ import sys import gtk import os import pwd +import inspect # set this to true to enable debugging output DEBUG = False +# set this to true to additionally list filenames in debugging +DEBUGFILES = False def dbg(log = ""): """Print a message if debugging is enabled""" if DEBUG: - print >> sys.stderr, log + stackitem = inspect.stack()[1] + parent_frame = stackitem[0] + method = parent_frame.f_code.co_name + names, varargs, keywords, local_vars = inspect.getargvalues(parent_frame) + try: + self_name = names[0] + classname = local_vars[self_name].__class__.__name__ + except IndexError: + classname = "noclass" + if DEBUGFILES: + line = stackitem[2] + filename = parent_frame.f_code.co_filename + extra = " (%s:%s)" % (filename, line) + else: + extra = "" + print >> sys.stderr, "%s::%s: %s%s" % (classname, method, log, extra) def err(log = ""): """Print an error message""" @@ -145,4 +163,3 @@ def dict_diff(reference, working): result[key] = working[key] return(result) -