Skip to content

Commit de1949f

Browse files
committed
[OMCPath] add class
1 parent 5394e94 commit de1949f

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

OMPython/OMCSession.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,31 @@ def getClassNames(self, className=None, recursive=False, qualified=False, sort=F
268268
return self._ask(question='getClassNames', opt=opt)
269269

270270

271+
class OMCPath(pathlib.PurePosixPath):
272+
"""
273+
Implementation of a basic Path object which uses OMC as backend. The connection to OMC is provided via a
274+
OMCSessionZMQ session object.
275+
"""
276+
277+
def __init__(self, *path, session: OMCSessionZMQ):
278+
super().__init__(*path)
279+
self._session = session
280+
281+
def with_segments(self, *pathsegments):
282+
# overwrite this function of PurePosixPath to ensure session is set
283+
return type(self)(*pathsegments, session=self._session)
284+
285+
# TODO: implement needed methods from pathlib._abc.PathBase:
286+
# is_dir()
287+
# is_file()
288+
# read_text() + binary()?
289+
# write_text() + binary()?
290+
# unlink()
291+
# resolve()
292+
# ... more ...
293+
# ??? test if local (write OMC => READ local and the other way) and use shortcuts ???
294+
295+
271296
class OMCSessionZMQ:
272297

273298
def __init__(
@@ -322,6 +347,9 @@ def __del__(self):
322347

323348
self.omc_zmq = None
324349

350+
def omcpath(self, *path) -> OMCPath:
351+
return OMCPath(*path, session=self)
352+
325353
def execute(self, command: str):
326354
warnings.warn("This function is depreciated and will be removed in future versions; "
327355
"please use sendExpression() instead", DeprecationWarning, stacklevel=2)

0 commit comments

Comments
 (0)