dump.py 1.8 KB

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