debug_prompt.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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: '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. print json.loads(urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": action, "username": username}))).read())