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


Python RawConfigParser.has_section方法代码示例

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


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

示例1: test_upgrade_pstate_files

# 需要导入模块: from six.moves.configparser import RawConfigParser [as 别名]
# 或者: from six.moves.configparser.RawConfigParser import has_section [as 别名]
    def test_upgrade_pstate_files(self):
        """
        Test whether the existing pstate files are correctly updated to 7.1.
        """
        os.makedirs(os.path.join(self.state_dir, STATEDIR_DLPSTATE_DIR))

        # Copy an old pstate file
        src_path = os.path.join(self.CONFIG_PATH, "download_pstate_70.state")
        shutil.copyfile(src_path, os.path.join(self.state_dir, STATEDIR_DLPSTATE_DIR, "download.state"))

        # Copy a corrupt pstate file
        src_path = os.path.join(self.CONFIG_PATH, "download_pstate_70_corrupt.state")
        corrupt_dest_path = os.path.join(self.state_dir, STATEDIR_DLPSTATE_DIR, "downloadcorrupt.state")
        shutil.copyfile(src_path, corrupt_dest_path)

        old_config = RawConfigParser()
        old_config.read(os.path.join(self.CONFIG_PATH, "tribler70.conf"))
        convert_config_to_tribler71(old_config, state_dir=self.state_dir)

        # Verify whether the section is correctly renamed
        download_config = RawConfigParser()
        download_config.read(os.path.join(self.state_dir, STATEDIR_DLPSTATE_DIR, "download.state"))
        self.assertTrue(download_config.has_section("download_defaults"))
        self.assertFalse(download_config.has_section("downloadconfig"))
        self.assertFalse(os.path.exists(corrupt_dest_path))

        # Do the upgrade again, it should not fail
        convert_config_to_tribler71(old_config, state_dir=self.state_dir)
开发者ID:Tribler,项目名称:tribler,代码行数:30,代码来源:test_config_upgrade_70_71.py

示例2: constructConfigParser

# 需要导入模块: from six.moves.configparser import RawConfigParser [as 别名]
# 或者: from six.moves.configparser.RawConfigParser import has_section [as 别名]
def constructConfigParser():
    """
    returns a pre-setup config parser
    """
    parser = RawConfigParser()
    parser.read([CONFIG_SYSTEM, CONFIG_USER])
    if not parser.has_section(GERALD_CONFIG_SECTION):
        parser.add_section(GERALD_CONFIG_SECTION)

    return parser
开发者ID:detrout,项目名称:htsworkflow,代码行数:12,代码来源:retrieve_config.py

示例3: _merge_from_file

# 需要导入模块: from six.moves.configparser import RawConfigParser [as 别名]
# 或者: from six.moves.configparser.RawConfigParser import has_section [as 别名]
    def _merge_from_file(self, config_file):
        """
        Merge variables from ``config_file`` into the environment.

        Any variables in ``config_file`` that have already been set will be
        ignored (meaning this method will *not* try to override them, which
        would raise an exception).

        If ``config_file`` does not exist or is not a regular file, or if there
        is an error parsing ``config_file``, ``None`` is returned.

        Otherwise this method returns a ``(num_set, num_total)`` tuple
        containing first the number of variables that were actually set, and
        second the total number of variables found in ``config_file``.

        This method will raise a ``ValueError`` if ``config_file`` is not an
        absolute path.  For example:

        >>> env = Env()
        >>> env._merge_from_file('my/config.conf')
        Traceback (most recent call last):
          ...
        ValueError: config_file must be an absolute path; got 'my/config.conf'

        Also see `Env._merge()`.

        :param config_file: Absolute path of the configuration file to load.
        """
        if path.abspath(config_file) != config_file:
            raise ValueError(
                'config_file must be an absolute path; got %r' % config_file
            )
        if not path.isfile(config_file):
            return
        parser = RawConfigParser()
        try:
            parser.read(config_file)
        except ParsingError:
            return
        if not parser.has_section(CONFIG_SECTION):
            parser.add_section(CONFIG_SECTION)
        items = parser.items(CONFIG_SECTION)
        if len(items) == 0:
            return (0, 0)
        i = 0
        for (key, value) in items:
            if key not in self:
                self[key] = value
                i += 1
        if 'config_loaded' not in self: # we loaded at least 1 file
            self['config_loaded'] = True
        return (i, len(items))
开发者ID:icute1349,项目名称:freeipa,代码行数:54,代码来源:config.py

示例4: read_cfg

# 需要导入模块: from six.moves.configparser import RawConfigParser [as 别名]
# 或者: from six.moves.configparser.RawConfigParser import has_section [as 别名]
 def read_cfg(self):
     parser = RawConfigParser()
     parser.read(self.cfg_file)
     if not parser.has_section('mail'):
         print('Creating cfg file.')
         self.make_cfg()
     
     self.auth     = parser.get('mail','auth')
     self.user     = parser.get('mail','username')
     self.passwd   = parser.get('mail','password')
     self.mailfrom = parser.get('mail','mailfrom')
     self.host     = parser.get('mail','host')
     self.port     = parser.get('mail','port')
     self.tls      = parser.get('mail','tls')
