當前位置: 首頁>>代碼示例>>Python>>正文


Python configparser.NoSectionError方法代碼示例

本文整理匯總了Python中six.moves.configparser.NoSectionError方法的典型用法代碼示例。如果您正苦於以下問題:Python configparser.NoSectionError方法的具體用法?Python configparser.NoSectionError怎麽用?Python configparser.NoSectionError使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在six.moves.configparser的用法示例。


在下文中一共展示了configparser.NoSectionError方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: config_default

# 需要導入模塊: from six.moves import configparser [as 別名]
# 或者: from six.moves.configparser import NoSectionError [as 別名]
def config_default(option, default=None, type=None, section=cli.name):
    """Guesses a default value of a CLI option from the configuration.

    ::

       @click.option('--locale', default=config_default('locale'))

    """
    def f(option=option, default=default, type=type, section=section):
        config = read_config()
        if type is None and default is not None:
            # detect type from default.
            type = builtins.type(default)
        get_option = option_getter(type)
        try:
            return get_option(config, section, option)
        except (NoOptionError, NoSectionError):
            return default
    return f 
開發者ID:what-studio,項目名稱:profiling,代碼行數:21,代碼來源:__main__.py

示例2: config_flag

# 需要導入模塊: from six.moves import configparser [as 別名]
# 或者: from six.moves.configparser import NoSectionError [as 別名]
def config_flag(option, value, default=False, section=cli.name):
    """Guesses whether a CLI flag should be turned on or off from the
    configuration.  If the configuration option value is same with the given
    value, it returns ``True``.

    ::

       @click.option('--ko-kr', 'locale', is_flag=True,
                     default=config_flag('locale', 'ko_KR'))

    """
    class x(object):
        def __bool__(self, option=option, value=value,
                     default=default, section=section):
            config = read_config()
            type = builtins.type(value)
            get_option = option_getter(type)
            try:
                return get_option(config, section, option) == value
            except (NoOptionError, NoSectionError):
                return default
        __nonzero__ = __bool__
    return x() 
開發者ID:what-studio,項目名稱:profiling,代碼行數:25,代碼來源:__main__.py

示例3: new_build

# 需要導入模塊: from six.moves import configparser [as 別名]
# 或者: from six.moves.configparser import NoSectionError [as 別名]
def new_build(watch=True):
    modules_check()
    flog = setup_fedpkg_logger()  # NOQA
    fcmd = get_fedpkg_commands()
    task_id = fcmd.build()

    if watch:
        print('')
        try:
            cli = get_fedpkg_cli()
            # TODO: might be good to push this return data back up
            #       or check the status of the return
            r = cli._watch_koji_tasks(fcmd.kojisession, [task_id])
        except configparser.NoSectionError:
            # <C-C> causes this for some reason
            print('')
        except Exception as ex:
            log.warn(str(type(ex).__name__))
            log.warn("Failed to get build status: %s" % ex)

    return fcmd.nvr 
開發者ID:softwarefactory-project,項目名稱:rdopkg,代碼行數:23,代碼來源:kojibuild.py

示例4: load

# 需要導入模塊: from six.moves import configparser [as 別名]
# 或者: from six.moves.configparser import NoSectionError [as 別名]
def load(self, name=None):
        config = configparser.ConfigParser()
        config.read(self._get_config_file())
        try:
            if name is None:
                sections = config.sections()
                if len(sections) < 1:
                    self.credentials = None
                    return
                section_name = sections[-1]
            else:
                section_name = self._section_name(name)
            username = config.get(section_name, "username")
            session_id = config.get(section_name, "session_id")
            database = config.get(section_name, "database")
            server = config.get(section_name, "server")
            self.credentials = mygeotab.Credentials(username, session_id, database, server)
        except configparser.NoSectionError:
            self.credentials = None
        except configparser.NoOptionError:
            self.credentials = None 
開發者ID:Geotab,項目名稱:mygeotab-python,代碼行數:23,代碼來源:cli.py

示例5: get_configured_defaults

