本文整理匯總了Python中exe.engine.configparser.ConfigParser.addSection方法的典型用法代碼示例。如果您正苦於以下問題:Python ConfigParser.addSection方法的具體用法?Python ConfigParser.addSection怎麽用?Python ConfigParser.addSection使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類exe.engine.configparser.ConfigParser
的用法示例。
在下文中一共展示了ConfigParser.addSection方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: testCreation
# 需要導入模塊: from exe.engine.configparser import ConfigParser [as 別名]
# 或者: from exe.engine.configparser.ConfigParser import addSection [as 別名]
def testCreation(self):
"""
When one creates a section with the same name
as an existing section the existing section should
just be returned
"""
mysec = Section('main', self.c)
assert mysec is self.c.main
othersec = Section('main', self.c)
assert othersec is mysec is self.c.main is self.c._sections['main']
newsec = Section('newsection', self.c)
assert newsec is \
self.c.addSection('newsection') is \
self.c.newsection is \
self.c._sections['newsection']
newsec2 = self.c.addSection('newsection2')
assert newsec2 is \
self.c.addSection('newsection2') is \
Section('newsection2', self.c) is \
self.c.newsection2 is \
self.c._sections['newsection2'] and \
newsec2 is not newsec
# Different parent should create new object
otherConf = ConfigParser()
sec1 = otherConf.addSection('x')
sec2 = self.c.addSection('x')
assert sec1 is not sec2
示例2: testUpgradeAppDir
# 需要導入模塊: from exe.engine.configparser import ConfigParser [as 別名]
# 或者: from exe.engine.configparser.ConfigParser import addSection [as 別名]
def testUpgradeAppDir(self):
"""
Tests that config files with
'appDataDir' are upgraded to 'configDir'
"""
# Write the old style config file
configPath = Path(u'test.exe.conf')
if configPath.exists():
configPath.remove()
oldParser = ConfigParser()
system = oldParser.addSection('system')
system.appDataDir = 'my old app data dir'
oldParser.write(configPath)
del system
del oldParser
# Make the config instance load it
Config._getConfigPathOptions = lambda self: ['test.exe.conf']
myconfig = Config()
myconfig.loadSettings()
# Check if it reads the old value into the new variable
assert not hasattr(myconfig, 'appDataDir')
self.assertEquals(myconfig.configPath, 'test.exe.conf')
self.assertEquals(myconfig.configDir, 'my old app data dir')
# Check if it has upgraded the file and added in some nice default values
newParser = ConfigParser()
newParser.read(configPath)
self.assertEquals(newParser.system.configDir, 'my old app data dir')
示例3: testFromScratch
# 需要導入模塊: from exe.engine.configparser import ConfigParser [as 別名]
# 或者: from exe.engine.configparser.ConfigParser import addSection [as 別名]
def testFromScratch(self):
"""
Tests adding stuff from nothing
"""
x = ConfigParser()
testing = x.addSection('testing')
assert x.testing is testing
testing.myval = 4
self.assertEquals(x.get('testing', 'myval'), '4')
示例4: Config
# 需要導入模塊: from exe.engine.configparser import ConfigParser [as 別名]
# 或者: from exe.engine.configparser.ConfigParser import addSection [as 別名]
#.........這裏部分代碼省略.........
# Load the "user" section
if self.configParser.has_section('user'):
if self.configParser.user.has_option('editorMode'):
self.editorMode = self.configParser.user.editorMode
if self.configParser.user.has_option('docType'):
self.docType = self.configParser.user.docType
common.setExportDocType(self.configParser.user.docType)
if self.configParser.user.has_option('defaultStyle'):
self.defaultStyle= self.configParser.user.defaultStyle
if self.configParser.user.has_option('styleSecureMode'):
self.styleSecureMode= self.configParser.user.styleSecureMode
if self.configParser.user.has_option('internalAnchors'):
self.internalAnchors = self.configParser.user.internalAnchors
if self.configParser.user.has_option('lastDir'):
self.lastDir = self.configParser.user.lastDir
if self.configParser.user.has_option('showPreferencesOnStart'):
self.showPreferencesOnStart = self.configParser.user.showPreferencesOnStart
if self.configParser.user.has_option('showIdevicesGrouped'):
self.showIdevicesGrouped = self.configParser.user.showIdevicesGrouped
if self.configParser.user.has_option('locale'):
self.locale = self.configParser.user.locale
return
self.locale = chooseDefaultLocale(self.localeDir)
def onWrite(self, configParser):
"""
Called just before the config file is written.
We use it to fill out any settings that are stored here and
not in the config parser itself
"""
# Recent projects
self.configParser.delete('recent_projects')
recentProjectsSection = self.configParser.addSection('recent_projects')
for num, path in enumerate(self.recentProjects):
recentProjectsSection[str(num)] = path
def setupLogging(self):
"""
setup logging file
"""
try:
hdlr = RotatingFileHandler(self.configDir/'exe.log', 'a',
500000, 10)
hdlr.doRollover()
except OSError:
# ignore the error we get if the log file is logged
hdlr = logging.FileHandler(self.configDir/'exe.log')
format = "%(asctime)s %(name)s %(levelname)s %(message)s"
log = logging.getLogger()
hdlr.setFormatter(logging.Formatter(format))
log.addHandler(hdlr)
loggingLevels = {"DEBUG" : logging.DEBUG,
"INFO" : logging.INFO,
"WARNING" : logging.WARNING,
"ERROR" : logging.ERROR,
"CRITICAL" : logging.CRITICAL }
if self.configParser.has_section('logging'):
for logger, level in self.configParser._sections["logging"].items():
if logger == "root":
logging.getLogger().setLevel(loggingLevels[level])
else:
示例5: __init__
# 需要導入模塊: from exe.engine.configparser import ConfigParser [as 別名]
# 或者: from exe.engine.configparser.ConfigParser import addSection [as 別名]
#.........這裏部分代碼省略.........
self.recentProjects = []
if self.configParser.has_section('recent_projects'):
recentProjectsSection = self.configParser.recent_projects
for key, path in recentProjectsSection.items():
self.recentProjects.append(path)
self.hiddeniDevices = []
if self.configParser.has_section('idevices'):
idevicesSection = self.configParser.idevices
for key,value in idevicesSection.items():
value = value.strip().lower()
if value == "0" or value == "no" or value == "false" or \
value == "off":
self.hiddeniDevices.append(key.lower())
if self.configParser.has_section('deprecated'):
deprecatedSection = self.configParser.deprecated
for key,value in deprecatedSection.items():
value = value.strip().lower()
if value == "1" or value == "yes" or value == "true" or \
value == "on":
if key.lower() in self.deprecatediDevices:
self.deprecatediDevices.remove(key.lower())
if self.configParser.has_section('user'):
if self.configParser.user.has_option('locale'):
self.locale = self.configParser.user.locale
return
self.locale = chooseDefaultLocale(self.localeDir)
def onWrite(self, configParser):
"""
Called just before the config file is written.
We use it to fill out any settings that are stored here and
not in the config parser itself
"""
self.configParser.delete('recent_projects')
recentProjectsSection = self.configParser.addSection('recent_projects')
for num, path in enumerate(self.recentProjects):
recentProjectsSection[str(num)] = path
def setupLogging(self):
"""
setup logging file
"""
try:
hdlr = RotatingFileHandler(self.configDir/'exe.log', 'a',
500000, 10)
hdlr.doRollover()
except OSError:
hdlr = logging.FileHandler(self.configDir/'exe.log')
format = "%(asctime)s %(name)s %(levelname)s %(message)s"
log = logging.getLogger()
hdlr.setFormatter(logging.Formatter(format))
log.addHandler(hdlr)
loggingLevels = {"DEBUG" : logging.DEBUG,
"INFO" : logging.INFO,
"WARNING" : logging.WARNING,
"ERROR" : logging.ERROR,
"CRITICAL" : logging.CRITICAL }
if self.configParser.has_section('logging'):
for logger, level in self.configParser._sections["logging"].items():
if logger == "root":
logging.getLogger().setLevel(loggingLevels[level])
else:
logging.getLogger(logger).setLevel(loggingLevels[level])
log.info("************** eXe logging started **************")
log.info("configPath = %s" % self.configPath)
log.info("exePath = %s" % self.exePath)
log.info("browserPath = %s" % self.browserPath)
log.info("webDir = %s" % self.webDir)
示例6: __init__
# 需要導入模塊: from exe.engine.configparser import ConfigParser [as 別名]
# 或者: from exe.engine.configparser.ConfigParser import addSection [as 別名]
#.........這裏部分代碼省略.........
if value == "0" or value == "no" or value == "false" or \
value == "off":
self.hiddeniDevices.append(key.lower())
#self.deprecatediDevices = [ "flash with text", "flash movie", ...]
# and UN-Load from the list of "deprecated" iDevices
if self.configParser.has_section('deprecated'):
deprecatedSection = self.configParser.deprecated
for key,value in deprecatedSection.items():
# emulate standard library's getboolean()
value = value.strip().lower()
if value == "1" or value == "yes" or value == "true" or \
value == "on":
if key.lower() in self.deprecatediDevices:
self.deprecatediDevices.remove(key.lower())
# Load the "user" section
if self.configParser.has_section('user'):
if self.configParser.user.has_option('internalAnchors'):
self.internalAnchors = self.configParser.user.internalAnchors
if self.configParser.user.has_option('locale'):
self.locale = self.configParser.user.locale
return
self.locale = chooseDefaultLocale(self.localeDir)
def onWrite(self, configParser):
"""
Called just before the config file is written.
We use it to fill out any settings that are stored here and
not in the config parser itself
"""
# Recent projects
self.configParser.delete('recent_projects')
recentProjectsSection = self.configParser.addSection('recent_projects')
for num, path in enumerate(self.recentProjects):
recentProjectsSection[str(num)] = path
def setupLogging(self):
"""
setup logging file
"""
try:
hdlr = RotatingFileHandler(self.configDir/'exe.log', 'a',
500000, 10)
hdlr.doRollover()
except OSError:
# ignore the error we get if the log file is logged
hdlr = logging.FileHandler(self.configDir/'exe.log')
format = "%(asctime)s %(name)s %(levelname)s %(message)s"
log = logging.getLogger()
hdlr.setFormatter(logging.Formatter(format))
log.addHandler(hdlr)
loggingLevels = {"DEBUG" : logging.DEBUG,
"INFO" : logging.INFO,
"WARNING" : logging.WARNING,
"ERROR" : logging.ERROR,
"CRITICAL" : logging.CRITICAL }
if self.configParser.has_section('logging'):
for logger, level in self.configParser._sections["logging"].items():
if logger == "root":
logging.getLogger().setLevel(loggingLevels[level])
else:
示例7: TestSections
# 需要導入模塊: from exe.engine.configparser import ConfigParser [as 別名]
# 或者: from exe.engine.configparser.ConfigParser import addSection [as 別名]
class TestSections(unittest.TestCase):
"""
Tests Section objects.
Section objects allow an easy way to read and write
"""
def setUp(self):
"""
Creates a ConfigParser to play with and
reads in the test text
"""
self.c = ConfigParser()
file_ = testFile()
self.c.read(file_)
def testSectionCreation(self):
"""
Tests that the configuration object
creates the section objects ok
"""
assert isinstance(self.c.main, Section)
assert isinstance(self.c.second, Section)
self.failUnlessRaises(AttributeError, lambda: self.c.notexist)
def testFromScratch(self):
"""
Tests adding stuff from nothing
"""
x = ConfigParser()
testing = x.addSection('testing')
assert x.testing is testing
testing.myval = 4
self.assertEquals(x.get('testing', 'myval'), '4')
def testAttributeRead(self):
"""
Tests that we can read attributes from sections
"""
assert self.c.main.level == '5'
assert self.c.main.power == 'on'
self.failUnlessRaises(AttributeError, lambda: self.c.main.notexist)
def testAttributeWrite(self):
"""
Tests that we can set attributes with sections
"""
self.c.main.level = 7
# Should be automatically converted to string also :)
self.assertEquals(self.c.get('main', 'level'), '7')
self.c.main.new = 'hello'
assert self.c.get('main', 'new') == 'hello'
def testAttributeDel(self):
"""
Tests that we can remove attributes from the config file
by removing the sections
"""
del self.c.main.level
assert not self.c.has_option('main', 'level')
def testSectionDel(self):
"""
Tests that we can remove whole sections
by deleting them
"""
del self.c.main
assert not self.c.has_section('main')
def delete(): del self.c.notexist
self.failUnlessRaises(AttributeError, delete)
def testParserIn(self):
"""
To test if a section exists, use the in operator
"""
assert 'main' in self.c
assert 'notexist' not in self.c
# Dotted format
assert 'main.level' in self.c
assert 'main.notexist' not in self.c
# And the sections can do it too
assert 'notexist' not in self.c.main
# Also the hasattr should give the same result
assert hasattr(self.c, 'main')
assert not hasattr(self.c, 'notexist')
assert hasattr(self.c, 'main.level')
assert hasattr(self.c.main, 'level')
assert not hasattr(self.c.main, 'notexist')
def testGet(self):
"""
System should have a get section for those funny
names that can't be attributes
"""
assert self.c.second.get('funny-name_mate') == 'crusty the clown'
def testCreation(self):
"""
When one creates a section with the same name
as an existing section the existing section should
just be returned
#.........這裏部分代碼省略.........