Skip to content

Commit b59e473

Browse files
committed
[OMCSessionZMQ] create a tempdir using omcpath_tempdir()
1 parent afb8511 commit b59e473

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

OMPython/OMCSession.py

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

490490
return OMCPath(*path, session=self)
491491

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

0 commit comments

Comments
 (0)