Skip to content

Commit 7a54e57

Browse files
committed
[OMCSessionZMQ] move file to Compat_v400
1 parent 3802b05 commit 7a54e57

4 files changed

Lines changed: 101 additions & 86 deletions

File tree

OMPython/Compat_v400/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
"""
55

66
from OMPython.Compat_v400.omc_session_cmd import OMCSessionCmd
7+
from OMPython.Compat_v400.omc_session_zmq import OMCSessionZMQ
78

89
__all__ = [
910
'OMCSessionCmd',
11+
'OMCSessionZMQ',
1012
]
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# -*- coding: utf-8 -*-
2+
"""
3+
Definition of class OMSessionZMQ - compatibility class
4+
"""
5+
6+
from __future__ import annotations
7+
8+
import logging
9+
from typing import Any, Optional
10+
import warnings
11+
12+
from OMPython.Base import (
13+
OMPathABC,
14+
15+
OMSessionABC,
16+
OMSessionException,
17+
)
18+
from OMPython.OMC import (
19+
OMCSessionABC,
20+
OMCSessionLocal,
21+
)
22+
23+
# define logger using the current module name as ID
24+
logger = logging.getLogger(__name__)
25+
26+
27+
class OMCSessionZMQ(OMSessionABC):
28+
"""
29+
This class is a compatibility layer for the new schema using OMCSession* classes.
30+
"""
31+
32+
def __init__(
33+
self,
34+
timeout: float = 10.00,
35+
omhome: Optional[str] = None,
36+
omc_process: Optional[OMCSessionABC] = None,
37+
) -> None:
38+
"""
39+
Initialisation for OMCSessionZMQ
40+
"""
41+
warnings.warn(message="The class OMCSessionZMQ is depreciated and will be removed in future versions; "
42+
"please use OMCProcess* classes instead!",
43+
category=DeprecationWarning,
44+
stacklevel=2)
45+
46+
if omc_process is None:
47+
omc_process = OMCSessionLocal(omhome=omhome, timeout=timeout)
48+
elif not isinstance(omc_process, OMCSessionABC):
49+
raise OMSessionException("Invalid definition of the OMC process!")
50+
self.omc_process = omc_process
51+
52+
super().__init__(timeout=timeout)
53+
54+
def __del__(self):
55+
if hasattr(self, 'omc_process'):
56+
del self.omc_process
57+
58+
@staticmethod
59+
def escape_str(value: str) -> str:
60+
"""
61+
Escape a string such that it can be used as string within OMC expressions, i.e. escape all double quotes.
62+
"""
63+
return OMCSessionABC.escape_str(value=value)
64+
65+
def omcpath(self, *path) -> OMPathABC:
66+
"""
67+
Create an OMCPath object based on the given path segments and the current OMC process definition.
68+
"""
69+
return self.omc_process.omcpath(*path)
70+
71+
def omcpath_tempdir(self, tempdir_base: Optional[OMPathABC] = None) -> OMPathABC:
72+
"""
73+
Get a temporary directory using OMC. It is our own implementation as non-local usage relies on OMC to run all
74+
filesystem related access.
75+
"""
76+
return self.omc_process.omcpath_tempdir(tempdir_base=tempdir_base)
77+
78+
def execute(self, command: str):
79+
return self.omc_process.execute(command=command)
80+
81+
def sendExpression(self, command: str, parsed: bool = True) -> Any:
82+
"""
83+
Send an expression to the OMC server and return the result.
84+
85+
The complete error handling of the OMC result is done within this method using 'getMessagesStringInternal()'.
86+
Caller should only check for OMCSessionException.
87+
"""
88+
return self.omc_process.sendExpression(expr=command, parsed=parsed)
89+
90+
def get_version(self) -> str:
91+
return self.omc_process.get_version()
92+
93+
def model_execution_prefix(self, cwd: Optional[OMPathABC] = None) -> list[str]:
94+
return self.omc_process.model_execution_prefix(cwd=cwd)
95+
96+
def set_workdir(self, workdir: OMPathABC) -> None:
97+
return self.omc_process.set_workdir(workdir=workdir)

OMPython/OMCSession.py

Lines changed: 0 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,9 @@
66
from __future__ import annotations
77

88
import logging
9-
from typing import Any, Optional
10-
import warnings
119

12-
from OMPython.Base import (
13-
OMSessionException,
14-
OMSessionABC,
15-
OMPathABC,
16-
)
1710
from OMPython.OMC.omc_session import DockerPopen
1811
from OMPython.OMC import (
19-
OMCSessionABC,
2012
OMCSessionDocker,
2113
OMCSessionDockerContainer,
2214
OMCSessionLocal,
@@ -28,79 +20,6 @@
2820
logger = logging.getLogger(__name__)
2921

3022

31-
class OMCSessionZMQ(OMSessionABC):
32-
"""
33-
This class is a compatibility layer for the new schema using OMCSession* classes.
34-
"""
35-
36-
def __init__(
37-
self,
38-
timeout: float = 10.00,
39-
omhome: Optional[str] = None,
40-
omc_process: Optional[OMCSessionABC] = None,
41-
) -> None:
42-
"""
43-
Initialisation for OMCSessionZMQ
44-
"""
45-
warnings.warn(message="The class OMCSessionZMQ is depreciated and will be removed in future versions; "
46-
"please use OMCProcess* classes instead!",
47-
category=DeprecationWarning,
48-
stacklevel=2)
49-
50-
if omc_process is None:
51-
omc_process = OMCSessionLocal(omhome=omhome, timeout=timeout)
52-
elif not isinstance(omc_process, OMCSessionABC):
53-
raise OMSessionException("Invalid definition of the OMC process!")
54-
self.omc_process = omc_process
55-
56-
super().__init__(timeout=timeout)
57-
58-
def __del__(self):
59-
if hasattr(self, 'omc_process'):
60-
del self.omc_process
61-
62-
@staticmethod
63-
def escape_str(value: str) -> str:
64-
"""
65-
Escape a string such that it can be used as string within OMC expressions, i.e. escape all double quotes.
66-
"""
67-
return OMCSessionABC.escape_str(value=value)
68-
69-
def omcpath(self, *path) -> OMPathABC:
70-
"""
71-
Create an OMCPath object based on the given path segments and the current OMC process definition.
72-
"""
73-
return self.omc_process.omcpath(*path)
74-
75-
def omcpath_tempdir(self, tempdir_base: Optional[OMPathABC] = None) -> OMPathABC:
76-
"""
77-
Get a temporary directory using OMC. It is our own implementation as non-local usage relies on OMC to run all
78-
filesystem related access.
79-
"""
80-
return self.omc_process.omcpath_tempdir(tempdir_base=tempdir_base)
81-
82-
def execute(self, command: str):
83-
return self.omc_process.execute(command=command)
84-
85-
def sendExpression(self, command: str, parsed: bool = True) -> Any:
86-
"""
87-
Send an expression to the OMC server and return the result.
88-
89-
The complete error handling of the OMC result is done within this method using '"getMessagesStringInternal()'.
90-
Caller should only check for OMCSessionException.
91-
"""
92-
return self.omc_process.sendExpression(expr=command, parsed=parsed)
93-
94-
def get_version(self) -> str:
95-
return self.omc_process.get_version()
96-
97-
def model_execution_prefix(self, cwd: Optional[OMPathABC] = None) -> list[str]:
98-
return self.omc_process.model_execution_prefix(cwd=cwd)
99-
100-
def set_workdir(self, workdir: OMPathABC) -> None:
101-
return self.omc_process.set_workdir(workdir=workdir)
102-
103-
10423
DummyPopen = DockerPopen
10524
OMCProcessLocal = OMCSessionLocal
10625
OMCProcessPort = OMCSessionPort

OMPython/__init__.py

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
)
2323
from OMPython.Compat_v400 import (
2424
OMCSessionCmd,
25+
OMCSessionZMQ,
2526
)
2627
from OMPython.OMC import (
2728
OMCPath,
@@ -56,9 +57,6 @@
5657
ModelicaSystemCmd,
5758
)
5859
from OMPython.OMCSession import (
59-
60-
OMCSessionZMQ,
61-
6260
OMCProcessLocal,
6361
OMCProcessPort,
6462
OMCProcessDocker,
@@ -80,6 +78,7 @@
8078
'OMCPath',
8179

8280
'OMCSessionCmd',
81+
'OMCSessionZMQ',
8382

8483
'OMCSessionABC',
8584
'OMCSessionDocker',
@@ -106,8 +105,6 @@
106105
'OMPathRunnerBash',
107106
'OMPathRunnerLocal',
108107

109-
'OMCSessionZMQ',
110-
111108
'OMCProcessLocal',
112109
'OMCProcessPort',
113110
'OMCProcessDocker',

0 commit comments

Comments
 (0)