Browse Source

Updated wrapper for the new interface

Yentl Van Tendeloo 8 years ago
parent
commit
9c078bc780

+ 5 - 5
core/core_algorithm.alc

@@ -901,7 +901,7 @@ String function cmd_transformation_between(user_id : String, source_name : Strin
 			result = set_overlap(onSource, onTarget)
 
 			String r
-			r = ""
+			r = "Success: "
 			while (read_nr_out(result) > 0):
 				transformation = set_pop(result)
 				if (allow_read(user_id, transformation)):
@@ -983,7 +983,7 @@ String function cmd_model_render(user_id : String, model_name : String, mapper_n
 					tracability_model = get_full_model(get_model_id(tracability_name))
 
 					// Also output the resulting model
-					return JSON_print(get_full_model(get_model_id(rendered_name)))!
+					return "Success: " + JSON_print(get_full_model(get_model_id(rendered_name)))!
 				else:
 					return "Permission denied to model: " + mapper_name!
 			else:
@@ -1097,7 +1097,7 @@ String function cmd_verify(user_id : String, model_name : String):
 	if (model_id != ""):
 		if (allow_read(user_id, model_id)):
 			result = conformance_scd(get_full_model(model_id))
-			return result!
+			return "Success: " + result!
 		else:
 			return "Permission denied to model: " + model_name!
 	else:
@@ -1155,7 +1155,7 @@ String function cmd_model_list():
 	String result
 	String m
 
-	result = ""
+	result = "Success: "
 	models = allInstances(core, "Model")
 	while (read_nr_out(models) > 0):
 		m = set_pop(models)
@@ -1174,7 +1174,7 @@ String function cmd_model_list_full():
 	String type
 	String result
 
-	result = ""
+	result = "Success: "
 	models = allInstances(core, "Model")
 	while (read_nr_out(models) > 0):
 		m = set_pop(models)

+ 8 - 8
core/mini_modify.alc

@@ -136,7 +136,7 @@ String function cmd_attr_add(write : Boolean, model : Element, element_name : St
 			Element attrs
 			attrs = getAttributeList(model, element_name)
 			if (set_in(dict_keys(attrs), attr_name)):
-				instantiate_attribute(model, element_name, attr_name, input())
+				instantiate_attribute(model, element_name, attr_name, value)
 				return "Success"!
 			else:
 				return "Attribute not found: " + attr_name!
@@ -152,7 +152,7 @@ String function cmd_attr_add_code(write : Boolean, model : Element, element_name
 			attrs = getAttributeList(model, element_name)
 			if (set_in(dict_keys(attrs), attr_name)):
 				output("Waiting for code constructors...")
-				instantiate_attribute_code(model, element_name, attr_name, input())
+				instantiate_attribute_code(model, element_name, attr_name)
 				return "Success"!
 			else:
 				return "Attribute not found: " + attr_name!
@@ -192,7 +192,7 @@ String function cmd_list(model : Element):
 	String result
 	String typename
 
-	result = ""
+	result = "Success: "
 	keys_m = dict_keys(model["model"])
 	while (read_nr_out(keys_m) > 0):
 		v_m = set_pop(keys_m)
@@ -209,7 +209,7 @@ String function cmd_list_full(model : Element):
 	String result
 	String typename
 
-	result = ""
+	result = "Success: "
 	keys_m = dict_keys(model["model"])
 	while (read_nr_out(keys_m) > 0):
 		v_m = set_pop(keys_m)
@@ -223,7 +223,7 @@ String function cmd_read_outgoing(model : Element, element_name : String, type :
 	String result
 	Element elems
 
-	result = ""
+	result = "Success: "
 	if (dict_in(model["model"], element_name)):
 		elems = allOutgoingAssociationInstances(model, element_name, type)
 		while (read_nr_out(elems) > 0):
@@ -251,7 +251,7 @@ String function cmd_read(model : Element, element_name : String):
 	Element attr_keys
 	String attr_key
 
-	result = ""
+	result = "Success: "
 	if (dict_in(model["model"], element_name)):
 		result = ((result + "ID: ") + element_name) + "\n"
 		result = ((result + "Type: ") + read_type(model, element_name)) + "\n"
@@ -282,7 +282,7 @@ String function cmd_types(model : Element):
 	String result
 
 	keys_t = dict_keys(model["metamodel"]["model"])
-	result = ""
+	result = "Success: "
 	while (read_nr_out(keys_t) > 0):
 		v_t = set_pop(keys_t)
 		if (bool_not(string_startswith(v_t, "__"))):
@@ -364,7 +364,7 @@ Element function modify(model : Element, write : Boolean):
 		elif (cmd == "read"):
 			output(cmd_read(model, single_input("Name?")))
 		elif (cmd == "verify"):
-			output(conformance_scd(model))
+			output("Success: " + conformance_scd(model))
 		elif (cmd == "types"):
 			output(cmd_types(model))
 		elif (cmd == "retype"):

+ 1 - 1
interface/HUTN/includes/conformance_scd.alh

@@ -1,7 +1,7 @@
 Boolean function is_direct_instance(model: Element, instance: String, type: String)
 Boolean function is_nominal_instance(model: Element, instance: String, type: String)
 Boolean function is_nominal_subtype(metamodel : Element, subclass : String, superclass : String)
-Element function conformance_scd(model: Element)
+String function conformance_scd(model: Element)
 Element function set_model_constraints(model: Element, func: Element)
 Element function generate_bottom_type_mapping(model: Element)
 Element function set_copy(a : Element)

+ 179 - 418
wrappers/modelverse.py

@@ -5,10 +5,55 @@ import random
 from urllib2 import URLError
 import sys
 
+COMPILER_PATH = "interface/HUTN"
+
 # Bind to the compiler (might have to update path manually!)
-sys.path.append("interface/HUTN")
+sys.path.append(COMPILER_PATH)
 from hutn_compiler.compiler import main as do_compile
 
+# Exceptions
+class ModelverseException(Exception):
+    pass
+
+class UnknownException(ModelverseException):
+    pass
+
+class UnknownIdentifier(ModelverseException):
+    pass
+
+class UnknownType(ModelverseException):
+    pass
+
+class NotAnAssociation(ModelverseException):
+    pass
+
+class UnsupportedValue(ModelverseException):
+    pass
+
+class CompilationError(ModelverseException):
+    pass
+
+class NoSuchAttribute(ModelverseException):
+    pass
+
+class UnknownModel(ModelverseException):
+    pass
+
+class ConnectionError(ModelverseException):
+    pass
+
+class ModelExists(ModelverseException):
+    pass
+
+class PermissionDenied(ModelverseException):
+    pass
+
+class InvalidMode(ModelverseException):
+    pass
+
+class InterfaceMismatch(ModelverseException):
+    pass
+
 # Helper functions and configuration: do not use yourself!
 taskname = random.random()
 address = None
@@ -43,7 +88,7 @@ def _compile_AL(code):
         f.write(code)
         f.flush()
 
-    return do_compile("__constraint.alc", "interface/HUTN/grammars/actionlanguage.g", "CS")
+    return do_compile("__constraint.alc", COMPILER_PATH + "/grammars/actionlanguage.g", "CS")
 
 def _compile_model(code):
     # Compile a model and send the compiled graph
@@ -60,7 +105,7 @@ def _compile_model(code):
         f.write(code)
         f.flush()
 
-    return do_compile("__model.mvc", "interface/HUTN/grammars/modelling.g", "M") + ["exit"]
+    return do_compile("__model.mvc", COMPILER_PATH + "/grammars/modelling.g", "M") + ["exit"]
 
 def _output(expected=None):
     try:
@@ -76,49 +121,29 @@ def _output(expected=None):
 def _last_output():
     return last_output
 
-# Exceptions
-class ModelverseException(Exception):
-    pass
-
-class UnknownException(ModelverseException):
-    pass
-
-class UnknownIdentifier(ModelverseException):
-    pass
-
-class UnknownType(ModelverseException):
-    pass
-
-class NotAnAssociation(ModelverseException):
-    pass
-
-class UnsupportedValue(ModelverseException):
-    pass
-
-class CompilationError(ModelverseException):
-    pass
-
-class NoSuchAttribute(ModelverseException):
-    pass
-
-class UnknownModel(ModelverseException):
-    pass
-
-class ConnectionError(ModelverseException):
-    pass
-
-class ModelExists(ModelverseException):
-    pass
-
-class PermissionDenied(ModelverseException):
-    pass
-
-class InvalidMode(ModelverseException):
-    pass
-
-class InterfaceMismatch(ModelverseException):
-    pass
-
+# Raise common exceptions
+def _handle_output(requested=None, split=None):
+    value = _output()
+    if value.startswith("Model exists: "):
+        raise ModelExists()
+    elif value.startswith("Permission denied"):
+        raise PermissionDenied()
+    elif value.startswith("Model not found: "):
+        raise UnknownModel()
+    elif value.startswith("Element not found: "):
+        raise UnknownIdentifier()
+    elif value.startswith("Element exists: "):
+        raise ElementExists()
+    elif value.startswith("Attribute not found: "):
+        raise NoSuchAttribute()
+    elif requested is not None and value.startswith(requested):
+        if split is None:
+            return value
+        else:
+            return value.strip().split(split, 1)[1].rstrip()
+    else:
+        raise InterfaceMismatch(value)
+    
 # Main MvC operations
 def init(address_param="http://127.0.0.1:8001"):
     """Starts up the connection to the Modelverse."""
@@ -152,7 +177,7 @@ def login(username, password):
         _input(password)
         if _output() == "Welcome to the Model Management Interface v2.0!":
             _output("Use the 'help' command for a list of possible commands")
-            _output("Ready for command...")
+            _input("quiet")
             mode = 2
         elif _last_output() == "Wrong password!":
             raise PermissionDenied()
@@ -165,7 +190,7 @@ def login(username, password):
         if _output() == "Passwords match!":
             _output("Welcome to the Model Management Interface v2.0!")
             _output("Use the 'help' command for a list of possible commands")
-            _output("Ready for command...")
+            _input("quiet")
             mode = 2
         elif _last_output() == "Not the same password!":
             # We just sent the same password, so it should be identical, unless the interface changed
@@ -194,27 +219,10 @@ def model_add(model_name, metamodel_name, model_code=None):
     else:
         compiled = ["exit"]
 
-    _input("model_add")
-    _output("Creating new model!")
-    _output("Model type?")
-    _input(metamodel_name)
-    if _output() == "Model name?":
-        _input(model_name)
-        if _output() == "Waiting for model constructors...":
-            _input(compiled)
-            _output("Model upload success!")
-            _output("Ready for command...")
-        elif _last_output() == "Model with that name already exists!":
-            _output("Ready for command...")
-            raise ModelExists()
-        else:
-            raise InterfaceMismatch(_last_output())
-    elif _last_output().startswith("Could not find type model"):
-        _output("Ready for command...")
-        raise UnknownModel()
-    elif _last_output() == "Permission denied":
-        _output("Ready for command...")
-        raise PermissionDenied()
+    _input(["model_add", metamodel_name, model_name])
+    _handle_output("Waiting for model constructors...")
+    _input(compiled)
+    _output("Success")
 
 def model_modify(model_name):
     """Modify an existing model."""
@@ -226,26 +234,17 @@ def model_modify(model_name):
     if mode != 2:
         raise InvalidMode()
 
-    _input("model_modify")
-    _output("Which model do you want to modify?")
-    _input(model_name)
-    if _output() == "Permission denied":
-        _output("Ready for command...")
-        raise PermissionDenied()
-    elif _last_output() == "Could not find model!":
-        _output("Ready for command...")
-        raise UnknownModel()
-    elif _last_output() == "Model loaded, ready for commands!":
-        mode = 3
-        if ("r/w" in _output()):
-            write = True
-        else:
-            write = False
-        _output("Use 'help' command for a list of possible commands")
-        _output("Please give your command.")
-        return write
+    _input(["model_modify", model_name])
+    _handle_output("Success")
+    # Mode has changed
+    mode = 3
+    _output("Model loaded, ready for commands!")
+    if ("r/w" in _output()):
+        write = True
     else:
-        raise InterfaceMismatch()
+        write = False
+    _output("Use 'help' command for a list of possible commands")
+    return write
 
 def model_list():
     """List all models."""
@@ -254,13 +253,15 @@ def model_list():
     if mode != 2:
         raise InvalidMode()
     _input("model_list")
+    output = _handle_output("Success: ", split=" ")
     lst = []
-    while (_output() != "Ready for command..."):
-        v = _last_output()
+    value = output.strip().split("\n")
+    for v in value:
         m, mm = v.split(":")
         m = m.strip()
         mm = mm.strip()
         lst.append((m, mm))
+
     return lst
 
 def model_list_full():
@@ -271,13 +272,14 @@ def model_list_full():
         raise InvalidMode()
     _input("model_list_full")
     lst = []
-    while (_output() != "Ready for command..."):
-        v = _last_output()
+    value = _output().strip().split("\n")
+    for v in value:
         m, mm = v.split(":")
         m = m.strip()
         mm = mm.strip()
         perm, own, grp, m = m.split(" ")
         lst.append((m, mm, own, grp, perm))
+
     return lst
 
 def verify(model):
@@ -287,21 +289,8 @@ def verify(model):
     # raises UnknownModel
     if mode != 2:
         raise InvalidMode()
-    _input("verify")
-    _output("Which model to verify?")
-    _input(model)
-    if _output() == "Verifying model...":
-        result = _output()
-        _output("Ready for command...")
-        return result
-    elif _last_output() == "Permission denied":
-        _output("Ready for command...")
-        raise PermissionDenied()
-    elif _last_output() == "No such model":
-        _output("Ready for command...")
-        raise UnknownModel()
-    else:
-        raise InterfaceMismatch(_last_output())
+    _input(["verify", model])
+    return _handle_output("Success: ", split=" ")
 
 def model_overwrite(model_name, new_model=None):
     """Upload a new model and overwrite an existing model."""
@@ -321,19 +310,10 @@ def model_overwrite(model_name, new_model=None):
     else:
         compiled = ["exit"]
 
-    _input("model_overwrite")
-    _output("Which model to overwrite?")
-    _input(model_name)
-    if _output() == "Permission denied":
-        _output("Ready for command...")
-        raise PermissionDenied()
-    elif _last_output() == "No such model":
-        _output("Ready for command...")
-        raise UnknownModel()
-    elif _last_output() == "Waiting for model constructors...":
-        _input(compiled)
-        _output("Model overwrite success")
-        _output("Ready for command...")
+    _input(["model_overwrite", model_name])
+    _handle_output("Waiting for model constructors...")
+    _input(compiled)
+    _output("Success")
 
 def user_logout():
     """Log out the current user and break the connection."""
@@ -365,41 +345,17 @@ def model_render(model, mapper):
     if mode != 2:
         raise InvalidMode()
 
-    #TODO error handling!
-
-    _input("model_render")
-    _output()
-    _input(model)
-    _output()
-    _input(mapper)
-    _output("Mapping success")
-    rendered = _output()
-    _output("Ready for command...")
-    return rendered
+    _input(["model_render", model, mapper])
+    return _handle_output("Success: ", split=" ")
 
 def transformation_between(source, target):
     global mode
     if mode != 2:
         raise InvalidMode()
 
-    _input("transformation_between")
-    _output("Source metamodel?")
-    _input(source)
-    if _output() == "Target metamodel?":
-        _input(target)
-        if _output() == "Searching transformations...":
-            result = []
-            while _output() != "Ready for command...":
-                result.append(_last_output())
-            return result
-        elif _last_output() == "Target unknown!":
-            raise UnknownModel()
-        else:
-            raise InterfaceMismatch(_last_output())
-    elif _last_output() == "Source unknown!":
-        raise UnknownModel()
-    else:
-        raise InterfaceMismatch(_last_output())
+    _input(["transformation_between", source, target])
+    output = _handle_output("Success: ", split=" ")
+    lst = [v for v in output.split("\n")]
 
 def transformation_add_MT_language():
     """Create a new Model Transformation language out of a set of metamodels."""
@@ -502,9 +458,8 @@ def element_list(model_name):
     try:
         _input("list_full")
         lst = []
-        _output("List of all elements:")
-        while (_output() != "Please give your command."):
-            v = _last_output()
+        output = _handle_output("Success: ", split=" ")
+        for v in output.split("\n"):
             m, mm = v.split(":")
             m = m.strip()
             mm = mm.strip()
@@ -525,10 +480,9 @@ def types(model_name):
 
     try:
         _input("types")
-        _output("List of types:")
         lst = []
-        while (_output() != "Please give your command."):
-            v = _last_output()
+        output = _handle_output("Success: ", split=" ")
+        for v in output.split("\n"):
             m, mm = v.split(":")
             m = m.strip()
             lst.append(m)
@@ -548,10 +502,9 @@ def types_full(model_name):
 
     try:
         _input("types")
-        _output("List of types:")
         lst = []
-        while (_output() != "Please give your command."):
-            v = _last_output()
+        output = _handle_output("Success: ", split=" ")
+        for v in output.split("\n"):
             m, mm = v.split(":")
             m = m.strip()
             mm = mm.strip()
@@ -572,23 +525,17 @@ def read(model_name, ID):
         raise InvalidMode()
 
     try:
-        _input("read")
-        _output("Element to read?")
-        _input(ID)
-        if _output() == "Unknown element; aborting":
-            _output("Please give your command.")
-            raise UnknownIdentifier()
-        elif _last_output() == "ID: " + str(ID):
-            t = _output().split(":")[1].strip()
-            if (not _output().startswith("Source:")):
-                rval = (t, None)
-            else:
-                src = _last_output().split(":")[1].strip()
-                trg = _output().split(":")[1].strip()
-                rval = (t, (src, trg))
-            while (_output() != "Please give your command."):
-                pass
-            return rval
+        _input(["read", ID])
+        output = _handle_output("Success: ", split=" ")
+        v = output.split("\n")
+        t = v[1].split(":")[1].strip()
+        if (not v[0].startswith("Source:")):
+            rval = (t, None)
+        else:
+            src = v[0].split(":")[1].strip()
+            trg = v[1].split(":")[1].strip()
+            rval = (t, (src, trg))
+        return rval
 
     finally:
         model_exit()
@@ -603,39 +550,37 @@ def read_attrs(model_name, ID):
     if mode != 3:
         raise InvalidMode()
 
-    _input("read")
-    _output("Element to read?")
-    _input(ID)
-    if _output() == "Unknown element; aborting":
-        _output("Please give your command.")
-        model_exit()
-        raise UnknownIdentifier()
-    elif _last_output() == "ID: " + str(ID):
+    try:
+        _input(["read", ID])
+        output = _handle_output("Success: ", split=" ")
+        v = output.split("\n")
+        searching = True
         rval = {}
-        # Skip until attributes
-        while (_output() != "Attributes:"):
-            pass
-        while (_output() != "Please give your command."):
-            r = _last_output()
-            key, value = r.split(":", 1)
-            _, value = value.split("=", 1)
-            key = json.loads(key.strip())
-            value = value.strip()
-            if value == "None":
-                value = None
-            elif value == "True":
-                value = True
-            elif value == "False":
-                value = False
+        for r in v:
+            if searching:
+                if r == "Attributes:":
+                    # Start working on attributes
+                    searching = False
             else:
-                value = json.loads(value)
-            rval[key] = value
-        model_exit()
+                key, value = r.split(":", 1)
+                _, value = value.split("=", 1)
+                key = json.loads(key.strip())
+                value = value.strip()
+                if value == "None":
+                    value = None
+                elif value == "True":
+                    value = True
+                elif value == "False":
+                    value = False
+                else:
+                    value = json.loads(value)
+                rval[key] = value
         return rval
-    else:
-        raise InterfaceMismatch(_last_output())
 
-def instantiate(model_name, typename, edge=None, ID=""):
+    finally:
+        model_exit()
+
+def instantiate(model_name, typename, edge=None):
     """Create a new instance of the specified typename, between the selected elements (if not None), and with the provided ID (if any)"""
     # return instantiated_ID
     # raises UnknownError
@@ -648,69 +593,11 @@ def instantiate(model_name, typename, edge=None, ID=""):
         raise InvalidMode()
 
     try:
-        _input("instantiate")
-        if (_output() == "Permission denied"):
-            _output("Please give your command.")
-            raise PermissionDenied()
+        if edge is None:
+            _input(["instantiate_node", typename, ""])
         else:
-            _input(typename)
-            if (_output() == "Name of new element?"):
-                _input(ID)
-                if (_output() == "Element already exists; aborting"):
-                    _output("Please give your command.")
-                    raise ElementExists()
-
-                if (edge is not None) and (_last_output() == "Source name?"):
-                    # Is an edge and we have data
-                    _input(edge[0])
-                    if _output() == "Destination name?":
-                        _input(edge[1])
-                        if _output() == "Instantiation successful!":
-                            ID = _output()
-                            _output("Please give your command.")
-                            return ID
-                        elif _last_output() == "Unknown destination; aborting":
-                            _output("Please give your command.")
-                            raise UnknownIdentifier()
-                        else:
-                            raise InterfaceMismatch(_last_output())
-                    elif _last_output() == "Unknown source; aborting":
-                        _output("Please give your command.")
-                        raise UnknownIdentifier()
-                    else:
-                        raise InterfaceMismatch(_last_output())
-                elif (edge is None) and (_last_output() != "Source name?"):
-                    # Is no edge and we don't have data
-                    if _last_output() == "Instantiation successful!":
-                        ID = _output()
-                        _output("Please give your command.")
-                        return ID
-                    else:
-                        raise InterfaceMismatch(_last_output())
-                elif (edge is not None) and (_last_output() != "Source name?"):
-                    # Is no edge, but we have edge data to input: ERROR
-                    # Delete the element again
-                    ID = _last_output()
-                    _output("Please give your command.")
-                    delete_element(ID)
-                    raise NotAnEdge()
-                elif (edge is None) and (_last_output() == "Source name?"):
-                    # Is an edge, but we have no edge data to input: ERROR
-                    # Add an empty source, which is guaranteed not to be there
-                    _input("")
-                    _output("Unknown source; aborting")
-                    _output("Please give your command.")
-                    raise NotAnEdge()
-
-            elif (_last_output() == "Permission denied"):
-                _output("Please give your command.")
-                raise PermissionDenied()
-            elif (_last_output() == "Unknown type specified; aborting"):
-                _output("Please give your command.")
-                raise UnknownType()
-            else:
-                raise InterfaceMismatch(_last_output())
-
+            _input(["instantiate_edge", typename, "", edge[0], edge[1]])
+        return _handle_output("Success: ", split=" ")
     finally:
         model_exit()
 
@@ -725,22 +612,8 @@ def delete_element(model_name, ID):
         raise InvalidMode()
 
     try:
-        _input("delete")
-        if _output() == "What is the name of the element you want to delete?":
-            _input(ID)
-            if _output() == "Deleted!":
-                _output("Please give your command.")
-            elif _last_output() == "No such element; aborting":
-                _output("Please give your command.")
-                raise UnknownIdentifier()
-            else:
-                raise InterfaceMismatch(_last_output())
-        elif _last_output() == "Permission denied":
-            _output("Please give your command.")
-            raise PermissionDenied()
-        else:
-            raise InterfaceMismatch(_last_output())
-
+        _input(["delete", ID])
+        _handle_output("Success")
     finally:
         model_exit()
 
@@ -757,35 +630,15 @@ def attr_assign(model_name, ID, attr, value):
         raise InvalidMode()
 
     try:
-        _input("attr_add")
-        if _output() == "Which element do you want to assign an attribute to?":
-            _input(ID)
-            if _output() == "Which attribute do you wish to assign?":
-                _input(attr)
-                if _output() == "Value of attribute?":
-                    _input(value)
-                    _output("Added attribute!")
-                    _output("Please give your command.")
-                elif _last_output() == "No such attribute!":
-                    _output("Please give your command.")
-                    raise NoSuchAttribute()
-                else:
-                    raise InterfaceMismatch(_last_output())
-
-            elif _last_output() == "No such element!":
-                _output("Please give your command.")
-                raise UnknownIdentifier()
-            else:
-                raise InterfaceMismatch(_last_output())
-
-        elif _last_output() == "Permission denied":
-            _output("Please give your command.")
-            raise PermissionDenied()
-        else:
-            raise InterfaceMismatch(_last_output())
-
+        print("Assign")
+        _input(["attr_add", ID, attr, value])
+        print("PREP")
+        _handle_output("Success")
+        print("DONE")
     finally:
+        print("EXIT")
         model_exit()
+        print("OK")
 
 def attr_assign_code(model_name, ID, attr, code):
     """Assign a piece of Action Language code to the attribute"""
@@ -805,32 +658,10 @@ def attr_assign_code(model_name, ID, attr, code):
         raise InvalidMode()
 
     try:
-        _input("attr_add")
-        if _output() == "Which element do you want to assign an attribute to?":
-            _input(ID)
-            if _output() == "Which attribute do you want to assign?":
-                _input(attr)
-                if _output() == "Waiting for code constructors...":
-                    _input(compiled)
-                    _output("Added attribute!")
-                    _output("Please give your command.")
-                elif _last_output() == "No such attribute!":
-                    _output("Please give your command.")
-                    raise NoSuchAttribute()
-                else:
-                    raise InterfaceMismatch(_last_output())
-
-            elif _last_output() == "No such element!":
-                _output("Please give your command.")
-                raise UnknownIdentifier()
-            else:
-                raise InterfaceMismatch(_last_output())
-
-        elif _last_output() == "Permission denied":
-            _output("Please give your command.")
-            raise PermissionDenied()
-        else:
-            raise InterfaceMismatch(_last_output())
+        _input(["attr_add", ID, attr])
+        output = _handle_output("Waiting for code constructors...")
+        _input(compiled)
+        _output("Success")
     finally:
         model_exit()
 
@@ -842,29 +673,8 @@ def attr_delete(model_name, ID, attr):
         raise InvalidMode()
 
     try:
-        _input("attr_del")
-        if _output() == "Which element do you want to remove an attribute of?":
-            _input(ID)
-            if _output() == "Which attribute do you want to delete?":
-                _input(attr)
-                if _output() == "Attribute deleted!":
-                    _output("Please give your command.")
-                elif _last_output() == "No such attribute!":
-                    _output("Please give your command.")
-                    raise NoSuchAttribute()
-                else:
-                    raise InterfaceMismatch(_last_output())
-            elif _last_output() == "No such element!":
-                _output("Please give your command.")
-                raise UnknownIdentifier()
-            else:
-                raise InterfaceMismatch(_last_output())
-        elif _last_output() == "Permission denied":
-            _output("Please give your command.")
-            raise PermissionDenied()
-        else:
-            raise InterfaceMismatch(_last_output())
-
+        _input(["attr_del", ID, attr])
+        _handle_output("Success")
     finally:
         model_exit()
 
@@ -879,21 +689,9 @@ def read_outgoing(model_name, ID, typename):
         raise InvalidMode()
 
     try:
-        _input("read_outgoing")
-        _output("Element to read from?")
-        _input(ID)
-        if _output() == "Type of outgoing edge (empty for all)?":
-            _input(typename)
-            lst = []
-            while (_output() != "Please give your command."):
-                lst.append(_last_output())
-            return lst
-        elif _last_output() == "Unknown element; aborting":
-            _output("Please give your command.")
-            raise UnknownIdentifier()
-        else:
-            raise InterfaceMismatch()
-
+        _input(["read_outgoing", ID, typename])
+        output = _handle_output("Success: ", split=" ")
+        return output.split("\n")
     finally:
         model_exit()
 
@@ -909,20 +707,9 @@ def read_incoming(model_name, ID, typename):
         raise InvalidMode()
 
     try:
-        _input("read_incoming")
-        _output("Element to read from?")
-        _input(ID)
-        if _output() == "Type of incoming edge (empty for all)?":
-            _input(typename)
-            lst = []
-            while (_output() != "Please give your command."):
-                lst.append(_last_output())
-            return lst
-        elif _last_output() == "Unknown element; aborting":
-            _output("Please give your command.")
-            raise UnknownIdentifier()
-        else:
-            raise InterfaceMismatch()
+        _input(["read_incoming", ID, typename])
+        output = _handle_output("Success: ", split=" ")
+        return output.split("\n")
     finally:
         model_exit()
 
@@ -938,21 +725,8 @@ def read_association_source(model_name, ID):
         raise InvalidMode()
 
     try:
-        _input("read_association_source")
-        _output("Association to read source of?")
-        _input(ID)
-        if _output() == "Read source:":
-            result = _output()
-            _output("Please give your command.")
-            return result
-        elif _last_output() == "Unknown element; aborting":
-            _output("Please give your command.")
-            raise UnknownIdentifier()
-        elif _last_output() == "Not an association; aborting":
-            _output("Please give your command.")
-            raise NotAnEdge()
-        else:
-            raise InterfaceMismatch(_last_output())
+        _input(["read_association_source", ID])
+        return _handle_output("Success: ", split=" ")
     finally:
         model_exit()
 
@@ -968,21 +742,8 @@ def read_association_destination(model_name, ID):
         raise InvalidMode()
 
     try:
-        _input("read_association_destination")
-        _output("Association to read destination of?")
-        _input(ID)
-        if _output() == "Read destination:":
-            result = _output()
-            _output("Please give your command.")
-            return result
-        elif _last_output() == "Unknown element; aborting":
-            _output("Please give your command.")
-            raise UnknownIdentifier()
-        elif _last_output() == "Not an association; aborting":
-            _output("Please give your command.")
-            raise NotAnEdge()
-        else:
-            raise InterfaceMismatch(_last_output())
+        _input(["read_association_destination", ID])
+        return _handle_output("Success: ", split=" ")
     finally:
         model_exit()
 
@@ -994,5 +755,5 @@ def model_exit():
     if mode != 3:
         raise InvalidMode()
     _input("exit")
-    _output("Ready for command...")
+    _output("Success")
     mode = 2

+ 34 - 47
wrappers/test_modelverse.py

@@ -10,60 +10,47 @@ init()
 login(username, password)
 
 model_add(model_name, "SimpleClassDiagrams", open("models/petrinet_ports.mvc", "r").read())
-print(verify("SimpleClassDiagrams"))
-model_modify("SimpleClassDiagrams")
-print(element_list())
+print(verify(model_name))
+print(element_list(model_name))
+print(model_list())
+print(types(model_name))
 try:
-    print(model_list())
+    print(read("SimpleClassDiagrams", "Place"))
     raise Exception("ERROR")
-except InvalidMode:
-    print(types())
+except UnknownIdentifier:
+    print(read("SimpleClassDiagrams", "Class"))
     try:
-        print(read("Place"))
+        print(read_attrs("SimpleClassDiagrams", "Place"))
         raise Exception("ERROR")
     except UnknownIdentifier:
-        print(read("Class"))
+        print(read_attrs("SimpleClassDiagrams", "Class"))
         try:
-            print(read_attrs("Place"))
+            print(instantiate("SimpleClassDiagrams", "Class", None))
             raise Exception("ERROR")
-        except UnknownIdentifier:
-            print(read_attrs("Class"))
+        except PermissionDenied:
+            print(("abc", "Class") not in element_list("SimpleClassDiagrams"))
+            print(verify(model_name))
+            print(element_list(model_name))
+            print(instantiate(model_name, "Class", None))
+            print(("abc", "Class") in element_list(model_name))
+            model_add(model_name2, model_name)
+            p1 = instantiate(model_name2, "Place")
+            p2 = instantiate(model_name2, "Place")
+            t1 = instantiate(model_name2, "Transition")
+            p2t = instantiate(model_name2, "P2T", (p1, t1))
+            t2p = instantiate(model_name2, "T2P", (t1, p2))
+            print(element_list(model_name2))
+            print(read_attrs(model_name2, p1))
+            attr_assign(model_name2, p1, "name", "p1")
+            attr_assign(model_name2, p1, "tokens", 1)
+            print(read_attrs(model_name2, p1))
+            print(verify(model_name2))
+            attr_assign(model_name2, p2, "name", "p2")
+            attr_assign(model_name2, p2, "tokens", 3)
+            print(verify(model_name2))
+            attr_assign(model_name2, t1, "name", "t1")
             try:
-                print(instantiate("Class", None, "abc"))
+                attr_assign(model_name2, t2p, "weight", 2)
                 raise Exception("ERROR")
-            except PermissionDenied:
-                print(("abc", "Class") not in element_list())
-                model_exit()
-                print(verify(model_name))
-                model_modify(model_name)
-                print(element_list())
-                print(instantiate("Class", None, "abc"))
-                print(("abc", "Class") in element_list())
-                model_exit()
-                model_add(model_name2, model_name)
-                model_modify(model_name2)
-                p1 = instantiate("Place")
-                p2 = instantiate("Place")
-                t1 = instantiate("Transition")
-                p2t = instantiate("P2T", (p1, t1))
-                t2p = instantiate("T2P", (t1, p2))
-                print(element_list())
-                print(read_attrs(p1))
-                attr_assign(p1, "name", "p1")
-                attr_assign(p1, "tokens", 1)
-                print(read_attrs(p1))
-                model_exit()
+            except NoSuchAttribute:
                 print(verify(model_name2))
-                model_modify(model_name2)
-                attr_assign(p2, "name", "p2")
-                attr_assign(p2, "tokens", 3)
-                model_exit()
-                print(verify(model_name2))
-                model_modify(model_name2)
-                attr_assign(t1, "name", "t1")
-                try:
-                    attr_assign(t2p, "weight", 2)
-                    raise Exception("ERROR")
-                except NoSuchAttribute:
-                    model_exit()
-                    print(verify(model_name2))