|
@@ -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
|