main.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/usr/bin/env python
  2. import sys
  3. sys.path.append("wrappers")
  4. from modelverse import *
  5. from subprocess import Popen, PIPE
  6. import json
  7. def lola_service(port):
  8. json_input = service_get(port)
  9. input_data = json.loads(json_input)
  10. print(input_data['petrinet'])
  11. print(input_data['query'])
  12. query_formula = "--formula=EF ("+ input_data['query']+")"
  13. lola = Popen(["services/LoLA/lola", "--path=path_output", query_formula, "--json=output.json"], stdin=PIPE, stdout=PIPE).communicate(input=input_data['petrinet'])
  14. output_file = open('output.json', 'r')
  15. result = json.load(output_file)
  16. output_file.close()
  17. # If safety query is violated resulting True in output
  18. path = ''
  19. if result['analysis']['result']:
  20. with open('path_output') as f:
  21. for transition in f:
  22. transition = transition.replace('\n',',')
  23. path = path + transition
  24. #json_result = '{"analysis_result": True , "path":\"'+path.rstrip(',') + '\"}'
  25. service_set(port, result['analysis']['result'])
  26. service_set(port, path.rstrip(','))
  27. try:
  28. init(sys.argv[1])
  29. login("LoLA", "LoLA_password")
  30. service_register("lola", lola_service)
  31. try:
  32. if sys.version_info[0] < 3:
  33. while raw_input() != "STOP":
  34. # Stay active, as we shouldn't exit while the service is running!
  35. pass
  36. else:
  37. while input() != "STOP":
  38. # Stay active, as we shouldn't exit while the service is running!
  39. pass
  40. finally:
  41. service_stop()
  42. except KeyboardInterrupt:
  43. pass