Remove project cache attribute from project class
This commit is contained in:
@@ -85,7 +85,6 @@ class NWProject(QObject):
|
||||
|
||||
# Class Settings
|
||||
self.projPath = None # The full path to where the currently open project is saved
|
||||
self.projCache = None # The full path to the project's cache folder
|
||||
self.projContent = None # The full path to the project's content folder
|
||||
self.projDict = None # The spell check dictionary
|
||||
self.projFiles = [] # A list of all files in the content folder on load
|
||||
@@ -254,7 +253,6 @@ class NWProject(QObject):
|
||||
|
||||
# Project Settings
|
||||
self.projPath = None
|
||||
self.projCache = None
|
||||
self.projContent = None
|
||||
self.projDict = None
|
||||
self.projFiles = []
|
||||
@@ -274,7 +272,6 @@ class NWProject(QObject):
|
||||
# ToDo: These should not be set explicitly, and should stay as Path
|
||||
self.projPath = str(self._storage.runtimePath)
|
||||
self.projContent = str(self._storage.contentPath)
|
||||
self.projCache = str(self._storage.cachePath)
|
||||
|
||||
logger.info("Opening project: %s", self.projPath)
|
||||
|
||||
@@ -478,15 +475,12 @@ class NWProject(QObject):
|
||||
if self.projPath is None or self.projPath == "":
|
||||
return False
|
||||
|
||||
self.projCache = os.path.join(self.projPath, "cache")
|
||||
self.projContent = os.path.join(self.projPath, "content")
|
||||
|
||||
if self.projPath == os.path.expanduser("~"):
|
||||
# Don't make a mess in the user's home folder
|
||||
return False
|
||||
|
||||
if not self._checkFolder(self.projCache):
|
||||
return False
|
||||
if not self._checkFolder(self.projContent):
|
||||
return False
|
||||
|
||||
|
||||
@@ -76,18 +76,6 @@ class NWStorage:
|
||||
return self._runtimePath / "content"
|
||||
return None
|
||||
|
||||
@property
|
||||
def metaPath(self):
|
||||
if self._runtimePath is not None:
|
||||
return self._runtimePath / "meta"
|
||||
return None
|
||||
|
||||
@property
|
||||
def cachePath(self):
|
||||
if self._runtimePath is not None:
|
||||
return self._runtimePath / "cache"
|
||||
return None
|
||||
|
||||
##
|
||||
# Core Methods
|
||||
##
|
||||
@@ -172,6 +160,13 @@ class NWStorage:
|
||||
return self._runtimePath / "meta" / fileName
|
||||
return None
|
||||
|
||||
def getCacheFile(self, fileName):
|
||||
"""Return the path to a file in the project cache folder.
|
||||
"""
|
||||
if self._runtimePath is not None:
|
||||
return self._runtimePath / "cache" / fileName
|
||||
return None
|
||||
|
||||
def readLockFile(self):
|
||||
"""Read the project lock file.
|
||||
"""
|
||||
|
||||
@@ -29,6 +29,7 @@ import logging
|
||||
import novelwriter
|
||||
|
||||
from time import time
|
||||
from pathlib import Path
|
||||
from datetime import datetime
|
||||
|
||||
from PyQt5.QtGui import (
|
||||
@@ -1088,9 +1089,12 @@ class GuiBuildNovel(QDialog):
|
||||
def _loadCache(self):
|
||||
"""Save the current data to cache.
|
||||
"""
|
||||
buildCache = os.path.join(self.theProject.projCache, nwFiles.BUILD_CACHE)
|
||||
buildCache = self.theProject.storage.getCacheFile(nwFiles.BUILD_CACHE)
|
||||
if not isinstance(buildCache, Path):
|
||||
return False
|
||||
|
||||
dataCount = 0
|
||||
if os.path.isfile(buildCache):
|
||||
if buildCache.exists():
|
||||
logger.debug("Loading build cache")
|
||||
try:
|
||||
with open(buildCache, mode="r", encoding="utf-8") as inFile:
|
||||
@@ -1115,7 +1119,10 @@ class GuiBuildNovel(QDialog):
|
||||
def _saveCache(self):
|
||||
"""Save the current data to cache.
|
||||
"""
|
||||
buildCache = os.path.join(self.theProject.projCache, nwFiles.BUILD_CACHE)
|
||||
buildCache = self.theProject.storage.getCacheFile(nwFiles.BUILD_CACHE)
|
||||
if not isinstance(buildCache, Path):
|
||||
return False
|
||||
|
||||
logger.debug("Saving build cache")
|
||||
try:
|
||||
with open(buildCache, mode="w+", encoding="utf-8") as outFile:
|
||||
|
||||
@@ -287,12 +287,6 @@ def testCoreProject_Helpers(monkeypatch, fncDir, mockGUI):
|
||||
mp.setattr("os.path.expanduser", lambda *a, **k: fncDir)
|
||||
assert theProject.ensureFolderStructure() is False
|
||||
|
||||
# Create a file to block cache folder
|
||||
cacheDir = os.path.join(fncDir, "cache")
|
||||
writeFile(cacheDir, "stuff")
|
||||
assert theProject.ensureFolderStructure() is False
|
||||
os.unlink(cacheDir)
|
||||
|
||||
# Create a file to block content folder
|
||||
contentDir = os.path.join(fncDir, "content")
|
||||
writeFile(contentDir, "stuff")
|
||||
@@ -301,8 +295,6 @@ def testCoreProject_Helpers(monkeypatch, fncDir, mockGUI):
|
||||
|
||||
# Now, do it right
|
||||
assert theProject.ensureFolderStructure() is True
|
||||
# assert os.path.isdir(metaDir)
|
||||
assert os.path.isdir(cacheDir)
|
||||
assert os.path.isdir(contentDir)
|
||||
|
||||
# END Test testCoreProject_Helpers
|
||||
|
||||
Reference in New Issue
Block a user