gump-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From leosim...@apache.org
Subject svn commit: r209260 - /gump/branches/Gump3/pygump/python/gump/plugins/introspection.py
Date Tue, 05 Jul 2005 11:58:31 GMT
Author: leosimons
Date: Tue Jul  5 04:58:30 2005
New Revision: 209260

URL: http://svn.apache.org/viewcvs?rev=209260&view=rev
Log:
Add a new introspection plugin useful as a 'debug probe'.

 * pygump/python/gump/plugins/introspection.py: new plugin usable for 'probing' during debugging.

Added:
    gump/branches/Gump3/pygump/python/gump/plugins/introspection.py
      - copied, changed from r209074, gump/branches/Gump3/pygump/python/gump/plugins/instrumentation.py

Copied: gump/branches/Gump3/pygump/python/gump/plugins/introspection.py (from r209074, gump/branches/Gump3/pygump/python/gump/plugins/instrumentation.py)
URL: http://svn.apache.org/viewcvs/gump/branches/Gump3/pygump/python/gump/plugins/introspection.py?p2=gump/branches/Gump3/pygump/python/gump/plugins/introspection.py&p1=gump/branches/Gump3/pygump/python/gump/plugins/instrumentation.py&r1=209074&r2=209260&rev=209260&view=diff
==============================================================================
--- gump/branches/Gump3/pygump/python/gump/plugins/instrumentation.py (original)
+++ gump/branches/Gump3/pygump/python/gump/plugins/introspection.py Tue Jul  5 04:58:30 2005
@@ -21,24 +21,64 @@
 
 from gump.plugins import AbstractPlugin
 
-class TimerPlugin(AbstractPlugin):
-    """Set a date property on each model object as it is visited."""
-    def __init__(self, propertyname, format='%d %b %Y %H:%M:%S'):
-        self.format = format
-        self.propertyname = propertyname
+class IntrospectionPlugin(AbstractPlugin):
+    """Print out a what the workspace looks like. Useful for debugging."""
+    def __init__(self, log):
+        self.log = log
         
-    def _do_visit(self, object):
-        setattr(object, self.propertyname, self.gettime())
-    
-    def visit_workspace(self, workspace):
-        self._do_visit(workspace)
-    
-    def visit_module(self, module):    
-        self._do_visit(module)
-    
-    def visit_project(self, project):    
-        self._do_visit(project)
-
-    def gettime(self):
-        import time
-        return time.strftime(self.format, time.localtime())
+    def finalize(self, workspace):
+        msg = "Workspace properties:\n   "
+        properties = [prop for prop in dir(workspace) if not prop.startswith("__")]
+        properties.sort()
+        msg += "\n   ".join(properties)
+
+        allproperties = []
+        for v in workspace.repositories.values():
+            properties = [prop for prop in dir(v) if not prop.startswith("__") and not prop
in allproperties]
+            allproperties.extend(properties)
+        allproperties.sort()
+        msg += "\n\nAll possible repository properties:\n   "
+        msg += "\n   ".join(allproperties)
+
+        allproperties = []
+        for v in workspace.modules.values():
+            properties = [prop for prop in dir(v) if not prop.startswith("__") and not prop
in allproperties]
+            allproperties.extend(properties)
+        allproperties.sort()
+        msg += "\n\nAll possible module properties:\n   "
+        msg += "\n   ".join(allproperties)
+
+        allproperties = []
+        for v in workspace.projects.values():
+            properties = [prop for prop in dir(v) if not prop.startswith("__") and not prop
in allproperties]
+            allproperties.extend(properties)
+        allproperties.sort()
+        msg += "\n\nAll possible project properties:\n   "
+        msg += "\n   ".join(allproperties)
+
+        msg += "\n\nAll known repositories:\n"
+        for k in workspace.repositories.keys():
+            msg += "   %s\n" % k
+
+        msg += "\nAll known modules:\n"
+        for k in workspace.modules.keys():
+            msg += "   %s\n" % k
+
+        msg += "\nAll known projects:\n"
+        for k in workspace.modules.keys():
+            msg += "   %s\n" % k
+        
+        self.log.debug("=" * 78)
+        self.log.debug(msg)
+        self.log.debug("=" * 78)
+        
+        # Example of how you can "probe" into specific parts of the model
+        # if you want...
+        #
+        #xmlapis = workspace.projects["xml-apis"]
+        #for prop in dir(xmlapis):
+        #    att = getattr(xmlapis, prop)
+        #    if callable(att):
+        #        continue
+        #    self.log.debug("XML-APIS attribute %s has value %s" % (prop, att))
+        
\ No newline at end of file



Mime
View raw message