开发者ID:BBOOXX,项目名称:stash,代码行数:16,代码来源:mail.py

示例5: set_config

# 需要导入模块: from six.moves.configparser import RawConfigParser [as 别名]
# 或者: from six.moves.configparser.RawConfigParser import has_section [as 别名]
 def set_config(self, path, value):
     """Set entry in local configuration."""
     section, option = path.split('.', 1)
     filename = os.path.join(self.path, '.hg', 'hgrc')
     if six.PY2:
         value = value.encode('utf-8')
         section = section.encode('utf-8')
         option = option.encode('utf-8')
     config = RawConfigParser()
     config.read(filename)
     if not config.has_section(section):
         config.add_section(section)
     if (config.has_option(section, option) and
             config.get(section, option) == value):
         return
     config.set(section, option, value)
     with open(filename, 'w') as handle:
         config.write(handle)
开发者ID:saily,项目名称:weblate,代码行数:20,代码来源:vcs.py

示例6: set_config

# 需要导入模块: from six.moves.configparser import RawConfigParser [as 别名]
# 或者: from six.moves.configparser.RawConfigParser import has_section [as 别名]
 def set_config(self, path, value):
     """
     Set entry in local configuration.
     """
     section, option = path.split(".", 1)
     filename = os.path.join(self.path, ".hg", "hgrc")
     if six.PY2:
         value = value.encode("utf-8")
         section = section.encode("utf-8")
         option = option.encode("utf-8")
     config = RawConfigParser()
     config.read(filename)
     if not config.has_section(section):
         config.add_section(section)
     if config.has_option(section, option) and config.get(section, option) == value:
         return
     config.set(section, option, value)
     with open(filename, "w") as handle:
         config.write(handle)
开发者ID:nijel,项目名称:weblate,代码行数:21,代码来源:vcs.py

示例7: _merge_from_file

# 需要导入模块: from six.moves.configparser import RawConfigParser [as 别名]
# 或者: from six.moves.configparser.RawConfigParser import has_section [as 别名]
    def _merge_from_file(self, config_file):
        """
        Merge variables from ``config_file`` into the environment.

        Any variables in ``config_file`` that have already been set will be
        ignored (meaning this method will *not* try to override them, which
        would raise an exception).

        If ``config_file`` does not exist or is not a regular file, or if there
        is an error parsing ``config_file``, ``None`` is returned.

        Otherwise this method returns a ``(num_set, num_total)`` tuple
        containing first the number of variables that were actually set, and
        second the total number of variables found in ``config_file``.

        Also see `Env._merge()`.

        :param config_file: Path of the configuration file to load.
        """
        if not path.isfile(config_file):
            return None
        parser = RawConfigParser()
        try:
            parser.read(config_file)
        except ParsingError:
            return None
        if not parser.has_section(CONFIG_SECTION):
            parser.add_section(CONFIG_SECTION)
        items = parser.items(CONFIG_SECTION)
        if len(items) == 0:
            return 0, 0
        i = 0
        for (key, value) in items:
            if key not in self:
                self[key] = value
                i += 1
        if 'config_loaded' not in self: # we loaded at least 1 file
            self['config_loaded'] = True
        return i, len(items)
开发者ID:npmccallum,项目名称:freeipa,代码行数:41,代码来源:config.py

示例8: print

# 需要导入模块: from six.moves.configparser import RawConfigParser [as 别名]
# 或者: from six.moves.configparser.RawConfigParser import has_section [as 别名]
      print(errmsg, file=sys.stderr)
      if email != None:
        subject = sys.argv[0] + ': Error message'
        send_email(FROM, email, subject, errmsg, server)
      sys.exit(1)
  else:
    errmsg = "Error... a run script executable 'exec' is required in the '[configuration]' section."
    print(errmsg, file=sys.stderr)
    if not startcron: remove_cron(cronid) # remove cron job
    if email != None:
      subject = sys.argv[0] + ': Error message'
      send_email(FROM, email, subject, errmsg, server)
    sys.exit(1)

  # edit start and end times for the main run configuration script
  if cprun.has_section('analysis'):
    cprun.set('analysis', 'starttime', str(newstart))  # set start time
    cprun.set('analysis', 'endtime', str(newend))      # set end time
    cprun.set('analysis', 'autonomous', 'True')        # set 'autonomous' to true
    cprun.set('analysis', 'submit_dag', 'True')        # set to make sure Condor DAG is submitted

    # create file name for DAG
    dagname = 'automated_run_%s-%s' % (str(newstart), str(newend))
    cprun.set('analysis', 'dag_name', dagname) # add this dag file name to the automation code configuration script (to be used to check for DAG completion)

    if prevdags != None:
      # add on new DAG file to list
      prevdags.append(os.path.join(rundir, dagname+'.dag'))
      cp.set('configuration', 'previous_dags', '['+', '.join(['"%s"' % z for z in prevdags])+']') # output as list
    else: # output DAG file to previous_dags list
      cp.set('configuration', 'previous_dags', '["'+os.path.join(rundir, dagname+'.dag')+'"]')
