Completed coverage of setProjectPath and made all os imports explicit
This commit is contained in:
+3
-3
@@ -27,8 +27,8 @@
|
||||
|
||||
import nw
|
||||
import logging
|
||||
import os
|
||||
|
||||
from os import path
|
||||
from datetime import datetime
|
||||
|
||||
from PyQt5.QtCore import Qt
|
||||
@@ -197,8 +197,8 @@ class GuiAbout(QDialog):
|
||||
"""Load the content for the License page.
|
||||
"""
|
||||
docName = "gplv3_%s.htm" % self.mainConf.guiLang
|
||||
docPath = path.join(self.mainConf.assetPath, "text", docName)
|
||||
if path.isfile(docPath):
|
||||
docPath = os.path.join(self.mainConf.assetPath, "text", docName)
|
||||
if os.path.isfile(docPath):
|
||||
with open(docPath, mode="r", encoding="utf8") as inFile:
|
||||
helpText = inFile.read()
|
||||
self.pageLicense.setHtml(helpText)
|
||||
|
||||
+6
-6
@@ -28,8 +28,8 @@
|
||||
import nw
|
||||
import logging
|
||||
import json
|
||||
import os
|
||||
|
||||
from os import path
|
||||
from time import time
|
||||
from datetime import datetime
|
||||
|
||||
@@ -630,8 +630,8 @@ class GuiBuildNovel(QDialog):
|
||||
cleanName = makeFileNameSafe(self.theProject.projName)
|
||||
fileName = "%s.%s" % (cleanName, fileExt)
|
||||
saveDir = self.mainConf.lastPath
|
||||
savePath = path.join(saveDir, fileName)
|
||||
if not path.isdir(saveDir):
|
||||
savePath = os.path.join(saveDir, fileName)
|
||||
if not os.path.isdir(saveDir):
|
||||
saveDir = self.mainConf.homePath
|
||||
|
||||
if self.mainConf.showGUI:
|
||||
@@ -792,9 +792,9 @@ class GuiBuildNovel(QDialog):
|
||||
def _loadCache(self):
|
||||
"""Save the current data to cache.
|
||||
"""
|
||||
buildCache = path.join(self.theProject.projCache, nwFiles.BUILD_CACHE)
|
||||
buildCache = os.path.join(self.theProject.projCache, nwFiles.BUILD_CACHE)
|
||||
dataCount = 0
|
||||
if path.isfile(buildCache):
|
||||
if os.path.isfile(buildCache):
|
||||
|
||||
logger.debug("Loading build cache")
|
||||
try:
|
||||
@@ -823,7 +823,7 @@ class GuiBuildNovel(QDialog):
|
||||
def _saveCache(self):
|
||||
"""Save the current data to cache.
|
||||
"""
|
||||
buildCache = path.join(self.theProject.projCache, nwFiles.BUILD_CACHE)
|
||||
buildCache = os.path.join(self.theProject.projCache, nwFiles.BUILD_CACHE)
|
||||
|
||||
if self.mainConf.debugInfo:
|
||||
nIndent = 2
|
||||
|
||||
@@ -27,8 +27,7 @@
|
||||
|
||||
import nw
|
||||
import logging
|
||||
|
||||
from os import path
|
||||
import os
|
||||
|
||||
from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtGui import QFont
|
||||
@@ -335,7 +334,7 @@ class GuiConfigEditGeneralTab(QWidget):
|
||||
"""Open a dialog to select the backup folder.
|
||||
"""
|
||||
currDir = self.backupPath
|
||||
if not path.isdir(currDir):
|
||||
if not os.path.isdir(currDir):
|
||||
currDir = ""
|
||||
|
||||
dlgOpt = QFileDialog.Options()
|
||||
|
||||
+2
-2
@@ -27,8 +27,8 @@
|
||||
|
||||
import nw
|
||||
import logging
|
||||
import os
|
||||
|
||||
from os import path
|
||||
from datetime import datetime
|
||||
|
||||
from PyQt5.QtCore import Qt, QSize
|
||||
@@ -186,7 +186,7 @@ class GuiProjectLoad(QDialog):
|
||||
options=dlgOpt
|
||||
)
|
||||
if projFile:
|
||||
thePath = path.abspath(path.dirname(projFile))
|
||||
thePath = os.path.abspath(os.path.dirname(projFile))
|
||||
self.selPath.setText(thePath)
|
||||
self.openPath = thePath
|
||||
self.openState = self.OPEN_STATE
|
||||
|
||||
@@ -27,8 +27,7 @@
|
||||
|
||||
import nw
|
||||
import logging
|
||||
|
||||
from os import path
|
||||
import os
|
||||
|
||||
from PyQt5.QtCore import Qt
|
||||
from PyQt5.QtWidgets import (
|
||||
@@ -208,7 +207,7 @@ class ProjWizardFolderPage(QWizardPage):
|
||||
"""Select a project folder.
|
||||
"""
|
||||
lastPath = self.mainConf.lastPath
|
||||
if not path.isdir(lastPath):
|
||||
if not os.path.isdir(lastPath):
|
||||
lastPath = ""
|
||||
|
||||
dlgOpt = QFileDialog.Options()
|
||||
@@ -220,7 +219,7 @@ class ProjWizardFolderPage(QWizardPage):
|
||||
if projDir:
|
||||
projName = self.field("projName")
|
||||
if projName is not None:
|
||||
fullDir = path.join(path.abspath(projDir), makeFileNameSafe(projName))
|
||||
fullDir = os.path.join(os.path.abspath(projDir), makeFileNameSafe(projName))
|
||||
self.projPath.setText(fullDir)
|
||||
else:
|
||||
self.projPath.setText("")
|
||||
|
||||
+38
-38
@@ -29,8 +29,8 @@
|
||||
import nw
|
||||
import logging
|
||||
import configparser
|
||||
import os
|
||||
|
||||
from os import path, listdir
|
||||
from math import ceil
|
||||
|
||||
from PyQt5.QtCore import Qt
|
||||
@@ -182,21 +182,21 @@ class GuiTheme:
|
||||
"""Add the fonts in the assets fonts folder to the app.
|
||||
"""
|
||||
ttfList = []
|
||||
fontAssets = path.join(self.mainConf.assetPath, self.fontPath)
|
||||
for fontFam in listdir(fontAssets):
|
||||
fontDir = path.join(fontAssets, fontFam)
|
||||
if path.isdir(fontDir):
|
||||
fontAssets = os.path.join(self.mainConf.assetPath, self.fontPath)
|
||||
for fontFam in os.listdir(fontAssets):
|
||||
fontDir = os.path.join(fontAssets, fontFam)
|
||||
if os.path.isdir(fontDir):
|
||||
if fontFam not in self.guiFontDB.families():
|
||||
for fontFile in listdir(fontDir):
|
||||
ttfFile = path.join(fontDir, fontFile)
|
||||
if path.isfile(ttfFile) and fontFile.endswith(".ttf"):
|
||||
for fontFile in os.listdir(fontDir):
|
||||
ttfFile = os.path.join(fontDir, fontFile)
|
||||
if os.path.isfile(ttfFile) and fontFile.endswith(".ttf"):
|
||||
ttfList.append(ttfFile)
|
||||
|
||||
for ttfFile in ttfList:
|
||||
logger.verbose("Font asset: %s" % path.relpath(ttfFile))
|
||||
logger.verbose("Font asset: %s" % os.path.relpath(ttfFile))
|
||||
fontID = self.guiFontDB.addApplicationFont(ttfFile)
|
||||
if fontID < 0:
|
||||
logger.error("Failed to add font: %s" % path.relpath(ttfFile))
|
||||
logger.error("Failed to add font: %s" % os.path.relpath(ttfFile))
|
||||
|
||||
return
|
||||
|
||||
@@ -227,10 +227,10 @@ class GuiTheme:
|
||||
self.guiTheme = self.mainConf.guiTheme
|
||||
self.guiSyntax = self.mainConf.guiSyntax
|
||||
self.themeRoot = self.mainConf.themeRoot
|
||||
self.themePath = path.join(self.mainConf.themeRoot, self.guiPath, self.guiTheme)
|
||||
self.syntaxFile = path.join(self.themeRoot, self.syntaxPath, self.guiSyntax+".conf")
|
||||
self.confFile = path.join(self.themePath, self.confName)
|
||||
self.cssFile = path.join(self.themePath, self.cssName)
|
||||
self.themePath = os.path.join(self.mainConf.themeRoot, self.guiPath, self.guiTheme)
|
||||
self.syntaxFile = os.path.join(self.themeRoot, self.syntaxPath, self.guiSyntax+".conf")
|
||||
self.confFile = os.path.join(self.themePath, self.confName)
|
||||
self.cssFile = os.path.join(self.themePath, self.cssName)
|
||||
|
||||
self.loadTheme()
|
||||
self.loadSyntax()
|
||||
@@ -259,7 +259,7 @@ class GuiTheme:
|
||||
# CSS File
|
||||
cssData = ""
|
||||
try:
|
||||
if path.isfile(self.cssFile):
|
||||
if os.path.isfile(self.cssFile):
|
||||
with open(self.cssFile, mode="r", encoding="utf8") as inFile:
|
||||
cssData = inFile.read()
|
||||
except Exception as e:
|
||||
@@ -375,8 +375,8 @@ class GuiTheme:
|
||||
return self.themeList
|
||||
|
||||
confParser = configparser.ConfigParser()
|
||||
for themeDir in listdir(path.join(self.mainConf.themeRoot, self.guiPath)):
|
||||
themeConf = path.join(self.mainConf.themeRoot, self.guiPath, themeDir, self.confName)
|
||||
for themeDir in os.listdir(os.path.join(self.mainConf.themeRoot, self.guiPath)):
|
||||
themeConf = os.path.join(self.mainConf.themeRoot, self.guiPath, themeDir, self.confName)
|
||||
logger.verbose("Checking theme config for '%s'" % themeDir)
|
||||
try:
|
||||
with open(themeConf, mode="r", encoding="utf8") as inFile:
|
||||
@@ -405,10 +405,10 @@ class GuiTheme:
|
||||
return self.syntaxList
|
||||
|
||||
confParser = configparser.ConfigParser()
|
||||
syntaxDir = path.join(self.mainConf.themeRoot, self.syntaxPath)
|
||||
for syntaxFile in listdir(syntaxDir):
|
||||
syntaxPath = path.join(syntaxDir, syntaxFile)
|
||||
if not path.isfile(syntaxPath):
|
||||
syntaxDir = os.path.join(self.mainConf.themeRoot, self.syntaxPath)
|
||||
for syntaxFile in os.listdir(syntaxDir):
|
||||
syntaxPath = os.path.join(syntaxDir, syntaxFile)
|
||||
if not os.path.isfile(syntaxPath):
|
||||
continue
|
||||
logger.verbose("Checking theme syntax for '%s'" % syntaxFile)
|
||||
try:
|
||||
@@ -612,11 +612,11 @@ class GuiIcons:
|
||||
logger.debug("Loading icon theme files")
|
||||
|
||||
self.themeMap = {}
|
||||
checkPath = path.join(self.mainConf.iconPath, self.mainConf.guiIcons)
|
||||
if path.isdir(checkPath):
|
||||
checkPath = os.path.join(self.mainConf.iconPath, self.mainConf.guiIcons)
|
||||
if os.path.isdir(checkPath):
|
||||
logger.debug("Loading icon theme '%s'" % self.mainConf.guiIcons)
|
||||
self.iconPath = checkPath
|
||||
self.confFile = path.join(checkPath, self.confName)
|
||||
self.confFile = os.path.join(checkPath, self.confName)
|
||||
else:
|
||||
return False
|
||||
|
||||
@@ -648,8 +648,8 @@ class GuiIcons:
|
||||
if iconName not in self.ICON_MAP:
|
||||
logger.error("Unknown icon name '%s' in config file" % iconName)
|
||||
else:
|
||||
iconPath = path.join(self.iconPath, iconFile)
|
||||
if path.isfile(iconPath):
|
||||
iconPath = os.path.join(self.iconPath, iconFile)
|
||||
if os.path.isfile(iconPath):
|
||||
self.themeMap[iconName] = iconPath
|
||||
logger.verbose("Icon slot '%s' using file '%s'" % (iconName, iconFile))
|
||||
else:
|
||||
@@ -671,10 +671,10 @@ class GuiIcons:
|
||||
logger.error("Decoration with name '%s' does not exist" % decoKey)
|
||||
return QPixmap()
|
||||
|
||||
imgPath = path.join(
|
||||
imgPath = os.path.join(
|
||||
self.mainConf.assetPath, "images", self.DECO_MAP[decoKey]
|
||||
)
|
||||
if not path.isfile(imgPath):
|
||||
if not os.path.isfile(imgPath):
|
||||
logger.error("Decoration file '%s' not in assets folder" % self.DECO_MAP[decoKey])
|
||||
return QPixmap()
|
||||
|
||||
@@ -714,11 +714,11 @@ class GuiIcons:
|
||||
return self.themeList
|
||||
|
||||
confParser = configparser.ConfigParser()
|
||||
for themeDir in listdir(self.mainConf.iconPath):
|
||||
themePath = path.join(self.mainConf.iconPath, themeDir)
|
||||
if not path.isdir(themePath) or themeDir == self.fbackName:
|
||||
for themeDir in os.listdir(self.mainConf.iconPath):
|
||||
themePath = os.path.join(self.mainConf.iconPath, themeDir)
|
||||
if not os.path.isdir(themePath) or themeDir == self.fbackName:
|
||||
continue
|
||||
themeConf = path.join(themePath, self.confName)
|
||||
themeConf = os.path.join(themePath, self.confName)
|
||||
logger.verbose("Checking icon theme config for '%s'" % themeDir)
|
||||
try:
|
||||
with open(themeConf, mode="r", encoding="utf8") as inFile:
|
||||
@@ -756,12 +756,12 @@ class GuiIcons:
|
||||
|
||||
# If we just want the app icon, return it right away
|
||||
if iconKey == "novelwriter":
|
||||
return QIcon(path.join(self.mainConf.iconPath, "novelwriter.svg"))
|
||||
return QIcon(os.path.join(self.mainConf.iconPath, "novelwriter.svg"))
|
||||
|
||||
# Otherwise, we start looking for it
|
||||
# First in the theme folder
|
||||
if iconKey in self.themeMap:
|
||||
logger.verbose("Loading: %s" % path.relpath(self.themeMap[iconKey]))
|
||||
logger.verbose("Loading: %s" % os.path.relpath(self.themeMap[iconKey]))
|
||||
return QIcon(self.themeMap[iconKey])
|
||||
|
||||
# Next, we try to load the Qt style icons
|
||||
@@ -777,14 +777,14 @@ class GuiIcons:
|
||||
|
||||
# Finally. we check if we have a fallback icon
|
||||
if self.mainConf.guiDark:
|
||||
fbackIcon = path.join(
|
||||
fbackIcon = os.path.join(
|
||||
self.mainConf.iconPath, self.fbackName, "%s-dark.svg" % iconKey
|
||||
)
|
||||
if path.isfile(fbackIcon):
|
||||
if os.path.isfile(fbackIcon):
|
||||
logger.verbose("Loading icon '%s' from fallback theme (dark mode)" % iconKey)
|
||||
return QIcon(fbackIcon)
|
||||
fbackIcon = path.join(self.mainConf.iconPath, self.fbackName, "%s.svg" % iconKey)
|
||||
if path.isfile(fbackIcon):
|
||||
fbackIcon = os.path.join(self.mainConf.iconPath, self.fbackName, "%s.svg" % iconKey)
|
||||
if os.path.isfile(fbackIcon):
|
||||
logger.verbose("Loading icon '%s' from fallback theme (light mode)" % iconKey)
|
||||
return QIcon(fbackIcon)
|
||||
|
||||
|
||||
@@ -28,8 +28,8 @@
|
||||
import nw
|
||||
import logging
|
||||
import json
|
||||
import os
|
||||
|
||||
from os import path
|
||||
from datetime import datetime
|
||||
|
||||
from PyQt5.QtCore import Qt
|
||||
@@ -322,8 +322,8 @@ class GuiWritingStats(QDialog):
|
||||
if fileExt:
|
||||
fileName = "sessionStats.%s" % fileExt
|
||||
saveDir = self.mainConf.lastPath
|
||||
savePath = path.join(saveDir, fileName)
|
||||
if not path.isdir(saveDir):
|
||||
savePath = os.path.join(saveDir, fileName)
|
||||
if not os.path.isdir(saveDir):
|
||||
saveDir = self.mainConf.homePath
|
||||
|
||||
dlgOpt = QFileDialog.Options()
|
||||
@@ -410,7 +410,7 @@ class GuiWritingStats(QDialog):
|
||||
ttTime = 0
|
||||
|
||||
try:
|
||||
logFile = path.join(self.theProject.projMeta, nwFiles.SESS_STATS)
|
||||
logFile = os.path.join(self.theProject.projMeta, nwFiles.SESS_STATS)
|
||||
with open(logFile, mode="r", encoding="utf8") as inFile:
|
||||
for inLine in inFile:
|
||||
if inLine.startswith("#"):
|
||||
|
||||
Reference in New Issue
Block a user