本文整理匯總了Python中exe.engine.configparser.ConfigParser.setdefault方法的典型用法代碼示例。如果您正苦於以下問題:Python ConfigParser.setdefault方法的具體用法?Python ConfigParser.setdefault怎麽用?Python ConfigParser.setdefault使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類exe.engine.configparser.ConfigParser
的用法示例。
在下文中一共展示了ConfigParser.setdefault方法的3個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: Config
# 需要導入模塊: from exe.engine.configparser import ConfigParser [as 別名]
# 或者: from exe.engine.configparser.ConfigParser import setdefault [as 別名]
#.........這裏部分代碼省略.........
self._writeDefaultConfigFile()
# Now we are ready to serve the application
self.loadSettings()
self.setupLogging()
self.loadLocales()
self.loadStyles()
def _overrideDefaultVals(self):
"""
Override this to override the
default config values
"""
def _getConfigPathOptions(self):
"""
Override this to give a list of
possible config filenames
in order of preference
"""
return ['exe.conf']
def _writeDefaultConfigFile(self):
"""
[Over]writes 'self.configPath' with a default config file
(auto write is on so we don't need to write the file at the end)
"""
if not G.application.portable:
for sectionName, optionNames in self.optionNames.items():
for optionName in optionNames:
defaultVal = getattr(self, optionName)
self.configParser.setdefault(sectionName,
optionName,
defaultVal)
# Logging can't really be changed from inside the program at the moment...
self.configParser.setdefault('logging', 'root', 'INFO')
def __setConfigPath(self):
"""
sets self.configPath to the filename of the config file that we'll
use.
In descendant classes set self.configFileOptions to a list
of directories where the configDir should be in order of preference.
If no config files can be found in these dirs, it will
force creation of the config file in the top dir
"""
# If there's an EXECONF environment variable, use it
self.configPath = None
configFileOptions = map(Path, self._getConfigPathOptions())
if "EXECONF" in os.environ:
envconf = Path(os.environ["EXECONF"])
if envconf.isfile():
self.configPath = os.environ["EXECONF"]
# Otherwise find the most appropriate existing file
if self.configPath is None:
for confPath in configFileOptions:
if confPath.isfile():
self.configPath = confPath
break
else:
# If no config files exist, create and use the
# first one on the list
self.configPath = configFileOptions[0]
示例2: __init__
# 需要導入模塊: from exe.engine.configparser import ConfigParser [as 別名]
# 或者: from exe.engine.configparser.ConfigParser import setdefault [as 別名]
class Config:
"""
The Config class contains the configuration information for eXe.
"""
optionNames = {
'system': ('webDir', 'xulDir', 'port', 'dataDir',
'configDir', 'localeDir', 'browserPath'),
'user': ('locale',),
}
def __init__(self):
"""
Initialise
"""
self.configPath = None
self.configParser = ConfigParser(self.onWrite)
self.exePath = Path(sys.argv[0]).abspath()
self.webDir = self.exePath.dirname()
self.xulDir = self.exePath.dirname()
self.localeDir = self.exePath.dirname()/"locale"
self.port = 51235
self.dataDir = Path(".")
self.configDir = Path(".")
self.browserPath = Path("firefox")
self.locale = chooseDefaultLocale(self.localeDir)
self.styles = []
self.recentProjects = []
self.hiddeniDevices = []
self.deprecatediDevices = [ "flash with text", "flash movie", "mp3", \
"attachment"]
self.assumeMediaPlugins = False;
self._overrideDefaultVals()
self.webDir = Path(self.webDir)
if not (self.webDir/'scripts').isdir() \
and (self.webDir/'webui').isdir():
self.webDir /= 'webui'
self.xulDir = Path(self.xulDir)
if not (self.xulDir/'scripts').isdir() \
and (self.xulDir/'xului').isdir():
self.xulDir /= 'xului'
self.__setConfigPath()
self._writeDefaultConfigFile()
self.loadSettings()
self.setupLogging()
self.loadStyles()
self.loadLocales()
def _overrideDefaultVals(self):
"""
Override this to override the
default config values
"""
def _getConfigPathOptions(self):
"""
Override this to give a list of
possible config filenames
in order of preference
"""
return ['exe.conf']
def _writeDefaultConfigFile(self):
"""
[Over]writes 'self.configPath' with a default config file
(auto write is on so we don't need to write the file at the end)
"""
for sectionName, optionNames in self.optionNames.items():
for optionName in optionNames:
defaultVal = getattr(self, optionName)
self.configParser.setdefault(sectionName,
optionName,
defaultVal)
self.configParser.setdefault('logging', 'root', 'INFO')
def __setConfigPath(self):
"""
sets self.configPath to the filename of the config file that we'll
use.
In descendant classes set self.configFileOptions to a list
of directories where the configDir should be in order of preference.
If no config files can be found in these dirs, it will
force creation of the config file in the top dir
"""
self.configPath = None
configFileOptions = map(Path, self._getConfigPathOptions())
if "EXECONF" in os.environ:
envconf = Path(os.environ["EXECONF"])
if envconf.isfile():
self.configPath = os.environ["EXECONF"]
if self.configPath is None:
for confPath in configFileOptions:
if confPath.isfile():
self.configPath = confPath
break
else:
self.configPath = configFileOptions[0]
folder = self.configPath.abspath().dirname()
if not folder.exists():
folder.makedirs()
self.configPath.touch()
self.configParser.read(self.configPath)
self.configParser.autoWrite = True
def upgradeFile(self):
"""
Called before loading the config file,
#.........這裏部分代碼省略.........
示例3: __init__
# 需要導入模塊: from exe.engine.configparser import ConfigParser [as 別名]
# 或者: from exe.engine.configparser.ConfigParser import setdefault [as 別名]
#.........這裏部分代碼省略.........
self.__setConfigPath()
# Fill in any undefined config options with our defaults
self._writeDefaultConfigFile()
# Now we are ready to serve the application
self.loadSettings()
self.setupLogging()
self.loadStyles()
self.loadLocales()
def _overrideDefaultVals(self):
"""
Override this to override the
default config values
"""
def _getConfigPathOptions(self):
"""
Override this to give a list of
possible config filenames
in order of preference
"""
return ['exe.conf']
def _writeDefaultConfigFile(self):
"""
[Over]writes 'self.configPath' with a default config file
(auto write is on so we don't need to write the file at the end)
"""
for sectionName, optionNames in self.optionNames.items():
for optionName in optionNames:
defaultVal = getattr(self, optionName)
self.configParser.setdefault(sectionName,
optionName,
defaultVal)
# Logging can't really be changed from inside the program at the moment...
self.configParser.setdefault('logging', 'root', 'INFO')
def _getWinFolder(self, code):
"""
Gets one of the windows famous directorys
depending on 'code'
Possible values can be found at:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/shellcc/platform/shell/reference/enums/csidl.asp#CSIDL_WINDOWS
"""
from ctypes import WinDLL, create_unicode_buffer
dll = WinDLL('shell32')
# The '5' and the '0' from the below call come from
# google: "ShellSpecialConstants site:msdn.microsoft.com"
result = create_unicode_buffer(260)
resource = dll.SHGetFolderPathW(None, code, None, 0, result)
if resource != 0:
return Path('')
else:
return Path(result.value)
def __setConfigPath(self):
"""
sets self.configPath to the filename of the config file that we'll
use.
In descendant classes set self.configFileOptions to a list
of directories where the configDir should be in order of preference.
If no config files can be found in these dirs, it will