开发者ID:lscsoft,项目名称:lalsuite,代码行数:33,代码来源:knope_automation_script.py

示例9: load_config

# 需要导入模块: from six.moves.configparser import RawConfigParser [as 别名]
# 或者: from six.moves.configparser.RawConfigParser import has_section [as 别名]

#.........这里部分代码省略.........
    cfdir = environ.get('koji.hub.ConfigDir', '/etc/koji-hub/hub.conf.d')
    if cfdir:
        configs = koji.config_directory_contents(cfdir)
    else:
        configs = []
    if cf and os.path.isfile(cf):
        configs.append(cf)
    if configs:
        config = RawConfigParser()
        config.read(configs)
    else:
        config = None
    cfgmap = [
        #option, type, default
        ['DBName', 'string', None],
        ['DBUser', 'string', None],
        ['DBHost', 'string', None],
        ['DBhost', 'string', None],   # alias for backwards compatibility
        ['DBPort', 'integer', None],
        ['DBPass', 'string', None],
        ['KojiDir', 'string', None],

        ['AuthPrincipal', 'string', None],
        ['AuthKeytab', 'string', None],
        ['ProxyPrincipals', 'string', ''],
        ['HostPrincipalFormat', 'string', None],

        ['DNUsernameComponent', 'string', 'CN'],
        ['ProxyDNs', 'string', ''],

        ['CheckClientIP', 'boolean', True],

        ['LoginCreatesUser', 'boolean', True],
        ['KojiWebURL', 'string', 'http://localhost.localdomain/koji'],
        ['EmailDomain', 'string', None],
        ['NotifyOnSuccess', 'boolean', True],
        ['DisableNotifications', 'boolean', False],

        ['Plugins', 'string', ''],
        ['PluginPath', 'string', '/usr/lib/koji-hub-plugins'],

        ['KojiDebug', 'boolean', False],
        ['KojiTraceback', 'string', None],
        ['VerbosePolicy', 'boolean', False],
        ['EnableFunctionDebug', 'boolean', False],

        ['LogLevel', 'string', 'WARNING'],
        ['LogFormat', 'string', '%(asctime)s [%(levelname)s] m=%(method)s u=%(user_name)s p=%(process)s r=%(remoteaddr)s %(name)s: %(message)s'],

        ['MissingPolicyOk', 'boolean', True],
        ['EnableMaven', 'boolean', False],
        ['EnableWin', 'boolean', False],

        ['RLIMIT_AS', 'string', None],
        ['RLIMIT_CORE', 'string', None],
        ['RLIMIT_CPU', 'string', None],
        ['RLIMIT_DATA', 'string', None],
        ['RLIMIT_FSIZE', 'string', None],
        ['RLIMIT_MEMLOCK', 'string', None],
        ['RLIMIT_NOFILE', 'string', None],
        ['RLIMIT_NPROC', 'string', None],
        ['RLIMIT_OFILE', 'string', None],
        ['RLIMIT_RSS', 'string', None],
        ['RLIMIT_STACK', 'string', None],

        ['MemoryWarnThreshold', 'integer', 5000],
        ['MaxRequestLength', 'integer', 4194304],

        ['LockOut', 'boolean', False],
        ['ServerOffline', 'boolean', False],
        ['OfflineMessage', 'string', None],
    ]
    opts = {}
    for name, dtype, default in cfgmap:
        key = ('hub', name)
        if config and config.has_option(*key):
            if dtype == 'integer':
                opts[name] = config.getint(*key)
            elif dtype == 'boolean':
                opts[name] = config.getboolean(*key)
            else:
                opts[name] = config.get(*key)
            continue
        opts[name] = default
    if opts['DBHost'] is None:
        opts['DBHost'] = opts['DBhost']
    # load policies
    # (only from config file)
    if config and config.has_section('policy'):
        #for the moment, we simply transfer the policy conf to opts
        opts['policy'] = dict(config.items('policy'))
    else:
        opts['policy'] = {}
    for pname, text in six.iteritems(_default_policies):
        opts['policy'].setdefault(pname, text)
    # use configured KojiDir
    if opts.get('KojiDir') is not None:
        koji.BASEDIR = opts['KojiDir']
        koji.pathinfo.topdir = opts['KojiDir']
    return opts
开发者ID:mikem23,项目名称:koji-playground,代码行数:104,代码来源:kojixmlrpc.py


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