def createTempDirectory(self): tempDir = qt.QDir(self.getTempDirectoryBase()) tempDirName = qt.QDateTime().currentDateTime().toString("yyyyMMdd_hhmmss_zzz") fileInfo = qt.QFileInfo(qt.QDir(tempDir), tempDirName) dirPath = fileInfo.absoluteFilePath() qt.QDir().mkpath(dirPath) return dirPath
def tempDirectory(self,key='__SlicerTestTemp__',tempDir=None,includeDateTime=False): """Come up with a unique directory name in the temp dir and make it and return it # TODO: switch to QTemporaryDir in Qt5. Note: this directory is not automatically cleaned up """ if not tempDir: tempDir = qt.QDir(slicer.app.temporaryPath) tempDirName = key if includeDateTime: key += qt.QDateTime().currentDateTime().toString("yyyy-MM-dd_hh+mm+ss.zzz") fileInfo = qt.QFileInfo(qt.QDir(tempDir), tempDirName) dirPath = fileInfo.absoluteFilePath() qt.QDir().mkpath(dirPath) return dirPath
def createTempDirectory(self, bySlicer=True): if bySlicer: import qt, slicer tempDir = qt.QDir(self.getTempDirectoryBase(bySlicer)) tempDirName = qt.QDateTime().currentDateTime().toString( "yyyyMMdd_hhmmss_zzz") fileInfo = qt.QFileInfo(qt.QDir(tempDir), tempDirName) dirPath = fileInfo.absoluteFilePath() qt.QDir().mkpath(dirPath) # Write inputs inputDir = os.path.join(dirPath, 'input') qt.QDir().mkpath(inputDir) resultTransformDir = os.path.join(dirPath, 'result-transform') qt.QDir().mkpath(resultTransformDir) resultResampleDir = os.path.join(dirPath, 'result-resample') qt.QDir().mkpath(resultResampleDir) return dirPath, inputDir, resultTransformDir, resultResampleDir