|
@@ -1,12 +1,9 @@
|
|
|
import urllib
|
|
|
-import urllib2
|
|
|
import json
|
|
|
import random
|
|
|
-from urllib2 import URLError
|
|
|
import sys
|
|
|
import time
|
|
|
import threading
|
|
|
-import Queue
|
|
|
import uuid
|
|
|
|
|
|
from sccd.runtime.statecharts_core import Event
|
|
@@ -173,16 +170,13 @@ def _input(value, port=None):
|
|
|
port = taskname
|
|
|
if isinstance(value, type([])):
|
|
|
value = json.dumps(value)
|
|
|
- #urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "data": value, "taskname": port}))).read()
|
|
|
ctrl_input.addInput(Event("HTTP_input", "request_in", [urllib.urlencode({"op": "set_input", "taskname": port, "data": value}), None]))
|
|
|
else:
|
|
|
value = json.dumps(value)
|
|
|
- #urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": value, "taskname": port}))).read()
|
|
|
ctrl_input.addInput(Event("HTTP_input", "request_in", [urllib.urlencode({"op": "set_input", "taskname": port, "value": value}), None]))
|
|
|
|
|
|
def _input_raw(value, taskname):
|
|
|
# Ugly json encoding of primitives
|
|
|
- #urllib2.urlopen(urllib2.Request(address, urllib.urlencode({"op": "set_input", "value": value, "taskname": taskname}))).read()
|
|
|
ctrl_input.addInput(Event("HTTP_input", "request_in", [urllib.urlencode({"op": "set_input", "taskname": taskname, "value": value}), None]))
|
|
|
|
|
|
def _compile_AL(code):
|
|
@@ -237,7 +231,7 @@ def _last_output():
|
|
|
return outputs[0]
|
|
|
|
|
|
# Raise common exceptions
|
|
|
-def _handle_output(requested=None, split=None):
|
|
|
+def _handle_output(requested=None, split=False):
|
|
|
value = _output()
|
|
|
if value.startswith("Model exists: "):
|
|
|
raise ModelExists(value.split(": ", 1)[1])
|
|
@@ -252,14 +246,14 @@ def _handle_output(requested=None, split=None):
|
|
|
elif value.startswith("Attribute not found: "):
|
|
|
raise NoSuchAttribute(value.split(": ", 1)[1])
|
|
|
elif requested is not None and value.startswith(requested):
|
|
|
- if split is None:
|
|
|
+ if not split:
|
|
|
return value
|
|
|
else:
|
|
|
- splitted = value.strip().split(split, 1)
|
|
|
- if len(splitted) == 1:
|
|
|
- return ""
|
|
|
+ splitted = value.strip().split(" ", 1)
|
|
|
+ if len(splitted) > 1:
|
|
|
+ return splitted[1].split("\n")
|
|
|
else:
|
|
|
- return splitted[1].rstrip()
|
|
|
+ return []
|
|
|
else:
|
|
|
raise InterfaceMismatch(value)
|
|
|
|
|
@@ -319,11 +313,12 @@ def init(address_param="127.0.0.1:8001", timeout=20.0):
|
|
|
port = int(port)
|
|
|
|
|
|
for ctrl in controllers:
|
|
|
- socket2event.boot_translation_service(ctrl)
|
|
|
listener = ctrl.addOutputListener("request_out")
|
|
|
+ socket2event.boot_translation_service(ctrl)
|
|
|
thrd = threading.Thread(target=ctrl.start)
|
|
|
thrd.daemon = True
|
|
|
thrd.start()
|
|
|
+ time.sleep(0.1)
|
|
|
|
|
|
print("Waiting for init")
|
|
|
evt = listener.fetch(-1)
|
|
@@ -433,19 +428,16 @@ def model_list(location):
|
|
|
"""List all models."""
|
|
|
_goto_mode(MODE_MODELLING)
|
|
|
_input(["model_list", location])
|
|
|
- return set(_handle_output("Success: ", split=" ").split("\n"))
|
|
|
+ return set(_handle_output("Success: ", split=True))
|
|
|
|
|
|
def model_list_full(location):
|
|
|
"""List full information on all models."""
|
|
|
_goto_mode(MODE_MODELLING)
|
|
|
_input(["model_list_full", location])
|
|
|
- output = _handle_output("Success: ", split=" ")
|
|
|
- if output == "":
|
|
|
- return set([])
|
|
|
+ output = _handle_output("Success: ", split=True)
|
|
|
|
|
|
lst = set([])
|
|
|
- value = output.strip().split("\n")
|
|
|
- for v in value:
|
|
|
+ for v in output:
|
|
|
m = v.strip()
|
|
|
perm, own, grp, m = m.split(" ", 3)
|
|
|
lst.add((m, own, grp, perm))
|
|
@@ -460,7 +452,7 @@ def verify(model_name, metamodel_name=None):
|
|
|
metamodel_name = _get_metamodel(model_name)
|
|
|
|
|
|
_input(["verify", model_name, metamodel_name])
|
|
|
- return _handle_output("Success: ", split=" ")
|
|
|
+ return _handle_output("Success: ", split=True)[0]
|
|
|
|
|
|
def model_overwrite(model_name, new_model=None, metamodel_name=None):
|
|
|
"""Upload a new model and overwrite an existing model."""
|
|
@@ -502,16 +494,14 @@ def model_render(model_name, mapper_name):
|
|
|
_goto_mode(MODE_MODELLING)
|
|
|
|
|
|
_input(["model_render", model_name, mapper_name])
|
|
|
- return json.loads(_handle_output("Success: ", split=" "))
|
|
|
+ return json.loads(_handle_output("Success: ", split=True)[0])
|
|
|
|
|
|
def transformation_between(source, target):
|
|
|
_goto_mode(MODE_MODELLING)
|
|
|
|
|
|
_input(["transformation_between", source, target])
|
|
|
- output = _handle_output("Success: ", split=" ")
|
|
|
- if output == "":
|
|
|
- return set([])
|
|
|
- return set([v for v in output.split("\n")])
|
|
|
+ output = _handle_output("Success: ", split=True)
|
|
|
+ return set(output)
|
|
|
|
|
|
def transformation_add_MT(source_metamodels, target_metamodels, operation_name, code, callback=lambda: None):
|
|
|
"""Create a new model transformation."""
|
|
@@ -673,13 +663,10 @@ def transformation_list():
|
|
|
_goto_mode(MODE_MODELLING)
|
|
|
|
|
|
_input("transformation_list")
|
|
|
- output = _handle_output("Success: ", split=" ")
|
|
|
- if output == "":
|
|
|
- return set([])
|
|
|
+ output = _handle_output("Success: ", split=True)
|
|
|
|
|
|
lst = set([])
|
|
|
- value = output.strip().split("\n")
|
|
|
- for v in value:
|
|
|
+ for v in output:
|
|
|
t, m = v.strip().split(" ", 1)
|
|
|
t = t[1:-1].strip()
|
|
|
m = m.strip().split(":")[0].strip()
|
|
@@ -801,10 +788,8 @@ def element_list(model_name):
|
|
|
|
|
|
_input("list_full")
|
|
|
lst = set([])
|
|
|
- output = _handle_output("Success: ", split=" ")
|
|
|
- if output == "":
|
|
|
- return set([])
|
|
|
- for v in output.split("\n"):
|
|
|
+ output = _handle_output("Success: ", split=True)
|
|
|
+ for v in output:
|
|
|
m, mm = v.split(":")
|
|
|
m = m.strip()
|
|
|
mm = mm.strip()
|
|
@@ -817,10 +802,8 @@ def types(model_name):
|
|
|
|
|
|
_input("types")
|
|
|
lst = set([])
|
|
|
- output = _handle_output("Success: ", split=" ")
|
|
|
- if output == "":
|
|
|
- return set([])
|
|
|
- for v in output.split("\n"):
|
|
|
+ output = _handle_output("Success: ", split=True)
|
|
|
+ for v in output:
|
|
|
m, mm = v.split(":")
|
|
|
m = m.strip()
|
|
|
lst.add(m)
|
|
@@ -832,10 +815,8 @@ def types_full(model_name):
|
|
|
|
|
|
_input("types")
|
|
|
lst = set([])
|
|
|
- output = _handle_output("Success: ", split=" ")
|
|
|
- if output == "":
|
|
|
- return set([])
|
|
|
- for v in output.split("\n"):
|
|
|
+ output = _handle_output("Success: ", split=True)
|
|
|
+ for v in output:
|
|
|
m, mm = v.split(":")
|
|
|
m = m.strip()
|
|
|
mm = mm.strip()
|
|
@@ -847,8 +828,7 @@ def read(model_name, ID):
|
|
|
_goto_mode(MODE_MODIFY, model_name)
|
|
|
|
|
|
_input(["read", ID])
|
|
|
- output = _handle_output("Success: ", split=" ")
|
|
|
- v = output.split("\n")
|
|
|
+ v = _handle_output("Success: ", split=True)
|
|
|
t = v[1].split(":")[1].strip()
|
|
|
if (not v[2].startswith("Source:")):
|
|
|
rval = (t, None)
|
|
@@ -863,11 +843,10 @@ def read_attrs(model_name, ID):
|
|
|
_goto_mode(MODE_MODIFY, model_name)
|
|
|
|
|
|
_input(["read", ID])
|
|
|
- output = _handle_output("Success: ", split=" ")
|
|
|
- v = output.split("\n")
|
|
|
+ output = _handle_output("Success: ", split=True)
|
|
|
searching = True
|
|
|
rval = {}
|
|
|
- for r in v:
|
|
|
+ for r in output:
|
|
|
if searching:
|
|
|
if r == "Attributes:":
|
|
|
# Start working on attributes
|
|
@@ -896,7 +875,7 @@ def instantiate(model_name, typename, edge=None, ID=""):
|
|
|
_input(["instantiate_node", typename, ID])
|
|
|
else:
|
|
|
_input(["instantiate_edge", typename, ID, edge[0], edge[1]])
|
|
|
- return _handle_output("Success: ", split=" ")
|
|
|
+ return _handle_output("Success: ", split=True)[0]
|
|
|
|
|
|
def delete_element(model_name, ID):
|
|
|
"""Delete the element with the given ID"""
|
|
@@ -940,36 +919,30 @@ def read_outgoing(model_name, ID, typename):
|
|
|
_goto_mode(MODE_MODIFY, model_name)
|
|
|
|
|
|
_input(["read_outgoing", ID, typename])
|
|
|
- output = _handle_output("Success: ", split=" ")
|
|
|
- if output == "":
|
|
|
- return set([])
|
|
|
- else:
|
|
|
- return set(output.split("\n"))
|
|
|
+ output = _handle_output("Success: ", split=True)
|
|
|
+ return set(output)
|
|
|
|
|
|
def read_incoming(model_name, ID, typename):
|
|
|
"""Returns a list of all incoming associations of a specific type ("" = all)"""
|
|
|
_goto_mode(MODE_MODIFY, model_name)
|
|
|
|
|
|
_input(["read_incoming", ID, typename])
|
|
|
- output = _handle_output("Success: ", split=" ")
|
|
|
- if output == "":
|
|
|
- return set([])
|
|
|
- else:
|
|
|
- return set(output.split("\n"))
|
|
|
+ output = _handle_output("Success: ", split=True)
|
|
|
+ return set(output)
|
|
|
|
|
|
def read_association_source(model_name, ID):
|
|
|
"""Returns the source of an association."""
|
|
|
_goto_mode(MODE_MODIFY, model_name)
|
|
|
|
|
|
_input(["read_association_source", ID])
|
|
|
- return _handle_output("Success: ", split=" ")
|
|
|
+ return _handle_output("Success: ", split=True)[0]
|
|
|
|
|
|
def read_association_destination(model_name, ID):
|
|
|
"""Returns the destination of an association."""
|
|
|
_goto_mode(MODE_MODIFY, model_name)
|
|
|
|
|
|
_input(["read_association_destination", ID])
|
|
|
- return _handle_output("Success: ", split=" ")
|
|
|
+ return _handle_output("Success: ", split=True)[0]
|
|
|
|
|
|
##### To document:
|
|
|
|
|
@@ -989,7 +962,7 @@ def service_register(name, function):
|
|
|
|
|
|
# Now we are in service-mode
|
|
|
mode = MODE_SERVICE
|
|
|
- port = _handle_output("Success: ", split=" ")
|
|
|
+ port = _handle_output("Success: ", split=True)[0]
|
|
|
|
|
|
# Process events in the background!
|
|
|
threading.Thread(target=service_process, args=[port]).start()
|
|
@@ -1030,7 +1003,7 @@ def element_list_nice(model_name):
|
|
|
|
|
|
_input(["element_list_nice", model_name, _get_metamodel(model_name)])
|
|
|
|
|
|
- data = _handle_output("Success: ", split=" ")
|
|
|
+ data = _handle_output("Success: ", split=True)[0]
|
|
|
try:
|
|
|
return json.loads(data)
|
|
|
except:
|
|
@@ -1042,29 +1015,23 @@ def connections_between(model_name, source_element, target_element):
|
|
|
_goto_mode(MODE_MODIFY, model_name)
|
|
|
|
|
|
_input(["connections_between", source_element, target_element])
|
|
|
- output = _handle_output("Success: ", split=" ")
|
|
|
- if output == "":
|
|
|
- return set([])
|
|
|
- else:
|
|
|
- return set(output.split("\n"))
|
|
|
+ output = _handle_output("Success: ", split=True)
|
|
|
+ return set(output)
|
|
|
|
|
|
def define_attribute(model_name, node, attr_name, attr_type):
|
|
|
"""Create a new attribute, which can be instantiated one meta-level below."""
|
|
|
_goto_mode(MODE_MODIFY, model_name)
|
|
|
|
|
|
_input(["define_attribute", node, attr_name, attr_type])
|
|
|
- return _handle_output("Success: ", split=" ")
|
|
|
+ return _handle_output("Success: ", split=True)[0]
|
|
|
|
|
|
def all_instances(model_name, type_name):
|
|
|
"""Returns a list of all elements of a specific type."""
|
|
|
_goto_mode(MODE_MODIFY, model_name)
|
|
|
|
|
|
_input(["all_instances", type_name])
|
|
|
- output = _handle_output("Success: ", split=" ")
|
|
|
- if output == "":
|
|
|
- return set([])
|
|
|
- else:
|
|
|
- return set(output.split("\n"))
|
|
|
+ output = _handle_output("Success: ", split=True)
|
|
|
+ return set(output)
|
|
|
|
|
|
def service_poll(port):
|
|
|
"""Checks whether or not the Modelverse side has any input ready to be processed."""
|