当前位置: 首页>>代码示例>>Python>>正文


Python RawConfigParser.write方法代码示例

本文整理汇总了Python中iniparse.RawConfigParser.write方法的典型用法代码示例。如果您正苦于以下问题:Python RawConfigParser.write方法的具体用法?Python RawConfigParser.write怎么用?Python RawConfigParser.write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在iniparse.RawConfigParser的用法示例。


在下文中一共展示了RawConfigParser.write方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: inifile_writestring

# 需要导入模块: from iniparse import RawConfigParser [as 别名]
# 或者: from iniparse.RawConfigParser import write [as 别名]
def inifile_writestring(inifilename,section,key,value):
    """Write a string parameter to inifile"""
    inifile = RawConfigParser()
    inifile.read(inifilename)
    if not inifile.has_section(section):
        inifile.add_section(section)
    inifile.set(section,key,value)
    inifile.write(open(inifilename,'w'))
开发者ID:ssamson-tis,项目名称:WAPT,代码行数:10,代码来源:setuphelpers.py

示例2: write

# 需要导入模块: from iniparse import RawConfigParser [as 别名]
# 或者: from iniparse.RawConfigParser import write [as 别名]
 def write(self):
     if not self.manage_repos:
         log.debug("Skipping write due to manage_repos setting: %s" %
                 self.path)
         return
     if self._has_changed():
         f = open(self.path, 'w')
         tidy_writer = TidyWriter(f)
         ConfigParser.write(self, tidy_writer)
         tidy_writer.close()
         f.close()
开发者ID:Januson,项目名称:subscription-manager,代码行数:13,代码来源:repofile.py

示例3: exit

# 需要导入模块: from iniparse import RawConfigParser [as 别名]
# 或者: from iniparse.RawConfigParser import write [as 别名]
            if code != postconf.DIALOG_OK:
                exit(1)
            else:
                waptserver_ini.set("options", "mongodb_ip", mongodb_ip)
        elif code != postconf.DIALOG_OK:
            exit(1)

    code, tag = postconf.menu("Mongodb server port: ", choices=[("1", "27017 (default)"), ("2", "other")])
    if code == postconf.DIALOG_OK:
        if tag == "1":
            waptserver_ini.set("options", "mongodb_port", "27017")
        elif tag == "2":
            (code, mongodb_port) = postconf.inputbox("mongodb server port: ")
            if code != postconf.DIALOG_OK:
                exit(1)
            else:
                waptserver_ini.set("options", "mongodb_port", mongodb_port)
        elif code != postconf.DIALOG_OK:
            exit(0)

    (code, wapt_password) = postconf.passwordbox("wapt server password:  ")
    if code != postconf.DIALOG_OK:
        exit(0)
    else:
        password = hashlib.sha512(wapt_password).hexdigest()
        waptserver_ini.set("options", "wapt_password", password)

    with open("/opt/wapt/waptserver/waptserver.ini", "w") as inifile:
        waptserver_ini.write(inifile)
    postconf.msgbox("postconf script completed !! \n Please start wapt server with /etc/init.d/waptserver start")
开发者ID:hashar,项目名称:WAPT,代码行数:32,代码来源:postconf.py

示例4: _enable_plugins

# 需要导入模块: from iniparse import RawConfigParser [as 别名]
# 或者: from iniparse.RawConfigParser import write [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
开发者ID:candlepin,项目名称:subscription-manager,代码行数:67,代码来源:repolib.py

示例5: enable_yum_plugins

# 需要导入模块: from iniparse import RawConfigParser [as 别名]
# 或者: from iniparse.RawConfigParser import write [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
开发者ID:Lorquas,项目名称:subscription-manager,代码行数:71,代码来源:repolib.py


注:本文中的iniparse.RawConfigParser.write方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。