@@ -71,8 +71,8 @@ class OMCSessionCmd:
7171 Implementation of Open Modelica Compiler API functions. Depreciated!
7272 """
7373
74- def __init__ (self , session : OMCSessionABC , readonly : bool = False ):
75- if not isinstance (session , OMCSessionABC ):
74+ def __init__ (self , session : OMSessionABC , readonly : bool = False ):
75+ if not isinstance (session , OMSessionABC ):
7676 raise OMCSessionException ("Invalid OMC process definition!" )
7777 self ._session = session
7878 self ._readonly = readonly
@@ -629,70 +629,6 @@ def run(self) -> int:
629629 return returncode
630630
631631
632- # TODO: OMCSessionCMd => separate file; based on OMCSessionZMQ?
633-
634- class OMCSessionZMQ :
635- """
636- This class is a compatibility layer for the new schema using OMCSession* classes.
637- """
638-
639- def __init__ (
640- self ,
641- timeout : float = 10.00 ,
642- omhome : Optional [str ] = None ,
643- omc_process : Optional [OMCSessionABC ] = None ,
644- ) -> None :
645- """
646- Initialisation for OMCSessionZMQ
647- """
648- warnings .warn (message = "The class OMCSessionZMQ is depreciated and will be removed in future versions; "
649- "please use OMCProcess* classes instead!" ,
650- category = DeprecationWarning ,
651- stacklevel = 2 )
652-
653- if omc_process is None :
654- omc_process = OMCSessionLocal (omhome = omhome , timeout = timeout )
655- elif not isinstance (omc_process , OMCSessionABC ):
656- raise OMCSessionException ("Invalid definition of the OMC process!" )
657- self .omc_process = omc_process
658-
659- def __del__ (self ):
660- if hasattr (self , 'omc_process' ):
661- del self .omc_process
662-
663- @staticmethod
664- def escape_str (value : str ) -> str :
665- """
666- Escape a string such that it can be used as string within OMC expressions, i.e. escape all double quotes.
667- """
668- return OMCSessionABC .escape_str (value = value )
669-
670- def omcpath (self , * path ) -> OMPathABC :
671- """
672- Create an OMCPath object based on the given path segments and the current OMC process definition.
673- """
674- return self .omc_process .omcpath (* path )
675-
676- def omcpath_tempdir (self , tempdir_base : Optional [OMPathABC ] = None ) -> OMPathABC :
677- """
678- Get a temporary directory using OMC. It is our own implementation as non-local usage relies on OMC to run all
679- filesystem related access.
680- """
681- return self .omc_process .omcpath_tempdir (tempdir_base = tempdir_base )
682-
683- def execute (self , command : str ):
684- return self .omc_process .execute (command = command )
685-
686- def sendExpression (self , command : str , parsed : bool = True ) -> Any :
687- """
688- Send an expression to the OMC server and return the result.
689-
690- The complete error handling of the OMC result is done within this method using '"getMessagesStringInternal()'.
691- Caller should only check for OMCSessionException.
692- """
693- return self .omc_process .sendExpression (command = command , parsed = parsed )
694-
695-
696632class PostInitCaller (type ):
697633 """
698634 Metaclass definition to define a new function __post_init__() which is called after all __init__() functions where
@@ -1310,6 +1246,79 @@ def _omc_port_get(self) -> str:
13101246 return port
13111247
13121248
1249+ # TODO: OMCSessionCMd => separate file; based on OMCSessionZMQ?
1250+ class OMCSessionZMQ (OMSessionABC ):
1251+ """
1252+ This class is a compatibility layer for the new schema using OMCSession* classes.
1253+ """
1254+
1255+ def __init__ (
1256+ self ,
1257+ timeout : float = 10.00 ,
1258+ omhome : Optional [str ] = None ,
1259+ omc_process : Optional [OMCSessionABC ] = None ,
1260+ ) -> None :
1261+ """
1262+ Initialisation for OMCSessionZMQ
1263+ """
1264+ super ().__init__ (timeout = timeout )
1265+ warnings .warn (message = "The class OMCSessionZMQ is depreciated and will be removed in future versions; "
1266+ "please use OMCProcess* classes instead!" ,
1267+ category = DeprecationWarning ,
1268+ stacklevel = 2 )
1269+
1270+ if omc_process is None :
1271+ omc_process = OMCSessionLocal (omhome = omhome , timeout = timeout )
1272+ elif not isinstance (omc_process , OMCSessionABC ):
1273+ raise OMCSessionException ("Invalid definition of the OMC process!" )
1274+ self .omc_process = omc_process
1275+
1276+ def __del__ (self ):
1277+ if hasattr (self , 'omc_process' ):
1278+ del self .omc_process
1279+
1280+ @staticmethod
1281+ def escape_str (value : str ) -> str :
1282+ """
1283+ Escape a string such that it can be used as string within OMC expressions, i.e. escape all double quotes.
1284+ """
1285+ return OMCSessionABC .escape_str (value = value )
1286+
1287+ def omcpath (self , * path ) -> OMPathABC :
1288+ """
1289+ Create an OMCPath object based on the given path segments and the current OMC process definition.
1290+ """
1291+ return self .omc_process .omcpath (* path )
1292+
1293+ def omcpath_tempdir (self , tempdir_base : Optional [OMPathABC ] = None ) -> OMPathABC :
1294+ """
1295+ Get a temporary directory using OMC. It is our own implementation as non-local usage relies on OMC to run all
1296+ filesystem related access.
1297+ """
1298+ return self .omc_process .omcpath_tempdir (tempdir_base = tempdir_base )
1299+
1300+ def execute (self , command : str ):
1301+ return self .omc_process .execute (command = command )
1302+
1303+ def sendExpression (self , command : str , parsed : bool = True ) -> Any :
1304+ """
1305+ Send an expression to the OMC server and return the result.
1306+
1307+ The complete error handling of the OMC result is done within this method using '"getMessagesStringInternal()'.
1308+ Caller should only check for OMCSessionException.
1309+ """
1310+ return self .omc_process .sendExpression (command = command , parsed = parsed )
1311+
1312+ def get_version (self ) -> str :
1313+ return self .omc_process .get_version ()
1314+
1315+ def model_execution_prefix (self , cwd : Optional [OMPathABC ] = None ) -> list [str ]:
1316+ return self .omc_process .model_execution_prefix (cwd = cwd )
1317+
1318+ def set_workdir (self , workdir : OMPathABC ) -> None :
1319+ return self .omc_process .set_workdir (workdir = workdir )
1320+
1321+
13131322class OMCSessionDockerABC (OMCSessionABC , metaclass = abc .ABCMeta ):
13141323 """
13151324 Base class for OMCSession implementations which run the OMC server in a Docker container.
@@ -2159,3 +2168,11 @@ def omcpath_tempdir(self, tempdir_base: Optional[OMPathABC] = None) -> OMPathABC
21592168
21602169 def sendExpression (self , command : str , parsed : bool = True ) -> Any :
21612170 raise OMCSessionException (f"{ self .__class__ .__name__ } does not uses an OMC server!" )
2171+
2172+
2173+ DummyPopen = DockerPopen
2174+ OMCProcessLocal = OMCSessionLocal
2175+ OMCProcessPort = OMCSessionPort
2176+ OMCProcessDocker = OMCSessionDocker
2177+ OMCProcessDockerContainer = OMCSessionDockerContainer
2178+ OMCProcessWSL = OMCSessionWSL
0 commit comments