Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 21 additions & 12 deletions source/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@
from configobj.validate import Validator
from logHandler import log
import logging
from logging import DEBUG
from utils.caseInsensitiveCollections import CaseInsensitiveSet
import winBindings.shell32
from shlobj import FolderId, SHGetKnownFolderPath
Expand Down Expand Up @@ -589,31 +588,41 @@ def _initBaseConf(self, factoryDefaults=False):
self.profiles.append(profile)
self._handleProfileSwitch()

def _loadConfig(self, fn, fileError=False):
def _loadConfig(self, fn: str | None, fileError: bool = False) -> ConfigObj:
"""Load a configuration from a file.

:param fn: The filename of the configuration file to load.
:param fileError: Whether to raise an error if the file cannot be read, defaults to False
:raises e: Re-raises any exception that occurs during the profile upgrade process.
:return: The loaded configuration object.
"""
log.info("Loading config: {0}".format(fn))
profile = ConfigObj(fn, indent_type="\t", encoding="UTF-8", file_error=fileError)
# Python converts \r\n to \n when reading files in Windows, so ConfigObj can't determine the true line ending.
profile.newlines = "\r\n"
profileCopy = deepcopy(profile)
if NVDAState.shouldWriteToDisk() and profile.filename is not None:
writeProfileFunc = self._writeProfileToFile
else:
writeProfileFunc = None
try:
if NVDAState.shouldWriteToDisk() and profile.filename is not None:
writeProfileFunc = self._writeProfileToFile
else:
writeProfileFunc = None
profileUpgrader.upgrade(profile, self.validator, writeProfileFunc)
except Exception as e:
# Log at level info to ensure that the profile is logged.
log.info("Config before schema update:\n%s" % profileCopy, exc_info=False)
# Log at level debug to ensure that the profile isn't logged by default.
log.debug("Config before schema update:\n%s" % profileCopy, exc_info=False)
Comment thread
seanbudd marked this conversation as resolved.
Outdated
raise e
# since profile settings are not yet imported we have to "peek" to see
# if debug level logging is enabled.
try:
logLevelName = profile["general"]["loggingLevel"]
logLevelName: str = profile["general"]["loggingLevel"]
except KeyError:
logLevelName = None
if log.isEnabledFor(log.DEBUG) or (logLevelName and DEBUG >= logging.getLevelName(logLevelName)):
# Log at level info to ensure that the profile is logged.
log.info(
if log.isEnabledFor(log.DEBUG) or (
logLevelName
and logging.getLevelNamesMapping().get(logLevelName, log.INFO) <= logging.DEBUG
):
# Log at level debug to ensure that the profile isn't logged by default.
log.debug(
Comment thread
seanbudd marked this conversation as resolved.
Outdated
"Config loaded (after upgrade, and in the state it will be used by NVDA):\n{0}".format(
profile,
),
Expand Down
Loading