|
@@ -125,17 +125,17 @@ def _last_output():
|
|
|
def _handle_output(requested=None, split=None):
|
|
|
value = _output()
|
|
|
if value.startswith("Model exists: "):
|
|
|
- raise ModelExists()
|
|
|
+ raise ModelExists(value.split(": ", 1)[1])
|
|
|
elif value.startswith("Permission denied"):
|
|
|
- raise PermissionDenied()
|
|
|
+ raise PermissionDenied(value.split(": ", 1)[1])
|
|
|
elif value.startswith("Model not found: "):
|
|
|
- raise UnknownModel()
|
|
|
+ raise UnknownModel(value.split(": ", 1)[1])
|
|
|
elif value.startswith("Element not found: "):
|
|
|
- raise UnknownIdentifier()
|
|
|
+ raise UnknownIdentifier(value.split(": ", 1)[1])
|
|
|
elif value.startswith("Element exists: "):
|
|
|
- raise ElementExists()
|
|
|
+ raise ElementExists(value.split(": ", 1)[1])
|
|
|
elif value.startswith("Attribute not found: "):
|
|
|
- raise NoSuchAttribute()
|
|
|
+ raise NoSuchAttribute(value.split(": ", 1)[1])
|
|
|
elif requested is not None and value.startswith(requested):
|
|
|
if split is None:
|
|
|
return value
|
|
@@ -374,17 +374,54 @@ def transformation_add_MT():
|
|
|
"""Create a new model transformation."""
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
-def transformation_add_AL():
|
|
|
- """Create a new action language fragment."""
|
|
|
- raise NotImplementedError()
|
|
|
+def transformation_add_AL(source_metamodels, target_metamodels, operation_name, code):
|
|
|
+ """Create a new action language model, which can be executed."""
|
|
|
+ global mode
|
|
|
+ if mode != 2:
|
|
|
+ raise InvalidMode()
|
|
|
+
|
|
|
+ try:
|
|
|
+ compiled = _compile_AL(code)
|
|
|
+ except Exception as e:
|
|
|
+ raise CompilationError(e)
|
|
|
+
|
|
|
+ _input(["transformation_add_AL"] + source_metamodels + [""] + target_metamodels + [""] + [operation_name])
|
|
|
+ _handle_output("Waiting for code constructors...")
|
|
|
+ _input(compiled)
|
|
|
+ _output("Success")
|
|
|
|
|
|
def transformation_add_MANUAL():
|
|
|
"""Create a new manual model operation."""
|
|
|
raise NotImplementedError()
|
|
|
|
|
|
-def transformation_execute():
|
|
|
+def transformation_execute_AL(operation_name, input_models_dict, output_models_dict, callback=lambda i: None):
|
|
|
"""Execute an existing model operation."""
|
|
|
- raise NotImplementedError()
|
|
|
+ global mode
|
|
|
+ if mode != 2:
|
|
|
+ raise InvalidMode()
|
|
|
+
|
|
|
+ mv_dict_rep = []
|
|
|
+ for key, value in input_models_dict.items():
|
|
|
+ mv_dict_rep += [key, value]
|
|
|
+ mv_dict_rep += [""]
|
|
|
+ for key, value in output_models_dict.items():
|
|
|
+ mv_dict_rep += [key, value]
|
|
|
+ mv_dict_rep += [""]
|
|
|
+
|
|
|
+ _input(["transformation_execute", operation_name] + mv_dict_rep)
|
|
|
+ _handle_output("Success: ready for AL execution")
|
|
|
+
|
|
|
+ # We are now executing, so everything we get is part of the dialog, except if it is the string for transformation termination
|
|
|
+ while _output() not in ["Success", "Failure"]:
|
|
|
+ reply = callback(_last_output())
|
|
|
+ if reply is not None:
|
|
|
+ _input(reply)
|
|
|
+
|
|
|
+ # Got termination message, so we are done!
|
|
|
+ if _last_output() == "Success":
|
|
|
+ return True
|
|
|
+ else:
|
|
|
+ return False
|
|
|
|
|
|
def transformation_list():
|
|
|
"""List existing model operations."""
|
|
@@ -669,7 +706,7 @@ def attr_assign_code(model_name, ID, attr, code):
|
|
|
|
|
|
try:
|
|
|
_input(["attr_add", ID, attr])
|
|
|
- output = _handle_output("Waiting for code constructors...")
|
|
|
+ _handle_output("Waiting for code constructors...")
|
|
|
_input(compiled)
|
|
|
_output("Success")
|
|
|
finally:
|