From 783a849e09edd2c04defbcdf5a3e28793771984b Mon Sep 17 00:00:00 2001 From: Veronica Berglyd Olsen <1619840+vkbo@users.noreply.github.com> Date: Sat, 5 Nov 2022 16:19:19 +0100 Subject: [PATCH] Remove the old legacy format code --- novelwriter/core/project.py | 74 ---------- tests/conftest.py | 21 --- tests/oldproj/data_1/9752e7f9d8af_main.nwd | 4 - tests/oldproj/data_7/ff63b8afc4cd_main.nwd | 4 - tests/oldproj/data_8/8124a4292d8b_main.nwd | 4 - tests/oldproj/data_9/058ae29f0dfd_main.nwd | 4 - tests/oldproj/data_9/1239bf2f8b69_main.nwd | 4 - tests/oldproj/data_a/764d5acf5a21_main.nwd | 4 - tests/oldproj/data_f/528d831f5b24_main.nwd | 4 - tests/oldproj/meta/sessionInfo.log | 2 - tests/oldproj/meta/tagsIndex.json | 72 ---------- tests/oldproj/nwProject.nwx | 148 -------------------- tests/test_core/test_core_project.py | 151 --------------------- 13 files changed, 496 deletions(-) delete mode 100644 tests/oldproj/data_1/9752e7f9d8af_main.nwd delete mode 100644 tests/oldproj/data_7/ff63b8afc4cd_main.nwd delete mode 100644 tests/oldproj/data_8/8124a4292d8b_main.nwd delete mode 100644 tests/oldproj/data_9/058ae29f0dfd_main.nwd delete mode 100644 tests/oldproj/data_9/1239bf2f8b69_main.nwd delete mode 100644 tests/oldproj/data_a/764d5acf5a21_main.nwd delete mode 100644 tests/oldproj/data_f/528d831f5b24_main.nwd delete mode 100644 tests/oldproj/meta/sessionInfo.log delete mode 100644 tests/oldproj/meta/tagsIndex.json delete mode 100644 tests/oldproj/nwProject.nwx diff --git a/novelwriter/core/project.py b/novelwriter/core/project.py index 00a01ff6..85bba2fa 100644 --- a/novelwriter/core/project.py +++ b/novelwriter/core/project.py @@ -378,9 +378,6 @@ class NWProject(QObject): self._options.loadSettings() self._index.loadIndex() - # Clean up no longer used files - self._deprecatedFiles() - # Update recent projects self.mainConf.updateRecentCache( self.projPath, self._data.name, sum(self._data.initCounts), time() @@ -1046,77 +1043,6 @@ class NWProject(QObject): return True - ## - # Legacy Data Structure Handlers - ## - - def _legacyDataFolder(self, dataDir): - """Clean up legacy data folders. - """ - dataPath = os.path.join(self.projPath, dataDir) - if not os.path.isdir(dataPath): - return False - - logger.info("Old data folder found: %s", dataDir) - - # Move Documents to Content - for dataItem in os.listdir(dataPath): - dataFile = os.path.join(dataPath, dataItem) - if not os.path.isfile(dataFile): - continue - - if len(dataItem) == 21 and dataItem.endswith("_main.nwd"): - tHandle = dataDir[-1] + dataItem[:12] - newPath = os.path.join(self.projContent, f"{tHandle}.nwd") - os.rename(dataFile, newPath) - logger.info("Moved file: %s", dataFile) - - elif len(dataItem) == 21 and dataItem.endswith("_main.bak"): - os.unlink(dataFile) - logger.info("Deleted file: %s", dataFile) - - # Remove Data Folder - if not os.listdir(dataPath): - os.rmdir(dataPath) - logger.info("Deleted folder: %s", dataDir) - - return True - - def _deprecatedFiles(self): - """Delete files that are no longer used by novelWriter. - """ - rmList = [ - os.path.join(self.projCache, "nwProject.nwx.0"), - os.path.join(self.projCache, "nwProject.nwx.1"), - os.path.join(self.projCache, "nwProject.nwx.2"), - os.path.join(self.projCache, "nwProject.nwx.3"), - os.path.join(self.projCache, "nwProject.nwx.4"), - os.path.join(self.projCache, "nwProject.nwx.5"), - os.path.join(self.projCache, "nwProject.nwx.6"), - os.path.join(self.projCache, "nwProject.nwx.7"), - os.path.join(self.projCache, "nwProject.nwx.8"), - os.path.join(self.projCache, "nwProject.nwx.9"), - os.path.join(self.projMeta, "mainOptions.json"), - os.path.join(self.projMeta, "exportOptions.json"), - os.path.join(self.projMeta, "outlineOptions.json"), - os.path.join(self.projMeta, "timelineOptions.json"), - os.path.join(self.projMeta, "docMergeOptions.json"), - os.path.join(self.projMeta, "sessionLogOptions.json"), - os.path.join(self.projPath, "ToC.json"), - ] - - for rmFile in rmList: - if os.path.isfile(rmFile): - logger.info("Deleting: %s", rmFile) - try: - os.unlink(rmFile) - except Exception: - logger.error("Could not delete: %s", rmFile) - logException() - return False - - return True - # END Class NWProject diff --git a/tests/conftest.py b/tests/conftest.py index 33cd3574..758d46da 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -267,27 +267,6 @@ def nwLipsum(tmpDir): return -@pytest.fixture(scope="function") -def nwOldProj(tmpDir): - """A minimal movelWriter project using the old folder structure used - for storage versions < 1.2. - """ - tstDir = os.path.dirname(__file__) - srcDir = os.path.join(tstDir, "oldproj") - dstDir = os.path.join(tmpDir, "oldproj") - if os.path.isdir(dstDir): - shutil.rmtree(dstDir) - - shutil.copytree(srcDir, dstDir) - - yield dstDir - - if os.path.isdir(dstDir): - shutil.rmtree(dstDir) - - return - - @pytest.fixture(scope="session") def ipsumText(): """Return five paragraphs of Lorem Ipsum text. diff --git a/tests/oldproj/data_1/9752e7f9d8af_main.nwd b/tests/oldproj/data_1/9752e7f9d8af_main.nwd deleted file mode 100644 index 5b25ad52..00000000 --- a/tests/oldproj/data_1/9752e7f9d8af_main.nwd +++ /dev/null @@ -1,4 +0,0 @@ -### Scene Four - -Scene Four - diff --git a/tests/oldproj/data_7/ff63b8afc4cd_main.nwd b/tests/oldproj/data_7/ff63b8afc4cd_main.nwd deleted file mode 100644 index 818712f7..00000000 --- a/tests/oldproj/data_7/ff63b8afc4cd_main.nwd +++ /dev/null @@ -1,4 +0,0 @@ -# Antagonist - -Antagonist - diff --git a/tests/oldproj/data_8/8124a4292d8b_main.nwd b/tests/oldproj/data_8/8124a4292d8b_main.nwd deleted file mode 100644 index 5fe1d9fe..00000000 --- a/tests/oldproj/data_8/8124a4292d8b_main.nwd +++ /dev/null @@ -1,4 +0,0 @@ -### Scene Two - -Scene Two - diff --git a/tests/oldproj/data_9/058ae29f0dfd_main.nwd b/tests/oldproj/data_9/058ae29f0dfd_main.nwd deleted file mode 100644 index 79e4dc06..00000000 --- a/tests/oldproj/data_9/058ae29f0dfd_main.nwd +++ /dev/null @@ -1,4 +0,0 @@ -# Protagonist - -Protagonist - diff --git a/tests/oldproj/data_9/1239bf2f8b69_main.nwd b/tests/oldproj/data_9/1239bf2f8b69_main.nwd deleted file mode 100644 index 2d701cd4..00000000 --- a/tests/oldproj/data_9/1239bf2f8b69_main.nwd +++ /dev/null @@ -1,4 +0,0 @@ -### Scene Three - -Scene Three - diff --git a/tests/oldproj/data_a/764d5acf5a21_main.nwd b/tests/oldproj/data_a/764d5acf5a21_main.nwd deleted file mode 100644 index 7ef7c622..00000000 --- a/tests/oldproj/data_a/764d5acf5a21_main.nwd +++ /dev/null @@ -1,4 +0,0 @@ -### Scene Five - -Scene Five - diff --git a/tests/oldproj/data_f/528d831f5b24_main.nwd b/tests/oldproj/data_f/528d831f5b24_main.nwd deleted file mode 100644 index 8fecdb8e..00000000 --- a/tests/oldproj/data_f/528d831f5b24_main.nwd +++ /dev/null @@ -1,4 +0,0 @@ -### Scene One - -Scene One - diff --git a/tests/oldproj/meta/sessionInfo.log b/tests/oldproj/meta/sessionInfo.log deleted file mode 100644 index 92da5e9a..00000000 --- a/tests/oldproj/meta/sessionInfo.log +++ /dev/null @@ -1,2 +0,0 @@ -Start: 2020-09-26 16:13:00 End: 2020-09-26 16:15:54 Words: 24 -Start: 2020-09-26 16:16:28 End: 2020-09-26 16:16:40 Words: -1 diff --git a/tests/oldproj/meta/tagsIndex.json b/tests/oldproj/meta/tagsIndex.json deleted file mode 100644 index d02515f6..00000000 --- a/tests/oldproj/meta/tagsIndex.json +++ /dev/null @@ -1,72 +0,0 @@ -{ - "tagIndex": {}, - "refIndex": { - "f528d831f5b24": [], - "88124a4292d8b": [], - "91239bf2f8b69": [], - "19752e7f9d8af": [], - "a764d5acf5a21": [], - "9058ae29f0dfd": [], - "7ff63b8afc4cd": [] - }, - "novelIndex": { - "f528d831f5b24": [ - [ - 1, - 3, - "Scene One", - "SCENE" - ] - ], - "88124a4292d8b": [ - [ - 1, - 3, - "Scene Two", - "SCENE" - ] - ], - "91239bf2f8b69": [ - [ - 1, - 3, - "Scene Three", - "SCENE" - ] - ], - "19752e7f9d8af": [ - [ - 1, - 3, - "Scene Four", - "SCENE" - ] - ], - "a764d5acf5a21": [ - [ - 1, - 3, - "Scene Five", - "SCENE" - ] - ] - }, - "noteIndex": { - "9058ae29f0dfd": [ - [ - 1, - 1, - "Protagonist", - "NOTE" - ] - ], - "7ff63b8afc4cd": [ - [ - 1, - 1, - "Antagonist", - "NOTE" - ] - ] - } -} \ No newline at end of file diff --git a/tests/oldproj/nwProject.nwx b/tests/oldproj/nwProject.nwx deleted file mode 100644 index 8ba21098..00000000 --- a/tests/oldproj/nwProject.nwx +++ /dev/null @@ -1,148 +0,0 @@ - - - - - - True - - - False - a764d5acf5a21 - None - 23 - - - New - Note - Draft - Finished - - - New - Minor - Major - Main - - - - - Novel - ROOT - NOVEL - New - True - - - Chapter One - FOLDER - NOVEL - New - True - - - Scene One - FILE - NOVEL - New - False - SCENE - 18 - 4 - 1 - 3 - - - Scene Two - FILE - NOVEL - New - False - SCENE - 18 - 4 - 1 - 2 - - - Scene Three - FILE - NOVEL - New - False - SCENE - 22 - 4 - 1 - 2 - - - Scene Four - FILE - NOVEL - New - False - SCENE - 20 - 4 - 1 - 2 - - - Scene Five - FILE - NOVEL - New - False - SCENE - 20 - 4 - 1 - 2 - - - Characters - ROOT - CHARACTER - New - True - - - Protagonist - FILE - CHARACTER - New - False - NOTE - 11 - 1 - 0 - 28 - - - Antagonist - FILE - CHARACTER - New - False - NOTE - 13 - 2 - 1 - 26 - - - Plot - ROOT - PLOT - New - False - - - World - ROOT - WORLD - New - False - - - diff --git a/tests/test_core/test_core_project.py b/tests/test_core/test_core_project.py index 29e1a561..118c0cb7 100644 --- a/tests/test_core/test_core_project.py +++ b/tests/test_core/test_core_project.py @@ -812,157 +812,6 @@ def testCoreProject_OrphanedFiles(mockGUI, nwLipsum): # END Test testCoreProject_OrphanedFiles -@pytest.mark.core -def testCoreProject_OldFormat(mockGUI, nwOldProj): - """Test that a project folder structure of version 1.0 can be - converted to the latest folder structure. Version 1.0 split the - documents into 'data_0' ... 'data_f' folders, which are now all - contained in a single 'content' folder. - """ - theProject = NWProject(mockGUI) - - # Create mock files for known legacy files - deleteFiles = [ - os.path.join(nwOldProj, "cache", "nwProject.nwx.0"), - os.path.join(nwOldProj, "cache", "nwProject.nwx.1"), - os.path.join(nwOldProj, "cache", "nwProject.nwx.2"), - os.path.join(nwOldProj, "cache", "nwProject.nwx.3"), - os.path.join(nwOldProj, "cache", "nwProject.nwx.4"), - os.path.join(nwOldProj, "cache", "nwProject.nwx.5"), - os.path.join(nwOldProj, "cache", "nwProject.nwx.6"), - os.path.join(nwOldProj, "cache", "nwProject.nwx.7"), - os.path.join(nwOldProj, "cache", "nwProject.nwx.8"), - os.path.join(nwOldProj, "cache", "nwProject.nwx.9"), - os.path.join(nwOldProj, "meta", "mainOptions.json"), - os.path.join(nwOldProj, "meta", "exportOptions.json"), - os.path.join(nwOldProj, "meta", "outlineOptions.json"), - os.path.join(nwOldProj, "meta", "timelineOptions.json"), - os.path.join(nwOldProj, "meta", "docMergeOptions.json"), - os.path.join(nwOldProj, "meta", "sessionLogOptions.json"), - ] - - # Create mock files - os.mkdir(os.path.join(nwOldProj, "cache")) - for aFile in deleteFiles: - writeFile(aFile, "Hi") - for aFile in deleteFiles: - assert os.path.isfile(aFile) - - # Open project and check that files that are not supposed to be - # there have been removed - assert theProject.openProject(nwOldProj) - for aFile in deleteFiles: - assert not os.path.isfile(aFile) - - assert not os.path.isdir(os.path.join(nwOldProj, "data_1")) - assert not os.path.isdir(os.path.join(nwOldProj, "data_7")) - assert not os.path.isdir(os.path.join(nwOldProj, "data_8")) - assert not os.path.isdir(os.path.join(nwOldProj, "data_9")) - assert not os.path.isdir(os.path.join(nwOldProj, "data_a")) - assert not os.path.isdir(os.path.join(nwOldProj, "data_f")) - - # Check that files we want to keep are in the right place - assert os.path.isdir(os.path.join(nwOldProj, "cache")) - assert os.path.isdir(os.path.join(nwOldProj, "content")) - assert os.path.isdir(os.path.join(nwOldProj, "meta")) - - assert os.path.isfile(os.path.join(nwOldProj, "content", "f528d831f5b24.nwd")) - assert os.path.isfile(os.path.join(nwOldProj, "content", "88124a4292d8b.nwd")) - assert os.path.isfile(os.path.join(nwOldProj, "content", "91239bf2f8b69.nwd")) - assert os.path.isfile(os.path.join(nwOldProj, "content", "19752e7f9d8af.nwd")) - assert os.path.isfile(os.path.join(nwOldProj, "content", "a764d5acf5a21.nwd")) - assert os.path.isfile(os.path.join(nwOldProj, "content", "9058ae29f0dfd.nwd")) - assert os.path.isfile(os.path.join(nwOldProj, "content", "7ff63b8afc4cd.nwd")) - - assert os.path.isfile(os.path.join(nwOldProj, "meta", "tagsIndex.json")) - assert os.path.isfile(os.path.join(nwOldProj, "meta", "sessionInfo.log")) - - # Close the project - theProject.closeProject() - - # Check that new files have been created - assert os.path.isfile(os.path.join(nwOldProj, "meta", "guiOptions.json")) - assert os.path.isfile(os.path.join(nwOldProj, "ToC.txt")) - -# END Test testCoreProject_OldFormat - - -@pytest.mark.core -def testCoreProject_LegacyData(monkeypatch, mockGUI, fncDir): - """Test the functins that handle legacy data folders and structure - with additional tests of failure handling. - """ - theProject = NWProject(mockGUI) - theProject.setProjectPath(fncDir) - - # Check behaviour of deprecated files function on OSError - tstFile = os.path.join(fncDir, "ToC.json") - writeFile(tstFile, "stuff") - assert os.path.isfile(tstFile) - - with monkeypatch.context() as mp: - mp.setattr("os.unlink", causeOSError) - assert theProject._deprecatedFiles() is False - - assert theProject._deprecatedFiles() - assert not os.path.isfile(tstFile) - - # Check processing non-folders - tstFile = os.path.join(fncDir, "data_0") - writeFile(tstFile, "stuff") - assert os.path.isfile(tstFile) - assert theProject._legacyDataFolder(tstFile) is False - - # Check renaming/deleting of old document files - tstData2 = os.path.join(fncDir, "data_2") - tstData3 = os.path.join(fncDir, "data_3") - tstDoc1m = os.path.join(tstData2, "000000000001_main.nwd") - tstDoc1b = os.path.join(tstData2, "000000000001_main.bak") - tstDoc2m = os.path.join(tstData2, "000000000002_main.nwd") - tstDoc2b = os.path.join(tstData2, "000000000002_main.bak") - tstDoc3m = os.path.join(tstData3, "tooshort003_main.nwd") - tstDoc3b = os.path.join(tstData3, "tooshort003_main.bak") - tstDir4a = os.path.join(tstData3, "stuff") - - os.mkdir(tstData2) - os.mkdir(tstData3) - writeFile(tstDoc1m, "stuff") - writeFile(tstDoc1b, "stuff") - writeFile(tstDoc2m, "stuff") - writeFile(tstDoc2b, "stuff") - writeFile(tstDoc3m, "stuff") - writeFile(tstDoc3b, "stuff") - os.mkdir(tstDir4a) - - # Make the above fail - with monkeypatch.context() as mp: - mp.setattr("os.rename", causeOSError) - mp.setattr("os.unlink", causeOSError) - with pytest.raises(OSError): - theProject._legacyDataFolder(tstData2) - theProject._legacyDataFolder(tstData3) - assert os.path.isfile(tstDoc1m) - assert os.path.isfile(tstDoc1b) - assert os.path.isfile(tstDoc2m) - assert os.path.isfile(tstDoc2b) - assert os.path.isfile(tstDoc3m) - assert os.path.isfile(tstDoc3b) - - # And succeed ... - assert theProject._legacyDataFolder(tstData2) is True - assert theProject._legacyDataFolder(tstData3) is True - - assert not os.path.isdir(tstData2) - assert os.path.isdir(tstData3) - assert os.path.isfile(os.path.join(fncDir, "content", "2000000000001.nwd")) - assert os.path.isfile(os.path.join(fncDir, "content", "2000000000002.nwd")) - assert os.path.isfile(os.path.join(fncDir, tstData3, "tooshort003_main.nwd")) - assert os.path.isfile(os.path.join(fncDir, tstData3, "tooshort003_main.bak")) - assert os.path.isdir(tstDir4a) - -# END Test testCoreProject_LegacyData - - @pytest.mark.core def testCoreProject_Backup(monkeypatch, mockGUI, fncDir, tmpDir): """Test the automated backup feature of the project class. The test