Browse Source

Added PythonPDEVS wrapper

Yentl Van Tendeloo 7 years ago
parent
commit
05e5578567
2 changed files with 33 additions and 0 deletions
  1. 33 0
      services/DEVS_batch/main.py
  2. 0 0
      services/DEVS_batch/models/.keepme

+ 33 - 0
services/DEVS_batch/main.py

@@ -0,0 +1,33 @@
+import sys
+sys.path.append("wrappers")
+from modelverse import *
+
+import random, json, uuid
+sys.path.append('services/DEVS_batch/models')
+
+def pypdevs_service(port):
+    code = service_get(port)
+    experiment = service_get(port)
+    model_name = str(uuid.uuid4()).replace("-", "")
+
+    with open("services/DEVS_batch/models/" + model_name + ".py", 'w') as f:
+        f.write(code)
+        f.write(experiment)
+
+    main = getattr(__import__(model_name), "main")
+    for i in main():
+        service_set(port, i)
+try:
+    init(sys.argv[1])
+    login("pypdevs_batch_service", "my_password")
+
+    service_register("pypdevs_batch_simulator", pypdevs_service)
+
+    try:
+        while True:
+            # Stay active, as we shouldn't exit while the service is running!
+            time.sleep(1)
+    finally:
+        service_stop()
+except KeyboardInterrupt:
+    pass

+ 0 - 0
services/DEVS_batch/models/.keepme