Skip to content

Commit 3a3c9a5

Browse files
committed
[OMCPath] add implementation using OMC via sendExpression()
1 parent de1949f commit 3a3c9a5

1 file changed

Lines changed: 20 additions & 5 deletions

File tree

OMPython/OMCSession.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -282,12 +282,27 @@ def with_segments(self, *pathsegments):
282282
# overwrite this function of PurePosixPath to ensure session is set
283283
return type(self)(*pathsegments, session=self._session)
284284

285+
def is_file(self) -> bool:
286+
return self._session.sendExpression(f'regularFileExists("{self.as_posix()}")')
287+
288+
def is_dir(self) -> bool:
289+
return self._session.sendExpression(f'directoryExists("{self.as_posix()}")')
290+
291+
def read_text(self) -> str:
292+
return self._session.sendExpression(f'readFile("{self.as_posix()}")')
293+
294+
def write_text(self, data: str) -> bool:
295+
return self._session.sendExpression(f'writeFile("{self.as_posix()}", "{data}", false)')
296+
297+
def unlink(self) -> bool:
298+
return self._session.sendExpression(f'deleteFile("{self.as_posix()}")')
299+
285300
# TODO: implement needed methods from pathlib._abc.PathBase:
286-
# is_dir()
287-
# is_file()
288-
# read_text() + binary()?
289-
# write_text() + binary()?
290-
# unlink()
301+
# OK - is_dir()
302+
# OK - is_file()
303+
# OK - read_text() + binary()?
304+
# OK - write_text() + binary()?
305+
# OK - unlink()
291306
# resolve()
292307
# ... more ...
293308
# ??? test if local (write OMC => READ local and the other way) and use shortcuts ???

0 commit comments

Comments
 (0)