Skip to content

Commit b1efdb1

Browse files
committed
[OMCSessionZMQ] create a tempdir using omcpath_tempdir()
1 parent 7a50441 commit b1efdb1

1 file changed

Lines changed: 24 additions & 0 deletions

File tree

OMPython/OMCSession.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -492,6 +492,30 @@ def omcpath(self, *path) -> OMCPath:
492492

493493
return OMCPath(*path, session=self)
494494

495+
def omcpath_tempdir(self) -> OMCPath:
496+
"""
497+
Get a temporary directory using OMC.
498+
"""
499+
names = [str(uuid.uuid4()) for _ in range(100)]
500+
501+
tempdir_str = self.sendExpression("getTempDirectoryPath()")
502+
tempdir_base = self.omcpath(tempdir_str)
503+
tempdir: Optional[OMCPath] = None
504+
for name in names:
505+
# create a unique temporary directory name
506+
tempdir = tempdir_base / name
507+
508+
if tempdir.exists():
509+
continue
510+
511+
tempdir.mkdir(parents=True, exist_ok=False)
512+
break
513+
514+
if tempdir is None or not tempdir.is_dir():
515+
raise OMCSessionException("Cannot create a temporary directory!")
516+
517+
return tempdir
518+
495519
def execute(self, command: str):
496520
warnings.warn("This function is depreciated and will be removed in future versions; "
497521
"please use sendExpression() instead", DeprecationWarning, stacklevel=2)

0 commit comments

Comments
 (0)