Fix missing data path issue (#1180)

This commit is contained in:
Veronica Berglyd Olsen
2022-10-18 20:43:33 +02:00
parent d232b22501
commit 33b95b60e3
5 changed files with 90 additions and 123 deletions
+20 -1
View File
@@ -35,7 +35,7 @@ from PyQt5.QtCore import QCoreApplication
from PyQt5.QtWidgets import qApp
from novelwriter.enum import nwItemClass, nwItemType, nwItemLayout
from novelwriter.error import logException
from novelwriter.error import formatException, logException
from novelwriter.constants import nwConst, nwUnicode
logger = logging.getLogger(__name__)
@@ -475,6 +475,25 @@ def makeFileNameSafe(value):
return cleanName
def ensureFolder(dirPath, parentPath=None, errLog=None):
"""Make sure a folder exists, and if it doesn't, create it.
"""
try:
if parentPath:
dirPath = os.path.join(parentPath, dirPath)
if not os.path.isdir(dirPath):
os.mkdir(dirPath)
except Exception as exc:
logger.error("Could not create folder: %s", dirPath)
logException()
if isinstance(errLog, list):
errLog.append(f"Could not create folder: {dirPath}")
errLog.append(formatException(exc))
return False
return True
def sha256sum(filePath):
"""Make a shasum of a file using a buffer.
Based on: https://stackoverflow.com/a/44873382/5825851