home *** CD-ROM | disk | FTP | other *** search
/ PC World 2002 May / PCWorld_2002-05_cd.bin / Software / TemaCD / activepython / ActivePython-2.1.1.msi / Python21_win32comext_axdebug_dump.py < prev    next >
Encoding:
Python Source  |  2001-07-26  |  1.6 KB  |  50 lines

  1. import sys, string
  2. import traceback
  3. from win32com.axdebug import axdebug
  4. from win32com.client.util import Enumerator
  5. import pythoncom
  6.  
  7. def DumpDebugApplicationNode(node, level = 0):
  8.     # Recursive dump of a DebugApplicationNode
  9.     spacer = " " * level
  10.     for desc, attr in [("Node Name", axdebug.DOCUMENTNAMETYPE_APPNODE),
  11.                        ("Title", axdebug.DOCUMENTNAMETYPE_TITLE),
  12.                        ("Filename", axdebug.DOCUMENTNAMETYPE_FILE_TAIL),
  13.                        ("URL", axdebug.DOCUMENTNAMETYPE_URL),
  14.                        ]:
  15.         try:
  16.             info = node.GetName(attr)
  17.         except pythoncom.com_error:
  18.             info = "<N/A>"
  19.         print "%s%s: %s" % (spacer, desc, info)
  20.     try:
  21.         doc = node.GetDocument()
  22.     except pythoncom.com_error:
  23.         doc = None
  24.     if doc:
  25.         doctext = doc.QueryInterface(axdebug.IID_IDebugDocumentText)
  26.         numLines, numChars = doctext.GetSize()
  27. #            text, attr = doctext.GetText(0, 20, 1)
  28.         text, attr = doctext.GetText(0, numChars, 1)
  29.         print "%sText is %s, %d bytes long" % (spacer, repr(text[:40]+"..."), len(text))
  30.     else:
  31.         print "%s%s" % (spacer, "<No document available>")
  32.     
  33.     for child in Enumerator(node.EnumChildren()):
  34.         DumpDebugApplicationNode(child, level+1)
  35.     
  36. def dumpall():
  37.     dm=pythoncom.CoCreateInstance(axdebug.CLSID_MachineDebugManager,None,pythoncom.CLSCTX_ALL, axdebug.IID_IMachineDebugManager)
  38.     e=Enumerator(dm.EnumApplications())
  39.     for app in e:
  40.         print "Application: %s" % app.GetName()
  41.         node = app.GetRootNode() # of type PyIDebugApplicationNode->PyIDebugDocumentProvider->PyIDebugDocumentInfo
  42.         DumpDebugApplicationNode(node)
  43.  
  44. if __name__=='__main__':
  45.     try:
  46.         dumpall()
  47.     except:
  48.         traceback.print_exc()
  49.  
  50.