Switch to Path objects nearly everywhere

This commit is contained in:
Veronica Berglyd Olsen
2022-11-09 22:43:48 +01:00
parent cb755ba820
commit 03e173634f
36 changed files with 406 additions and 521 deletions
+14 -12
View File
@@ -19,10 +19,11 @@ You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
"""
import os
import time
import shutil
from pathlib import Path
from PyQt5.QtWidgets import qApp
XML_IGNORE = ("<novelWriterXML", "<project")
@@ -129,24 +130,25 @@ def writeFile(fileName, fileData):
outFile.write(fileData)
def cleanProject(projPath):
def cleanProject(path):
"""Delete all generated files in a project.
"""
cacheDir = os.path.join(projPath, "cache")
if os.path.isdir(cacheDir):
path = Path(path)
cacheDir = path / "cache"
if cacheDir.is_dir():
shutil.rmtree(cacheDir)
metaDir = os.path.join(projPath, "meta")
if os.path.isdir(metaDir):
metaDir = path / "meta"
if metaDir.is_dir():
shutil.rmtree(metaDir)
bakFile = os.path.join(projPath, "nwProject.bak")
if os.path.isfile(bakFile):
os.unlink(bakFile)
bakFile = path / "nwProject.bak"
if bakFile.is_file():
bakFile.unlink()
tocFile = os.path.join(projPath, "ToC.txt")
if os.path.isfile(tocFile):
os.unlink(tocFile)
tocFile = path / "ToC.txt"
if tocFile.is_file():
tocFile.unlink()
return