Fix tests and added --data option to command line
This commit is contained in:
+6
-1
@@ -87,6 +87,7 @@ def main(sysArgs=None):
|
||||
"logfile=",
|
||||
"version",
|
||||
"config=",
|
||||
"data=",
|
||||
"testmode",
|
||||
"style=",
|
||||
]
|
||||
@@ -105,6 +106,7 @@ def main(sysArgs=None):
|
||||
" -l, --logfile= Specify log file.\n"
|
||||
" --style= Set Qt5 style flag. Defaults to 'Fusion'.\n"
|
||||
" --config= Alternative config file.\n"
|
||||
" --data= Alternative user data path.\n"
|
||||
" --headless Do not display GUI. Useful for testing scripts.\n"
|
||||
).format(
|
||||
appname = __package__,
|
||||
@@ -120,6 +122,7 @@ def main(sysArgs=None):
|
||||
toFile = False
|
||||
toStd = True
|
||||
confPath = None
|
||||
dataPath = None
|
||||
testMode = False
|
||||
qtStyle = "Fusion"
|
||||
cmdOpen = None
|
||||
@@ -157,6 +160,8 @@ def main(sysArgs=None):
|
||||
qtStyle = inArg
|
||||
elif inOpt in ("--config"):
|
||||
confPath = inArg
|
||||
elif inOpt in ("--data"):
|
||||
dataPath = inArg
|
||||
elif inOpt in ("--testmode"):
|
||||
testMode = True
|
||||
|
||||
@@ -187,7 +192,7 @@ def main(sysArgs=None):
|
||||
|
||||
logger.setLevel(debugLevel)
|
||||
|
||||
CONFIG.initConfig(confPath)
|
||||
CONFIG.initConfig(confPath, dataPath)
|
||||
|
||||
if testMode:
|
||||
nwGUI = GuiMain()
|
||||
|
||||
+21
-8
@@ -117,9 +117,6 @@ class Config:
|
||||
self.showRefPanel = True
|
||||
self.viewComments = True
|
||||
|
||||
## Path
|
||||
self.recentList = [""]*10
|
||||
|
||||
# Check Qt5 Versions
|
||||
verQt = splitVersionNumber(QT_VERSION_STR)
|
||||
self.verQtString = QT_VERSION_STR
|
||||
@@ -172,7 +169,10 @@ class Config:
|
||||
# Actions
|
||||
##
|
||||
|
||||
def initConfig(self, confPath=None):
|
||||
def initConfig(self, confPath=None, dataPath=None):
|
||||
"""Initialise the config class. The manual setting of confPath
|
||||
and dataPath is mainly intended for the test suite.
|
||||
"""
|
||||
|
||||
if confPath is None:
|
||||
confRoot = QStandardPaths.writableLocation(QStandardPaths.ConfigLocation)
|
||||
@@ -181,11 +181,15 @@ class Config:
|
||||
logger.info("Setting config from alternative path: %s" % confPath)
|
||||
self.confPath = confPath
|
||||
|
||||
if self.verQtValue >= 50400:
|
||||
dataRoot = QStandardPaths.writableLocation(QStandardPaths.AppDataLocation)
|
||||
if dataPath is None:
|
||||
if self.verQtValue >= 50400:
|
||||
dataRoot = QStandardPaths.writableLocation(QStandardPaths.AppDataLocation)
|
||||
else:
|
||||
dataRoot = QStandardPaths.writableLocation(QStandardPaths.DataLocation)
|
||||
self.dataPath = path.join(path.abspath(dataRoot), self.appHandle)
|
||||
else:
|
||||
dataRoot = QStandardPaths.writableLocation(QStandardPaths.DataLocation)
|
||||
self.dataPath = path.join(path.abspath(dataRoot), self.appHandle)
|
||||
logger.info("Setting data path from alternative path: %s" % dataPath)
|
||||
self.dataPath = dataPath
|
||||
|
||||
logger.verbose("Config path: %s" % self.confPath)
|
||||
logger.verbose("Data path: %s" % self.dataPath)
|
||||
@@ -571,6 +575,15 @@ class Config:
|
||||
self.confFile = path.basename(newPath)
|
||||
return True
|
||||
|
||||
def setDataPath(self, newPath):
|
||||
if newPath is None:
|
||||
return True
|
||||
if not path.isdir(newPath):
|
||||
logger.error("Config: Path not found. Using default data path instead.")
|
||||
return False
|
||||
self.dataPath = path.dirname(newPath)
|
||||
return True
|
||||
|
||||
def setLastPath(self, lastPath):
|
||||
if lastPath is None or lastPath == "":
|
||||
self.lastPath = ""
|
||||
|
||||
Reference in New Issue
Block a user