|
6 | 6 | from __future__ import annotations |
7 | 7 |
|
8 | 8 | import logging |
9 | | -from typing import Any, Optional |
10 | | -import warnings |
11 | 9 |
|
12 | | -from OMPython.Base import ( |
13 | | - OMSessionException, |
14 | | - OMSessionABC, |
15 | | - OMPathABC, |
16 | | -) |
17 | 10 | from OMPython.OMC.omc_session import DockerPopen |
18 | 11 | from OMPython.OMC import ( |
19 | | - OMCSessionABC, |
20 | 12 | OMCSessionDocker, |
21 | 13 | OMCSessionDockerContainer, |
22 | 14 | OMCSessionLocal, |
|
28 | 20 | logger = logging.getLogger(__name__) |
29 | 21 |
|
30 | 22 |
|
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 | | - |
104 | 23 | DummyPopen = DockerPopen |
105 | 24 | OMCProcessLocal = OMCSessionLocal |
106 | 25 | OMCProcessPort = OMCSessionPort |
|
0 commit comments