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


Python RawConfigParser.has_option方法代码示例

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


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

示例1: inifile_readstring

# 需要导入模块: from iniparse import RawConfigParser [as 别名]
# 或者: from iniparse.RawConfigParser import has_option [as 别名]
def inifile_readstring(inifilename,section,key,default=None):
    """Read a string parameter from inifile"""
    inifile = RawConfigParser()
    inifile.read(inifilename)
    if inifile.has_section(section) and inifile.has_option(section,key):
        return inifile.get(section,key)
    else:
        return default
开发者ID:ssamson-tis,项目名称:WAPT,代码行数:10,代码来源:setuphelpers.py

示例2: _enable_plugins

# 需要导入模块: from iniparse import RawConfigParser [as 别名]
# 或者: from iniparse.RawConfigParser import has_option [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

示例3: main

# 需要导入模块: from iniparse import RawConfigParser [as 别名]
# 或者: from iniparse.RawConfigParser import has_option [as 别名]
def main():
    if len(args) == 0:
        print "ERROR : You must provide one action to perform"
        parser.print_usage()
        sys.exit(2)

    action = args[0]

    # Config file
    if not os.path.isfile(config_file):
        logger.error("Error : could not find file : " + config_file + ", please check the path")

    logger.debug("Config file: %s" % config_file)

    defaults = {
        "repositories": "",
        "repo_url": "",
        "default_source_url": "",
        "private_key": "",
        "public_cert": "",
        "default_development_base": "c:\tranquilit",
        "default_package_prefix": "tis",
        "default_sources_suffix": "wapt",
        "default_sources_url": "",
        "upload_cmd": "",
        "wapt_server": "",
        "loglevel": "info",
    }

    cp = RawConfigParser(defaults=defaults)
    cp.add_section("global")
    cp.read(config_file)

    global loglevel
    if not loglevel and cp.has_option("global", "loglevel"):
        loglevel = cp.get("global", "loglevel")
        setloglevel(loglevel)

    mywapt = Wapt(config=cp)
    if options.wapt_url:
        mywapt.wapt_repourl = options.wapt_url

    if options.private_key:
        mywapt.private_key = options.private_key
    else:
        mywapt.private_key = cp.get("global", "private_key")

    mywapt.dry_run = options.dry_run
    # logger.info("Main wapt Repository %s" % mywapt.wapt_repourl)
    logger.debug("WAPT base directory : %s" % mywapt.wapt_base_dir)
    logger.debug("Package cache dir : %s" % mywapt.packagecachedir)
    logger.debug("WAPT DB Structure version;: %s" % mywapt.waptdb.db_version)

    try:
        params_dict = {}
        try:
            params_dict = json.loads(options.params.replace("'", '"'))
        except:
            raise Exception("Install Parameters must be in json format")

        if action == "install" or action == "download":
            if len(args) < 2:
                print "You must provide at least one package name"
                sys.exit(1)

            if os.path.isdir(args[1]) or os.path.isfile(args[1]):
                print "installing WAPT file %s" % args[1]
                if action == "install":
                    mywapt.install_wapt(args[1], params_dict=params_dict)
            else:
                print "%sing WAPT packages %s" % (action, ",".join(args[1:]))
                if options.update_packages:
                    print "Update package list"
                    mywapt.update()

                result = mywapt.install(
                    args[1:], force=options.force, params_dict=params_dict, download_only=(action == "download")
                )
                print "\nResults :"
                if action <> "download":
                    for k in ("install", "additional", "upgrade", "skipped", "errors"):
                        if result.get(k, []):
                            print "\n=== %s packages ===\n%s" % (
                                k,
                                "\n".join(
                                    ["  %-30s | %s (%s)" % (s[0], s[1].package, s[1].version) for s in result[k]]
                                ),
                            )
                else:
                    for k in ("downloaded", "skipped", "errors"):
                        if result.get("downloads", {"downloaded": [], "skipped": [], "errors": []})[k]:
                            print "\n=== %s packages ===\n%s" % (
                                k,
                                "\n".join(["  %s" % (s,) for s in result["downloads"][k]]),
                            )

        elif action == "download":
            if len(args) < 2:
                print "You must provide at least one package name to download"
                sys.exit(1)
#.........这里部分代码省略.........
开发者ID:ssamson-tis,项目名称:WAPT,代码行数:103,代码来源:wapt-get.py

示例4: enable_yum_plugins

# 需要导入模块: from iniparse import RawConfigParser [as 别名]
# 或者: from iniparse.RawConfigParser import has_option [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

示例5: inifile_hasoption

# 需要导入模块: from iniparse import RawConfigParser [as 别名]
# 或者: from iniparse.RawConfigParser import has_option [as 别名]
def inifile_hasoption(inifilename,section,key):
    """Read a string parameter from inifile"""
    inifile = RawConfigParser()
    inifile.read(inifilename)
    return inifile.has_section(section) and inifile.has_option(section,key)
开发者ID:ssamson-tis,项目名称:WAPT,代码行数:7,代码来源:setuphelpers.py


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