debug_prompt.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  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("Switching context to Modelverse: all data is piped.")
  24. local_print("Available commands: 'attach_debugger', 'detach_debugger', 'pause', 'resume'")
  25. local_print("To quit: execute command 'quit'")
  26. while 1:
  27. inp = raw_input().split(" ")
  28. action = inp[0]
  29. if action == "quit":
  30. local_print("Received quit: breaking connection to Modelverse immediately!")
  31. break
  32. else:
  33. username = inp[1]
  34. urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": action, "username": username}))).read()