# 需要導入模塊: from six.moves import configparser [as 別名]
# 或者: from six.moves.configparser import NoSectionError [as 別名]
def get_configured_defaults():
    config = _reload_config()
    try:
        defaults_section = config.defaults_section_name if hasattr(config, 'defaults_section_name') else 'defaults'
        defaults = {}
        if before_2_0_64:
            options = config.config_parser.options(defaults_section)
            for opt in options:
                value = config.get(defaults_section, opt)
                if value:
                    defaults[opt] = value
        else:
            options = config.items(defaults_section)
            for opt in options:
                name = opt['name']
                value = opt['value']
                if value:
                    defaults[name] = value
        return defaults
    except configparser.NoSectionError:
        return {} 
開發者ID:microsoft,項目名稱:vscode-azurecli,代碼行數:23,代碼來源:tooling2.py

示例6: get_PAT_from_file

# 需要導入模塊: from six.moves import configparser [as 別名]
# 或者: from six.moves.configparser import NoSectionError [as 別名]
def get_PAT_from_file(self, key):
        ensure_dir(AZ_DEVOPS_GLOBAL_CONFIG_DIR)
        logger.debug('Keyring not configured properly or package not found.'
                     'Looking for credentials with key:%s in the file: %s', key, self._PAT_FILE)
        creds_list = self._get_credentials_list()
        try:
            return creds_list.get(key, self._USERNAME)
        except (configparser.NoOptionError, configparser.NoSectionError):
            return None 
開發者ID:Azure,項目名稱:azure-devops-cli-extension,代碼行數:11,代碼來源:credential_store.py

示例7: _get_section_name

# 需要導入模塊: from six.moves import configparser [as 別名]
# 或者: from six.moves.configparser import NoSectionError [as 別名]
def _get_section_name(self, name):
        for section_name in self.sections():
            if section_name.lower() == name.lower():
                return section_name
        else:
            raise NoSectionError(name) 
開發者ID:ywangd,項目名稱:stash,代碼行數:8,代碼來源:pip.py

示例8: _update_default_info

# 需要導入模塊: from six.moves import configparser [as 別名]
# 或者: from six.moves.configparser import NoSectionError [as 別名]
def _update_default_info(self):
        try:
            options = az_config.config_parser.options(DEFAULTS_SECTION)
            self.config_default = ""
            for opt in options:
                self.config_default += opt + ": " + az_config.get(DEFAULTS_SECTION, opt) + "  "
        except configparser.NoSectionError:
            self.config_default = "" 
開發者ID:Azure,項目名稱:azure-cli-shell,代碼行數:10,代碼來源:app.py

示例9: _config_to_dict

# 需要導入模塊: from six.moves import configparser [as 別名]
# 或者: from six.moves.configparser import NoSectionError [as 別名]
def _config_to_dict(self, config_file):
        """Convert a config file to a dict."""
        config = configparser.ConfigParser()
        try:
            with open(config_file, 'r'):
                logger.info("Overlays config file %s found", str(config_file))
            config.read(config_file)
        except IOError:
            logger.error("Overlays config file %s does not exist!",
                         str(config_file))
            raise
        except configparser.NoSectionError:
            logger.error("Error in %s", str(config_file))
            raise

        SECTIONS = ['cache', 'coasts', 'rivers', 'borders', 'cities', 'points', 'grid']
        overlays = {}
        for section in config.sections():
            if section in SECTIONS:
                overlays[section] = {}
                for option in config.options(section):
                    val = config.get(section, option)
                    try:
                        overlays[section][option] = ast.literal_eval(val)
                    except ValueError:
                        overlays[section][option] = val
        return overlays 
開發者ID:pytroll,項目名稱:pycoast,代碼行數:29,代碼來源:cw_base.py

示例10: get_value

# 需要導入模塊: from six.moves import configparser [as 別名]
# 或者: from six.moves.configparser import NoSectionError [as 別名]
def get_value(cls, section, key):
        try:
            value = cls._translator_config.get(section, key)
        except configparser.NoOptionError:
            raise exception.ConfOptionNotDefined(key=key, section=section)
        except configparser.NoSectionError:
            raise exception.ConfSectionNotDefined(section=section)

        return value 
開發者ID:openstack,項目名稱:heat-translator,代碼行數:11,代碼來源:config.py

示例11: projecttool

