Remove project path attribute from project class

This commit is contained in:
Veronica Berglyd Olsen
2022-11-06 00:39:30 +01:00
parent a75424e44b
commit 615ee2958a
7 changed files with 15 additions and 24 deletions
-2
View File
@@ -307,8 +307,6 @@ class ProjectBuilder:
if not project.storage.openProjectInPlace(projPath, newProject=True): if not project.storage.openProjectInPlace(projPath, newProject=True):
return False return False
project.projPath = projPath
lblNewProject = self.tr("New Project") lblNewProject = self.tr("New Project")
lblNewChapter = self.tr("New Chapter") lblNewChapter = self.tr("New Chapter")
lblNewScene = self.tr("New Scene") lblNewScene = self.tr("New Scene")
+7 -18
View File
@@ -83,7 +83,6 @@ class NWProject(QObject):
self.lockedBy = None # Data on which computer has the project open self.lockedBy = None # Data on which computer has the project open
# Class Settings # Class Settings
self.projPath = None # The full path to where the currently open project is saved
self.projDict = None # The spell check dictionary self.projDict = None # The spell check dictionary
self.projFiles = [] # A list of all files in the content folder on load self.projFiles = [] # A list of all files in the content folder on load
@@ -250,7 +249,6 @@ class NWProject(QObject):
self._data = NWProjectData(self) self._data = NWProjectData(self)
# Project Settings # Project Settings
self.projPath = None
self.projDict = None self.projDict = None
self.projFiles = [] self.projFiles = []
@@ -266,10 +264,7 @@ class NWProject(QObject):
if not self._storage.openProjectInPlace(projPath): if not self._storage.openProjectInPlace(projPath):
return False return False
# ToDo: These should not be set explicitly, and should stay as Path logger.info("Opening project: %s", projPath)
self.projPath = str(self._storage.runtimePath)
logger.info("Opening project: %s", self.projPath)
self.projDict = str(self._storage.getMetaFile(nwFiles.PROJ_DICT)) self.projDict = str(self._storage.getMetaFile(nwFiles.PROJ_DICT))
@@ -368,7 +363,7 @@ class NWProject(QObject):
# Update recent projects # Update recent projects
self.mainConf.updateRecentCache( self.mainConf.updateRecentCache(
self.projPath, self._data.name, sum(self._data.initCounts), time() self._storage.storagePath, self._data.name, sum(self._data.initCounts), time()
) )
self.mainConf.saveRecentCache() self.mainConf.saveRecentCache()
@@ -399,12 +394,6 @@ class NWProject(QObject):
to make sure if the save fails, we're not left with a truncated to make sure if the save fails, we're not left with a truncated
file. file.
""" """
if self.projPath is None:
self.mainGui.makeAlert(self.tr(
"Project path not set, cannot save project."
), nwAlert.ERROR)
return False
if not self._storage.isOpen(): if not self._storage.isOpen():
self.mainGui.makeAlert(self.tr( self.mainGui.makeAlert(self.tr(
"There is no project open." "There is no project open."
@@ -413,7 +402,7 @@ class NWProject(QObject):
saveTime = time() saveTime = time()
logger.info("Saving project: %s", self.projPath) logger.info("Saving project: %s", self._storage.storagePath)
if autoSave: if autoSave:
self._data.incAutoCount() self._data.incAutoCount()
@@ -442,7 +431,7 @@ class NWProject(QObject):
# Update recent projects # Update recent projects
self.mainConf.updateRecentCache( self.mainConf.updateRecentCache(
self.projPath, self._data.name, sum(self._data.currCounts), saveTime self._storage.storagePath, self._data.name, sum(self._data.currCounts), saveTime
) )
self.mainConf.saveRecentCache() self.mainConf.saveRecentCache()
@@ -455,7 +444,7 @@ class NWProject(QObject):
def closeProject(self, idleTime=0.0): def closeProject(self, idleTime=0.0):
"""Close the current project and clear all meta data. """Close the current project and clear all meta data.
""" """
logger.info("Closing project: %s", self.projPath) logger.info("Closing project")
self._options.saveSettings() self._options.saveSettings()
self._tree.writeToCFile() self._tree.writeToCFile()
self._appendSessionStats(idleTime) self._appendSessionStats(idleTime)
@@ -517,7 +506,7 @@ class NWProject(QObject):
), nwAlert.ERROR, exception=exc) ), nwAlert.ERROR, exception=exc)
return False return False
if baseDir and baseDir.startswith(self.projPath): if baseDir and baseDir.startswith(str(self._storage.runtimePath)):
self.mainGui.makeAlert(self.tr( self.mainGui.makeAlert(self.tr(
"Cannot backup project because the backup path is within the " "Cannot backup project because the backup path is within the "
"project folder to be backed up. Please choose a different " "project folder to be backed up. Please choose a different "
@@ -530,7 +519,7 @@ class NWProject(QObject):
try: try:
self._storage.clearLockFile() self._storage.clearLockFile()
shutil.make_archive(baseName, "zip", self.projPath, ".") shutil.make_archive(baseName, "zip", self._storage.runtimePath, ".")
self._storage.writeLockFile() self._storage.writeLockFile()
logger.info("Backup written to: %s", archName) logger.info("Backup written to: %s", archName)
if doNotify: if doNotify:
+4
View File
@@ -67,6 +67,10 @@ class NWStorage:
# Properties # Properties
## ##
@property
def storagePath(self):
return self._storagePath
@property @property
def runtimePath(self): def runtimePath(self):
return self._runtimePath return self._runtimePath
+1 -1
View File
@@ -260,7 +260,7 @@ class GuiProjectDetailsMain(QWidget):
self.revCountVal.setText(f"{self.theProject.data.saveCount:n}") self.revCountVal.setText(f"{self.theProject.data.saveCount:n}")
self.editTimeVal.setText(f"{edTime//3600:02d}:{edTime%3600//60:02d}") self.editTimeVal.setText(f"{edTime//3600:02d}:{edTime%3600//60:02d}")
self.projPathVal.setText(self.theProject.projPath) self.projPathVal.setText(str(self.theProject.storage.storagePath))
return return
+1 -1
View File
@@ -1382,7 +1382,7 @@ class GuiMain(QMainWindow):
""" """
doSave = self.hasProject doSave = self.hasProject
doSave &= self.theProject.projChanged doSave &= self.theProject.projChanged
doSave &= self.theProject.projPath is not None doSave &= self.theProject.storage.isOpen()
if doSave: if doSave:
logger.debug("Autosaving project") logger.debug("Autosaving project")
+2 -1
View File
@@ -649,7 +649,8 @@ def testCoreProject_OrphanedFiles(mockGUI, nwLipsum):
writeFile(tstPath, "\n") writeFile(tstPath, "\n")
assert theProject.openProject(nwLipsum) assert theProject.openProject(nwLipsum)
assert theProject.projPath is not None assert theProject.storage.storagePath is not None
assert theProject.storage.runtimePath is not None
assert theProject.tree["636b6aa9b697bb"] is None assert theProject.tree["636b6aa9b697bb"] is None
assert theProject.tree["abcdefghijklm"] is None assert theProject.tree["abcdefghijklm"] is None
-1
View File
@@ -166,7 +166,6 @@ def buildTestProject(theObject, projPath):
theProject = theObject.theProject theProject = theObject.theProject
theProject.clearProject() theProject.clearProject()
theProject.projPath = projPath
theProject.storage.openProjectInPlace(projPath) theProject.storage.openProjectInPlace(projPath)
theProject.setDefaultStatusImport() theProject.setDefaultStatusImport()