debug_prompt.py 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import threading
  2. import subprocess
  3. import os
  4. import sys
  5. import json
  6. if sys.version_info[0] < 3:
  7. from urllib2 import urlopen as urlopen
  8. from urllib2 import Request as Request
  9. from urllib import urlencode as urlencode
  10. else:
  11. from urllib.request import urlopen as urlopen
  12. from urllib.request import Request as Request
  13. from urllib.parse import urlencode as urlencode
  14. def local_print(string):
  15. if os.name == "posix":
  16. # Nicer colour output when using posix (and thus supporting colour)
  17. string = "\033[92m%s\033[0m" % string
  18. print(string)
  19. def remote_print(string):
  20. if os.name == "posix":
  21. # Nicer colour output when using posix (and thus supporting colour)
  22. string = "\033[94m%s\033[0m" % string
  23. print(string)
  24. local_print("Welcome to the debugging shell!")
  25. local_print("Please specify Modelverse location (default: 127.0.0.1:8001)")
  26. if sys.version_info[0] < 3:
  27. location = raw_input()
  28. else:
  29. location = input()
  30. if location == "":
  31. address = "http://127.0.0.1:8001/"
  32. local_print("Please specify task name (default: test)")
  33. if sys.version_info[0] < 3:
  34. taskname = raw_input()
  35. else:
  36. taskname = input()
  37. if location == "":
  38. taskname = "test"
  39. local_print("Switching context to Modelverse: all data is piped.")
  40. local_print("Available commands: 'pause', 'resume'")
  41. local_print("To quit: execute command 'quit'")
  42. while 1:
  43. if sys.version_info[0] < 3:
  44. inp = raw_input().split(" ")
  45. else:
  46. inp = input().split(" ")
  47. action = inp[0]
  48. if action == "quit":
  49. local_print("Received quit: breaking connection to Modelverse immediately!")
  50. break
  51. data = urlencode({"op": action, "taskname": taskname})
  52. print(json.loads(urlopen(Request(address, data)).read()))