debug_prompt.py 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import urllib
  2. import urllib2
  3. import threading
  4. import subprocess
  5. import os
  6. import sys
  7. import json
  8. def local_print(string):
  9. if os.name == "posix":
  10. # Nicer colour output when using posix (and thus supporting colour)
  11. string = "\033[92m%s\033[0m" % string
  12. print(string)
  13. def remote_print(string):
  14. if os.name == "posix":
  15. # Nicer colour output when using posix (and thus supporting colour)
  16. string = "\033[94m%s\033[0m" % string
  17. print(string)
  18. local_print("Welcome to the debugging shell!")
  19. local_print("Please specify Modelverse location (default: 127.0.0.1:8001)")
  20. location = raw_input()
  21. if location == "":
  22. address = "http://127.0.0.1:8001/"
  23. local_print("Please specify user name (default: test)")
  24. username = raw_input()
  25. if location == "":
  26. username = "test"
  27. local_print("Switching context to Modelverse: all data is piped.")
  28. local_print("Available commands: 'attach_debugger', 'detach_debugger', 'pause', 'resume'")
  29. local_print("To quit: execute command 'quit'")
  30. while 1:
  31. inp = raw_input().split(" ")
  32. action = inp[0]
  33. if action == "quit":
  34. local_print("Received quit: breaking connection to Modelverse immediately!")
  35. break
  36. reply = json.loads(urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": action, "username": username}))).read())
  37. print "RES: %s" % reply['result']
  38. print "STATE: %s" % reply['state']
  39. if 'info' in reply:
  40. print "STACK:\n\t%s" % '\n\t'.join(["%s. %s" % item for item in reversed(list(enumerate(reply['info'])))])