本文整理汇总了Python中ConfigParser.ConfigParser.filename方法的典型用法代码示例。如果您正苦于以下问题:Python ConfigParser.filename方法的具体用法?Python ConfigParser.filename怎么用?Python ConfigParser.filename使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ConfigParser.ConfigParser
的用法示例。
在下文中一共展示了ConfigParser.filename方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: load_configparser
# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import filename [as 别名]
def load_configparser(config_file=None):
cp = CP()
if config_file is not None:
config_file = resolve_file(config_file)
if not os.path.isfile(config_file):
es = "Could not find configuration file [%s]"
raise ValueError(es % (config_file))
else:
possible_config_files = ['zdstackrc', 'zdstack.ini',
'~/.zdstackrc', '~/.zdstack.ini',
'~/.zdstack/zdstackrc',
'~/.zdstack/zdstack.ini',
'/etc/zdstackrc', '/etc/zdstack.ini',
'/etc/zdstack/zdstackrc'
'/etc/zdstack/zdstack.ini']
possible_config_files = \
[resolve_file(x) for x in possible_config_files]
if not [y for y in possible_config_files if os.path.isfile(y)]:
raise ValueError("Could not find a valid configuration file")
config_file = possible_config_files[0]
config_fobj = StringIO(read_file(config_file))
regexp = r'^\[(.*)\]%'
sections = []
for line in config_fobj.getvalue().splitlines():
if re.match(regexp, line) and line in sections:
es = "Duplicate section found in config: [%s]"
raise ValueError(es % (line))
config_fobj.seek(0)
cp.readfp(config_fobj)
cp.filename = config_file
for section in cp.sections():
cp.set(section, 'name', section)
return cp
示例2: load_app
# 需要导入模块: from ConfigParser import ConfigParser [as 别名]
# 或者: from ConfigParser.ConfigParser import filename [as 别名]
def load_app(filename):
filename = os.path.abspath(filename)
parser = ConfigParser()
parser.read([filename])
parser.filename = filename
parser.defaults()['here'] = os.path.dirname(filename)
parser.defaults()['__file__'] = filename
return load_app_from_parser(parser)