# 需要導入模塊: from six.moves import configparser [as 別名]
# 或者: from six.moves.configparser import NoSectionError [as 別名]
def projecttool(args, get_path, set_path):
  """
  Run the MAXON API Project Tool. The path to the project tool must be
  configured once.
  """

  cfg = load_cfg()
  if set_path:
    if not os.path.isfile(set_path):
      print('fatal: "{}" is not a file'.format(set_path), file=sys.stderr)
      sys.exit(2)
    if not cfg.has_section('projecttool'):
      cfg.add_section('projecttool')
    cfg.set('projecttool', 'path', set_path)
    save_cfg(cfg)
    return
  try:
    path = cfg.get('projecttool', 'path')
  except NoSectionError:
    print('fatal: path to projecttool is not configured', file=sys.stderr)
    sys.exit(1)
  if get_path:
    print(path)
    return

  sys.exit(oscall([path] + list(args))) 
開發者ID:NiklasRosenstein,項目名稱:c4ddev,代碼行數:28,代碼來源:__main__.py

示例12: _find_configured_default

# 需要導入模塊: from six.moves import configparser [as 別名]
# 或者: from six.moves.configparser import NoSectionError [as 別名]
def _find_configured_default(config, argument):
    if not (hasattr(argument.type, 'default_name_tooling') and argument.type.default_name_tooling):
        return None
    try:
        defaults_section = config.defaults_section_name if hasattr(config, 'defaults_section_name') else 'defaults'
        return config.get(defaults_section, argument.type.default_name_tooling, None)
    except configparser.NoSectionError:
        return None 
開發者ID:microsoft,項目名稱:vscode-azurecli,代碼行數:10,代碼來源:tooling2.py

示例13: get_configured_defaults

# 需要導入模塊: from six.moves import configparser [as 別名]
# 或者: from six.moves.configparser import NoSectionError [as 別名]
def get_configured_defaults():
    _reload_config()
    try:
        options = az_config.config_parser.options(DEFAULTS_SECTION)
        defaults = {}
        for opt in options:
            value = az_config.get(DEFAULTS_SECTION, opt)
            if value:
                defaults[opt] = value
        return defaults
    except configparser.NoSectionError:
        return {} 
開發者ID:microsoft,項目名稱:vscode-azurecli,代碼行數:14,代碼來源:tooling1.py

示例14: _find_configured_default

# 需要導入模塊: from six.moves import configparser [as 別名]
# 或者: from six.moves.configparser import NoSectionError [as 別名]
def _find_configured_default(argument):
    if not (hasattr(argument.type, 'default_name_tooling') and argument.type.default_name_tooling):
        return None
    try:
        return az_config.get(DEFAULTS_SECTION, argument.type.default_name_tooling, None)
    except configparser.NoSectionError:
        return None 
開發者ID:microsoft,項目名稱:vscode-azurecli,代碼行數:9,代碼來源:tooling1.py

示例15: from_config

# 需要導入模塊: from six.moves import configparser [as 別名]
# 或者: from six.moves.configparser import NoSectionError [as 別名]
def from_config(cls, cp, variable_params):
        """Gets sampling transforms specified in a config file.

        Sampling parameters and the parameters they replace are read from the
        ``sampling_params`` section, if it exists. Sampling transforms are
        read from the ``sampling_transforms`` section(s), using
        ``transforms.read_transforms_from_config``.

        An ``AssertionError`` is raised if no ``sampling_params`` section
        exists in the config file.

        Parameters
        ----------
        cp : WorkflowConfigParser
            Config file parser to read.
        variable_params : list
            List of parameter names of the original variable params.

        Returns
        -------
        SamplingTransforms
            A sampling transforms class.
        """
        # Check if a sampling_params section is provided
        try:
            sampling_params, replace_parameters = \
                read_sampling_params_from_config(cp)
        except NoSectionError as e:
            logging.warning("No sampling_params section read from config file")
            raise e
        # get sampling transformations
        sampling_transforms = transforms.read_transforms_from_config(
            cp, 'sampling_transforms')
        logging.info("Sampling in {} in place of {}".format(
            ', '.join(sampling_params), ', '.join(replace_parameters)))
        return cls(variable_params, sampling_params,
                   replace_parameters, sampling_transforms) 
開發者ID:gwastro,項目名稱:pycbc,代碼行數:39,代碼來源:base.py


注:本文中的six.moves.configparser.NoSectionError方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。