Skip to content

Commit 8230f67

Browse files
authored
Some more code cleanups (#258)
* cleanup old code for Python 2.x * fix OMCSessionBase - the variables self.readonly and self.omc_cache are needed here * [ModelicaSystem] fix True in docstring
1 parent f838239 commit 8230f67

File tree

1 file changed

+11
-12
lines changed

1 file changed

+11
-12
lines changed

OMPython/__init__.py

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@
3232
import warnings
3333

3434

35-
if sys.platform == 'darwin':
36-
# On Mac let's assume omc is installed here and there might be a broken omniORB installed in a bad place
37-
sys.path.append('/opt/local/lib/python2.7/site-packages/')
38-
sys.path.append('/opt/openmodelica/lib/python2.7/site-packages/')
39-
4035
# TODO: replace this with the new parser
4136
from OMPython import OMTypedParser, OMParser
4237

@@ -103,6 +98,10 @@ def wait(self, timeout):
10398

10499
class OMCSessionBase(metaclass=abc.ABCMeta):
105100

101+
def __init__(self, readonly=False):
102+
self._readonly = readonly
103+
self._omc_cache = {}
104+
106105
def clearOMParserResult(self):
107106
OMParser.result = {}
108107

@@ -130,10 +129,10 @@ def sendExpression(self, command, parsed=True):
130129
def ask(self, question, opt=None, parsed=True):
131130
p = (question, opt, parsed)
132131

133-
if self.readonly and question != 'getErrorString':
132+
if self._readonly and question != 'getErrorString':
134133
# can use cache if readonly
135-
if p in self.omc_cache:
136-
return self.omc_cache[p]
134+
if p in self._omc_cache:
135+
return self._omc_cache[p]
137136

138137
if opt:
139138
expression = f'{question}({opt})'
@@ -149,7 +148,7 @@ def ask(self, question, opt=None, parsed=True):
149148
raise
150149

151150
# save response
152-
self.omc_cache[p] = res
151+
self._omc_cache[p] = res
153152

154153
return res
155154

@@ -334,10 +333,10 @@ def __init__(self, readonly=False, timeout=10.00,
334333
if dockerExtraArgs is None:
335334
dockerExtraArgs = []
336335

336+
super().__init__(readonly=readonly)
337+
337338
self.omhome = self._get_omhome(omhome=omhome)
338339

339-
self.readonly = readonly
340-
self.omc_cache = {}
341340
self._omc_process = None
342341
self._omc_command = None
343342
self._omc = None
@@ -1466,7 +1465,7 @@ def convertMo2Fmu(self, version="2.0", fmuType="me_cs", fileNamePrefix="<default
14661465
with arguments of https://build.openmodelica.org/Documentation/OpenModelica.Scripting.translateModelFMU.html
14671466
usage
14681467
>>> convertMo2Fmu()
1469-
>>> convertMo2Fmu(version="2.0", fmuType="me|cs|me_cs", fileNamePrefix="<default>", includeResources=true)
1468+
>>> convertMo2Fmu(version="2.0", fmuType="me|cs|me_cs", fileNamePrefix="<default>", includeResources=True)
14701469
"""
14711470

14721471
if fileNamePrefix == "<default>":

0 commit comments

Comments
 (0)