def getTmpPathForName(self, name, extension=None, copyFromCache=False, path_relative_to_tmp=''):
'Returns the tmp path for a file, and a flag indicating if the file exists. Will also check in the cache and copy to tmp if copyFromCache==True'
unicodeName = unicode(name)
dir_path = os.path.join(self.getTmpProjectPath(), path_relative_to_tmp)
if not os.path.isdir(dir_path):
os.makedirs(dir_path)
slugifiedName = ".".join([slugify(unicodeName), extension]) if extension else slugify(unicodeName)
tmpPath = os.path.join(dir_path, slugifiedName)
fileExists = False
if os.path.isfile(tmpPath):
# file already exists in tmp path, return path and exists flag
fileExists = True
elif copyFromCache:
# See if the file exists in cache, and copy over to project folder.
cacheFilePath = os.path.join(self.getCachePath(), slugifiedName)
if os.path.isfile(cacheFilePath):
shutil.copy(cacheFilePath, tmpPath)
fileExists = True
return (tmpPath, fileExists)
评论列表
文章目录