本文整理汇总了Python中iniparse.RawConfigParser.getboolean方法的典型用法代码示例。如果您正苦于以下问题:Python RawConfigParser.getboolean方法的具体用法?Python RawConfigParser.getboolean怎么用?Python RawConfigParser.getboolean使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类iniparse.RawConfigParser
的用法示例。
在下文中一共展示了RawConfigParser.getboolean方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _enable_plugins
# 需要导入模块: from iniparse import RawConfigParser [as 别名]
# 或者: from iniparse.RawConfigParser import getboolean [as 别名]
def _enable_plugins(cls, pkg_mgr_name, plugin_dir):
"""
This class method tries to enable plugins for DNF or YUM
:param pkg_mgr_name: It can be "dnf" or "yum"
:type pkg_mgr_name: str
:param plugin_dir: Directory with configuration files for (dnf/yum) plugins
:type plugin_dir: str
:return:
"""
# List of successfully enabled plugins
enabled_lugins = []
# Go through the list of yum plugins and try to find configuration
# file of these plugins.
for plugin_name in cls.PLUGINS:
plugin_file_name = plugin_dir + '/' + plugin_name + '.conf'
plugin_config = ConfigParser()
try:
result = plugin_config.read(plugin_file_name)
except Exception as err:
# Capture all errors during reading yum plugin conf file
# report them and skip this conf file
log.error(
"Error during reading %s plugin config file '%s': %s. Skipping this file." %
(pkg_mgr_name, plugin_file_name, err)
)
continue
if len(result) == 0:
log.warn('Configuration file of %s plugin: "%s" cannot be read' %
(pkg_mgr_name, plugin_file_name))
continue
is_plugin_enabled = False
if not plugin_config.has_section('main'):
log.warning(
'Configuration file of %s plugin: "%s" does not include main section. Adding main section.' %
(pkg_mgr_name, plugin_file_name)
)
plugin_config.add_section('main')
elif plugin_config.has_option('main', 'enabled'):
try:
# Options 'enabled' can be 0 or 1
is_plugin_enabled = plugin_config.getint('main', 'enabled')
except ValueError:
try:
# Options 'enabled' can be also: true or false
is_plugin_enabled = plugin_config.getboolean('main', 'enabled')
except ValueError:
log.warning(
"File %s has wrong value of options: 'enabled' in section: 'main' (not a int nor boolean)" %
plugin_file_name
)
if is_plugin_enabled == cls.PLUGIN_ENABLED:
log.debug('%s plugin: "%s" already enabled. Nothing to do.' %
(pkg_mgr_name, plugin_file_name))
else:
log.warning('Enabling %s plugin: "%s".' % (pkg_mgr_name, plugin_file_name))
# Change content of plugin configuration file and enable this plugin.
with open(plugin_file_name, 'w') as cfg_file:
plugin_config.set('main', 'enabled', cls.PLUGIN_ENABLED)
plugin_config.write(cfg_file)
enabled_lugins.append(plugin_file_name)
return enabled_lugins
示例2: enable_yum_plugins
# 需要导入模块: from iniparse import RawConfigParser [as 别名]
# 或者: from iniparse.RawConfigParser import getboolean [as 别名]
def enable_yum_plugins(cls):
"""
This function tries to enable yum plugins: subscription-manager and product-id.
It takes no action, when automatic enabling of yum plugins is disabled in rhsm.conf.
:return: It returns list of enabled plugins
"""
# When user doesn't want to automatically enable yum plugins, then return empty list
if cls.is_auto_enable_enabled() is False:
log.info('The rhsm.auto_enable_yum_plugins is disabled. Skipping the enablement of yum plugins.')
return []
log.debug('The rhsm.auto_enable_yum_plugins is enabled')
# List of successfully enabled plugins
enabled_yum_plugins = []
# Go through the list of yum plugins and try to find configuration
# file of these plugins.
for yum_plugin_name in cls.YUM_PLUGINS:
yum_plugin_file_name = cls.YUM_PLUGIN_DIR + '/' + yum_plugin_name + '.conf'
yum_plugin_config = ConfigParser()
try:
result = yum_plugin_config.read(yum_plugin_file_name)
except Exception as err:
# Capture all errors during reading yum plugin conf file
# report them and skip this conf file
log.error(
"Error during reading yum plugin config file '%s': %s. Skipping this file." %
(yum_plugin_file_name, err)
)
continue
if len(result) == 0:
log.info('Configuration file of yum plugin: "%s" cannot be read' % yum_plugin_file_name)
continue
is_plugin_enabled = False
if not yum_plugin_config.has_section('main'):
log.warn(
'Configuration file of yum plugin: "%s" does not include main section. Adding main section.' %
yum_plugin_file_name
)
yum_plugin_config.add_section('main')
elif yum_plugin_config.has_option('main', 'enabled'):
try:
# Options 'enabled' can be 0 or 1
is_plugin_enabled = yum_plugin_config.getint('main', 'enabled')
except ValueError:
try:
# Options 'enabled' can be also: true or false
is_plugin_enabled = yum_plugin_config.getboolean('main', 'enabled')
except ValueError:
log.warn(
"File %s has wrong value of options: 'enabled' in section: 'main' (not a int nor boolean)" %
yum_plugin_file_name
)
if is_plugin_enabled == cls.YUM_PLUGIN_ENABLED:
log.debug('Yum plugin: "%s" already enabled. Nothing to do.' % yum_plugin_file_name)
else:
log.warn('Enabling yum plugin: "%s".' % yum_plugin_file_name)
# Change content of plugin configuration file and enable this plugin.
with open(yum_plugin_file_name, 'w') as cfg_file:
yum_plugin_config.set('main', 'enabled', cls.YUM_PLUGIN_ENABLED)
yum_plugin_config.write(cfg_file)
enabled_yum_plugins.append(yum_plugin_file_name)
return enabled_yum_plugins