Skip to content

Commit

Permalink
Add log level and command line options to simulation server (#953)
Browse files Browse the repository at this point in the history
  • Loading branch information
lochel committed Feb 17, 2021
1 parent ac94aaf commit 5bf0755
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
19 changes: 16 additions & 3 deletions src/OMSimulatorPython/NewAPI.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,36 @@
from OMSimulator import Model, Scope, Types


def newModel(cref):
def newModel(cref: str):
status = Scope._capi.newModel(cref)
if Types.Status(status) == Types.Status.OK:
Scope._Scope.append(cref)
else:
raise Exception('error {}'.format(Types.Status(status)))
return Model(cref)

def importFile(file):
def importFile(file: str):
cref, status = Scope._capi.importFile(file)
if Types.Status(status) == Types.Status.OK:
Scope._Scope.append(cref)
else:
raise Exception('error {}'.format(Types.Status(status)))
return Model(cref)

def setTempDirectory(dir):
def setTempDirectory(dir: str):
status = Scope._capi.setTempDirectory(dir)
if Types.Status(status) != Types.Status.OK:
raise Exception('error {}'.format(Types.Status(status)))

def setCommandLineOption(cmd: str):
status = Scope._capi.setCommandLineOption(cmd)
if Types.Status(status) != Types.Status.OK:
raise Exception('error {}'.format(Types.Status(status)))

def setLoggingLevel(level: int):
if not isinstance(level, int):
raise Exception('bad argument: {}'.format(level))

status = Scope._capi.setLoggingLevel(level)
if Types.Status(status) != Types.Status.OK:
raise Exception('error {}'.format(Types.Status(status)))
4 changes: 4 additions & 0 deletions src/OMSimulatorServer/OMSimulatorServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ def _main():
parser.add_argument('--endpoint-pub', default=None, help='define the endpoint for the pub/sub communication')
parser.add_argument('--endpoint-rep', default=None, help='define the endpoint for the req/rep communication')
parser.add_argument('--model', default=None, required=True, help='define the model to simulate')
parser.add_argument('--logLevel', default=0, type=int, help='defines the logging level')
parser.add_argument('--option', default='', help='defines optional command line options')
parser.add_argument('--result-file', default=None, help='defines whether and if so to which file the results will be written')
parser.add_argument('--temp', default='./temp/', help='defines the temp directory')
args = parser.parse_args()
Expand All @@ -84,6 +86,8 @@ def _main():
else:
socket_sub = None

oms.setCommandLineOption(args.option)
oms.setLoggingLevel(args.logLevel)
oms.setTempDirectory(args.temp)
model = oms.importFile(args.model)

Expand Down

0 comments on commit 5bf0755

Please sign in to comment.