Skip to content

Commit cb281ba

Browse files
committed
??? [ModelicaSystem] remove verbose - use logger.debug
1 parent e2e3957 commit cb281ba

File tree

1 file changed

+11
-14
lines changed

1 file changed

+11
-14
lines changed

OMPython/ModelicaSystem.py

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,6 @@ def __init__(
130130
commandLineOptions: Optional[str] = None,
131131
variableFilter: Optional[str] = None,
132132
customBuildDirectory: Optional[str | os.PathLike] = None,
133-
verbose: bool = True,
134133
omhome: Optional[str] = None,
135134
session: Optional[OMCSessionBase] = None
136135
):
@@ -157,7 +156,6 @@ def __init__(
157156
customBuildDirectory: Path to a directory to be used for temporary
158157
files like the model executable. If left unspecified, a tmp
159158
directory will be created.
160-
verbose: If True, enable verbose logging.
161159
omhome: OPENMODELICAHOME value to be used when creating the OMC
162160
session.
163161
session: OMC session to be used. If unspecified, a new session
@@ -187,8 +185,6 @@ def __init__(
187185
self.linearstates = [] # linearization states list
188186
self.tempdir = ""
189187

190-
self._verbose = verbose
191-
192188
if session is not None:
193189
if not isinstance(session, OMCSessionZMQ):
194190
raise ModelicaSystemError("Invalid session data provided!")
@@ -314,12 +310,13 @@ def _run_cmd(self, cmd: list, timeout: Optional[int] = None):
314310
timeout=timeout)
315311
stdout = cmdres.stdout.strip()
316312
stderr = cmdres.stderr.strip()
313+
314+
logger.debug("OM output for command %s:\n%s", cmd, stdout)
315+
317316
if cmdres.returncode != 0:
318317
raise ModelicaSystemError(f"Error running command {cmd}: nonzero return code")
319318
if stderr:
320319
raise ModelicaSystemError(f"Error running command {cmd}: {stderr}")
321-
if self._verbose and stdout:
322-
logger.info("OM output for command %s:\n%s", cmd, stdout)
323320
except subprocess.TimeoutExpired:
324321
raise ModelicaSystemError(f"Timeout running command {repr(cmd)}")
325322
except Exception as ex:
@@ -335,8 +332,7 @@ def buildModel(self, variableFilter=None):
335332
varFilter = 'variableFilter=".*"'
336333
logger.debug("varFilter=%s", varFilter)
337334
buildModelResult = self.requestApi("buildModel", self.modelName, properties=varFilter)
338-
if self._verbose:
339-
logger.info("OM model build result: %s", buildModelResult)
335+
logger.debug("OM model build result: %s", buildModelResult)
340336

341337
self.xmlFile = pathlib.Path(buildModelResult[0]).parent / buildModelResult[1]
342338
self.xmlparse()
@@ -346,6 +342,9 @@ def sendExpression(self, expr, parsed=True):
346342
retval = self.getconn.sendExpression(expr, parsed)
347343
except OMCSessionException as ex:
348344
raise ModelicaSystemError(f"Error executing {repr(expr)}") from ex
345+
346+
logger.debug(f"Result of executing {repr(expr)}: {repr(retval)}")
347+
349348
return retval
350349

351350
# request to OMC
@@ -838,12 +837,10 @@ def setParameters(self, pvals): # 14
838837
def isParameterChangeable(self, name, value):
839838
q = self.getQuantities(name)
840839
if q[0]["changeable"] == "false":
841-
if self._verbose:
842-
logger.info("setParameters() failed : It is not possible to set "
843-
f'the following signal "{name}", It seems to be structural, final, '
844-
"protected or evaluated or has a non-constant binding, use sendExpression("
845-
f"setParameterValue({self.modelName}, {name}, {value}), "
846-
"parsed=false) and rebuild the model using buildModel() API")
840+
logger.verbose(f"setParameters() failed : It is not possible to set the following signal {repr(name)}. "
841+
"It seems to be structural, final, protected or evaluated or has a non-constant binding, "
842+
f"use sendExpression(\"setParameterValue({self.modelName}, {name}, {value})\", "
843+
"parsed=False) and rebuild the model using buildModel() API")
847844
return False
848845
return True
849846

0 commit comments

Comments
 (0)