Skip to content

Commit 086f7b5

Browse files
committed
[ModelicaSystemCmd] move handling of simflags info this class
1 parent ed7a160 commit 086f7b5

1 file changed

Lines changed: 22 additions & 31 deletions

File tree

OMPython/ModelicaSystem.py

Lines changed: 22 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,26 @@ def get_exe_file(self, tempdir, modelName) -> pathlib.Path:
189189
else:
190190
return pathlib.Path(tempdir) / modelName
191191

192+
def parse_simflags(self, simflags: str) -> dict:
193+
# add old style simulation arguments
194+
warnings.warn("The argument 'simflags' is depreciated and will be removed in future versions; "
195+
"please use 'simargs' instead", DeprecationWarning, stacklevel=2)
196+
197+
simargs = {}
198+
199+
args = [s for s in simflags.split(' ') if s]
200+
for arg in args:
201+
if arg[0] != '-':
202+
raise ModelicaSystemError(f"Invalid simulation flag: {arg}")
203+
arg = arg[1:]
204+
parts = arg.split('=')
205+
if len(parts) == 1:
206+
simargs[parts[0]] = None
207+
else:
208+
simargs[parts[0]] = '='.join(parts[1:])
209+
210+
return simargs
211+
192212

193213
class ModelicaSystem:
194214
def __init__(
@@ -708,23 +728,8 @@ def simulate(self, resultfile: Optional[str] = None, simflags: Optional[str] = N
708728
om_cmd.arg_set(key="r", val=self.resultfile)
709729

710730
# allow runtime simulation flags from user input
711-
# TODO: merge into ModelicaSystemCmd?
712731
if simflags is not None:
713-
# add old style simulation arguments
714-
warnings.warn("The argument simflags is depreciated and will be removed in future versions; "
715-
"please use simargs instead", DeprecationWarning, stacklevel=1)
716-
717-
args = [s for s in simflags.split(' ') if s]
718-
for arg in args:
719-
if arg[0] != '-':
720-
raise ModelicaSystemError(f"Invalid simulation flag: {arg}")
721-
arg = arg[1:]
722-
parts = arg.split('=')
723-
if len(parts) == 1:
724-
val = None
725-
else:
726-
val = '='.join(parts[1:])
727-
om_cmd.arg_set(key=parts[0], val=val)
732+
om_cmd.args_set(args=om_cmd.parse_simflags(simflags=simflags))
728733

729734
if simargs:
730735
om_cmd.args_set(args=simargs)
@@ -1122,22 +1127,8 @@ def linearize(self, lintime: Optional[float] = None, simflags: Optional[str] = N
11221127
om_cmd.arg_set(key="l", val=f"{lintime or self.linearOptions["stopTime"]}")
11231128

11241129
# allow runtime simulation flags from user input
1125-
# TODO: merge into ModelicaSystemCmd?
11261130
if simflags is not None:
1127-
# add old style simulation arguments
1128-
warnings.warn("The argument simflags is depreciated and will be removed in future versions; "
1129-
"please use simargs instead", DeprecationWarning, stacklevel=1)
1130-
1131-
args = [s for s in simflags.split(' ') if s]
1132-
for arg in args:
1133-
if arg[0] != '-':
1134-
raise ModelicaSystemError(f"Invalid simulation flag: {arg}")
1135-
parts = arg.split('=')
1136-
if len(parts) == 1:
1137-
val = None
1138-
else:
1139-
val = '='.join(parts[1:])
1140-
om_cmd.arg_set(key=parts[0], val=val)
1131+
om_cmd.args_set(args=om_cmd.parse_simflags(simflags=simflags))
11411132

11421133
if simargs:
11431134
om_cmd.args_set(args=simargs)

0 commit comments

Comments
 (0)