File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 )
You can’t perform that action at this time.
0 commit comments