[PATCH] pdb hack to have autocompletion and anaconda reference

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

this is hack for more comfortable anaconda debugging with pdb.
What it does:
- Adds commands to enable/disable rlcompleter completion
 in pdb (cmplon, cmploff).
- Allows to bring objects from anaconda into local namespace
 of pdb frame (anaconda object is used in example;).
 Objects added to namespace are printed with cmplns command.
(see docstring of the pdb_completion)

I missed these things in my anaconda debugging, if you do
too, it might be useful, thoug it's perhaps too raw and
specialized to add to rawhide.

First patch is the hackfunction, the second one is example of
use - it adds the features to pdb sessions invoked by clicking Debug
in gui.

I borrowed here:
http://code.activestate.com/recipes/498182/

Any feedback is welcome...

Radek
diff --git a/iutil.py b/iutil.py
index 1982577..1ac8337 100644
--- a/iutil.py
+++ b/iutil.py
@@ -608,3 +608,61 @@ def isConsoleOnVirtualTerminal():
     if isS390():
         return False
     return not flags.serial
+
+def pdb_completion(pdb, namespace_update=None):
+    """Add autocompletion to pdb module.
+
+    Module rlcompleter is used for autocompletion.
+    Commands added to pdb:
+    cmplon  - turns autocompletion on
+    cmploff - turns autocompletion off
+    cmplns  - prints objects added to local namespace by cmplon
+
+    namespace_update: dict holding namespace to be added to local namespace
+                      with cmplon command (e.g. anaconda object)
+    """
+
+
+    def do_cmplon(self, args):
+        namespace = self.curframe.f_locals
+        if self.added_namespace:
+            namespace.update(self.added_namespace)
+
+        import rlcompleter
+        # keep a completer class, and make sure that it uses the current local scope
+        if not hasattr(self, 'completer'):
+            self.completer = rlcompleter.Completer(namespace)
+        else:
+            self.completer.namespace = namespace
+        
+        import readline
+        readline.set_completer(self.completer.complete)
+        print >>self.stdout, "rl completion on"
+
+    def do_cmploff(self, args):
+        import readline
+        readline.set_completer(self.complete)
+        print >>self.stdout, "rl completion off"
+
+    def do_cmplns(self, args):
+        print >>self.stdout, self.added_namespace
+
+    def help_cmplon(self):
+        print >>self.stdout, """Turns rlcompleter autocompletion on. Also can
+        add objects to local namespace - to list added objects run cmplns"""
+
+    def help_cmploff(self):
+        print >>self.stdout, """Turns rlcompleter autocompletion off"""
+
+    def help_cmplns(self):
+        print >>self.stdout, """Prints objects added to local namespace with
+        cmplon command"""
+
+    pdb.Pdb.added_namespace = namespace_update
+    pdb.Pdb.do_cmplon = do_cmplon
+    pdb.Pdb.do_cmploff = do_cmploff
+    pdb.Pdb.do_cmplns = do_cmplns
+    pdb.Pdb.help_cmplon = help_cmplon
+    pdb.Pdb.help_cmploff = help_cmploff
+    pdb.Pdb.help_cmplns = help_cmplns
+   
diff --git a/gui.py b/gui.py
index 2fcc9e9..a23f9cf 100755
--- a/gui.py
+++ b/gui.py
@@ -972,6 +972,10 @@ class MessageWindow:
             pass
         import pdb
         try:
+            iutil.pdb_completion(pdb)
+        except:
+            reload(pdb)
+        try:
             pdb.set_trace()
         except:
             sys.exit(-1)
@@ -1366,6 +1370,10 @@ class InstallControlWindow:
             pass
         import pdb
         try:
+            iutil.pdb_completion(pdb, {'danconda': self.anaconda})
+        except:
+            reload(pdb)
+        try:
             pdb.set_trace()
         except:
             sys.exit(-1)
_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list

[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux