Fix missing data path issue (#1180)
This commit is contained in:
+20
-1
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user