Skip to content

Commit 7856740

Browse files
authored
Always call getErrorString() when verbose=True (#203)
* Always call getErrorString() when verbose=True If verbose=False then only call getErrorString() in case of failure. * Improve
1 parent 1fcbcac commit 7856740

File tree

1 file changed

+11
-20
lines changed

1 file changed

+11
-20
lines changed

OMPython/__init__.py

Lines changed: 11 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,7 @@ def __init__(self, fileName=None, modelName=None, lmodel=[], useCorba=False, com
859859
self.setTempDirectory()
860860

861861
if fileName is not None:
862-
self.loadFile()
862+
self.loadFile(verbose)
863863
self.loadLibrary(verbose)
864864

865865
## allow directly loading models from MSL without fileName
@@ -879,11 +879,12 @@ def setCommandLineOptions(self):
879879
if not cmdexp:
880880
return print(self.getconn.sendExpression("getErrorString()"))
881881

882-
def loadFile(self):
882+
def loadFile(self, verbose):
883883
# load file
884884
loadFileExp="".join(["loadFile(","\"",self.fileName,"\"",")"]).replace("\\","/")
885885
loadMsg = self.getconn.sendExpression(loadFileExp)
886-
if not loadMsg:
886+
## Show notification or warnings to the user when verbose=True OR if some error occurred i.e., not result
887+
if verbose or not loadMsg:
887888
return print(self.getconn.sendExpression("getErrorString()"))
888889

889890
# for loading file/package, loading model and building model
@@ -893,31 +894,21 @@ def loadLibrary(self, verbose):
893894
if element is not None:
894895
if isinstance(element, str):
895896
if element.endswith(".mo"):
896-
loadModelResult = self.requestApi("loadFile", element)
897-
if not loadModelResult:
898-
loadmodelError = self.requestApi('getErrorString')
899-
## always print the notification warning to user, to suppress the warnings add verbose=False
900-
if verbose:
901-
print(self.requestApi('getErrorString'))
897+
apiCall = "loadFile"
902898
else:
903-
loadModelResult = self.requestApi("loadModel", element)
904-
if not loadModelResult:
905-
loadmodelError = self.requestApi('getErrorString')
906-
if verbose:
907-
print(self.requestApi('getErrorString'))
908-
899+
apiCall = "loadModel"
900+
result = self.requestApi(apiCall, element)
909901
elif isinstance(element, tuple):
910902
if not element[1]:
911903
libname = "".join(["loadModel(", element[0], ")"])
912904
else:
913905
libname = "".join(["loadModel(", element[0], ", ", "{", "\"", element[1], "\"", "}", ")"])
914-
loadModelResult = self.sendExpression(libname)
915-
if not loadModelResult:
916-
loadmodelError = self.sendExpression("getErrorString()")
917-
if verbose:
918-
print(self.requestApi('getErrorString'))
906+
result = self.sendExpression(libname)
919907
else:
920908
print("| info | loadLibrary() failed, Unknown type detected: ", element , " is of type ", type(element), ", The following patterns are supported\n1)[\"Modelica\"]\n2)[(\"Modelica\",\"3.2.3\"), \"PowerSystems\"]\n")
909+
## Show notification or warnings to the user when verbose=True OR if some error occurred i.e., not result
910+
if verbose or not result:
911+
print(self.requestApi('getErrorString'))
921912

922913
def setTempDirectory(self):
923914
# create a unique temp directory for each session and build the model in that directory

0 commit comments

Comments
 (0)