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


Python configparser.RawConfigParser方法代码示例

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


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

示例1: read_config

# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import RawConfigParser [as 别名]
def read_config(self):
    """Read the user's configuration file."""

    logging.debug('[VT Plugin] Reading user config file: %s', self.vt_cfgfile)
    config_file = configparser.RawConfigParser()
    config_file.read(self.vt_cfgfile)

    try:
      if config_file.get('General', 'auto_upload') == 'True':
        self.auto_upload = True
      else:
        self.auto_upload = False
      return True
    except:
      logging.error('[VT Plugin] Error reading the user config file.')
      return False 
开发者ID:VirusTotal,项目名称:vt-ida-plugin,代码行数:18,代码来源:plugin_loader.py

示例2: _load_options_from_inputs_spec

# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import RawConfigParser [as 别名]
def _load_options_from_inputs_spec(app_root, stanza_name):
    input_spec_file = 'inputs.conf.spec'
    file_path = op.join(app_root, 'README', input_spec_file)

    if not op.isfile(file_path):
        raise RuntimeError("README/%s doesn't exist" % input_spec_file)

    parser = configparser.RawConfigParser(allow_no_value=True)
    parser.read(file_path)
    options = list(parser.defaults().keys())
    stanza_prefix = '%s://' % stanza_name

    stanza_exist = False
    for section in parser.sections():
        if section == stanza_name or section.startswith(stanza_prefix):
            options.extend(parser.options(section))
            stanza_exist = True
    if not stanza_exist:
        raise RuntimeError("Stanza %s doesn't exist" % stanza_name)
    return set(options) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:22,代码来源:cloud_connect_mod_input.py

示例3: _read_config

# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import RawConfigParser [as 别名]
def _read_config(files):
        config = configparser.RawConfigParser()
        if isinstance(files, (str, type(u''))):
            files = [files]

        found_files = []
        for filename in files:
            try:
                found_files.extend(config.read(filename))
            except UnicodeDecodeError:
                LOG.exception("There was an error decoding a config file."
                              "The file with a problem was %s.",
                              filename)
            except configparser.ParsingError:
                LOG.exception("There was an error trying to parse a config "
                              "file. The file with a problem was %s.",
                              filename)
        return (config, found_files) 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:20,代码来源:config.py

示例4: __init__

# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import RawConfigParser [as 别名]
def __init__(self,
                  default_lib_dirs=default_lib_dirs,
                  default_include_dirs=default_include_dirs,
                  verbosity=1,
                  ):
        self.__class__.info = {}
        self.local_prefixes = []
        defaults = {'library_dirs': os.pathsep.join(default_lib_dirs),
                    'include_dirs': os.pathsep.join(default_include_dirs),
                    'runtime_library_dirs': os.pathsep.join(default_runtime_dirs),
                    'rpath': '',
                    'src_dirs': os.pathsep.join(default_src_dirs),
                    'search_static_first': str(self.search_static_first),
                    'extra_compile_args': '', 'extra_link_args': ''}
        self.cp = ConfigParser(defaults)
        self.files = []
        self.files.extend(get_standard_file('.numpy-site.cfg'))
        self.files.extend(get_standard_file('site.cfg'))
        self.parse_config_files()

        if self.section is not None:
            self.search_static_first = self.cp.getboolean(
                self.section, 'search_static_first')
        assert isinstance(self.search_static_first, int) 
开发者ID:Frank-qlu,项目名称:recruit,代码行数:26,代码来源:system_info.py

示例5: __init__

# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import RawConfigParser [as 别名]
def __init__(self, filename = None, section = None, simulation = False, log = None):

        super(MyConfig, self).__init__()
        self.log = log
        self.FileName = filename
        self.Section = section
        self.Simulation = simulation
        self.CriticalLock = threading.Lock()        # Critical Lock (writing conf file)
        self.InitComplete = False
        try:
            self.config = RawConfigParser()
            self.config.read(self.FileName)

            if self.Section == None:
                SectionList = self.GetSections()
                if len(SectionList):
                    self.Section = SectionList[0]

        except Exception as e1:
            self.LogErrorLine("Error in MyConfig:init: " + str(e1))
            return
        self.InitComplete = True
    #---------------------MyConfig::HasOption----------------------------------- 
开发者ID:jgyates,项目名称:genmon,代码行数:25,代码来源:myconfig.py

示例6: generate_url

# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import RawConfigParser [as 别名]
def generate_url(rse, config):
    '''
    :param rse: Name of the endpoint.
    :param config: RawConfigParser instance which may have configuration
    related to the endpoint.
    :returns: Tuple with the URL where the links can be queried to find new
    dumps and the pattern used to parse the date of the dump of the files/directories
    listed..
    '''
    site = rse.split('_')[0]
    if site not in config.sections():
        base_url = ddmendpoint_url(rse) + 'dumps'
        url_pattern = 'dump_%Y%m%d'
    else:
        url_components = config.get(site, rse).split('/')
        # The pattern may not be the last component
        pattern_index = next(idx for idx, comp in enumerate(url_components) if '%m' in comp)
        base_url = '/'.join(url_components[:pattern_index])
        url_pattern = '/'.join(url_components[pattern_index:])

    return base_url, url_pattern 
开发者ID:rucio,项目名称:rucio,代码行数:23,代码来源:srmdumps.py

示例7: write_global_vcm

# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import RawConfigParser [as 别名]
def write_global_vcm(self):
        print(f"Creating global config file with defaults in {GLOBAL_CONFIG_LOCATION}")

        global global_config
        global_config = configparser.RawConfigParser()
        global_config.add_section('GlobalSettings')

        global_config.set('GlobalSettings', 'openssl_binary', self.open_ssl_binary)

        global_config_file = os.path.expanduser(GLOBAL_CONFIG_LOCATION)

        with open(global_config_file, 'w') as configfile:
            try:
                global_config.write(configfile)
            except configparser.Error as ex:
                print(f"Error writing config file: {global_config_file} : {ex.message}")
                return 
开发者ID:willasaywhat,项目名称:vcm,代码行数:19,代码来源:vcm.py

示例8: write_project_vcm

# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import RawConfigParser [as 别名]
def write_project_vcm(self, project_name, local_folder, remote_folder, url_targets):
        project_config = configparser.RawConfigParser()
        project_config.add_section('ProjectSettings')
        project_config.set('ProjectSettings', 'project_name', project_name)
        project_config.set('ProjectSettings', 'local_path', os.path.join(local_folder, ''))
        project_config.set('ProjectSettings', 'remote_path', os.path.join(remote_folder, ''))
        project_config.set('ProjectSettings', 'url_targets', url_targets)

        project_vmc_filename = os.path.join(local_folder, '.vcm')

        with open(project_vmc_filename, 'w') as configfile:
            try:
                project_config.write(configfile)
            except configparser.Error as ex:
                print(f"Error writing config file: {project_vmc_filename} : {ex.message}")
                return 
开发者ID:willasaywhat,项目名称:vcm,代码行数:18,代码来源:vcm.py

示例9: test_generate_config_disable_symbolic_names

# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import RawConfigParser [as 别名]
def test_generate_config_disable_symbolic_names(self):
        # Test that --generate-rcfile puts symbolic names in the --disable
        # option.

        out = StringIO()
        self._run_pylint(["--generate-rcfile", "--rcfile="], out=out)

        output = out.getvalue()
        # Get rid of the pesky messages that pylint emits if the
        # configuration file is not found.
        master = re.search(r"\[MASTER", output)
        out = StringIO(output[master.start() :])
        parser = configparser.RawConfigParser()
        parser.read_file(out)
        messages = utils._splitstrip(parser.get("MESSAGES CONTROL", "disable"))
        assert "suppressed-message" in messages 
开发者ID:sofia-netsurv,项目名称:python-netsurv,代码行数:18,代码来源:test_self.py

示例10: parse_configuration

# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import RawConfigParser [as 别名]
def parse_configuration(config_filename, config_format):
    '''
    Given a config filename and an expected config file format, return the parsed configuration
    as a namedtuple with one attribute for each parsed section.

    Raise IOError if the file cannot be read, or ValueError if the format is not as expected.
    '''
    parser = RawConfigParser()
    if not parser.read(config_filename):
        raise ValueError('Configuration file cannot be opened: {}'.format(config_filename))

    validate_configuration_format(parser, config_format)

    # Describes a parsed configuration, where each attribute is the name of a configuration file
    # section and each value is a dict of that section's parsed options.
    Parsed_config = namedtuple(
        'Parsed_config', (section_format.name for section_format in config_format)
    )

    return Parsed_config(
        *(parse_section_options(parser, section_format) for section_format in config_format)
    ) 
开发者ID:witten,项目名称:borgmatic,代码行数:24,代码来源:legacy.py

示例11: __init__

# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import RawConfigParser [as 别名]
def __init__(self,
                  default_lib_dirs=default_lib_dirs,
                  default_include_dirs=default_include_dirs,
                  verbosity=1,
                  ):
        self.__class__.info = {}
        self.local_prefixes = []
        defaults = {'library_dirs': os.pathsep.join(default_lib_dirs),
                    'include_dirs': os.pathsep.join(default_include_dirs),
                    'runtime_library_dirs': os.pathsep.join(default_runtime_dirs),
                    'rpath': '',
                    'src_dirs': os.pathsep.join(default_src_dirs),
                    'search_static_first': str(self.search_static_first),
                    'extra_compile_args': '', 'extra_link_args': ''}
        self.cp = ConfigParser(defaults)
        self.files = []
        self.files.extend(get_standard_file('.numpy-site.cfg'))
        self.files.extend(get_standard_file('site.cfg'))
        self.parse_config_files()
        if self.section is not None:
            self.search_static_first = self.cp.getboolean(
                self.section, 'search_static_first')
        assert isinstance(self.search_static_first, int) 
开发者ID:abhisuri97,项目名称:auto-alt-text-lambda-api,代码行数:25,代码来源:system_info.py

示例12: read

# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import RawConfigParser [as 别名]
def read(self, filenames, option_parser):
        if type(filenames) in (str, str):
            filenames = [filenames]
        for filename in filenames:
            try:
                # Config files must be UTF-8-encoded:
                fp = codecs.open(filename, 'r', 'utf-8')
            except IOError:
                continue
            try:
                if sys.version_info < (3,2):
                    CP.RawConfigParser.readfp(self, fp, filename)
                else:
                    CP.RawConfigParser.read_file(self, fp, filename)
            except UnicodeDecodeError:
                self._stderr.write(self.not_utf8_error % (filename, filename))
                fp.close()
                continue
            fp.close()
            self._files.append(filename)
            if self.has_section('options'):
                self.handle_old_config(filename)
            self.validate_settings(filename, option_parser) 
开发者ID:skarlekar,项目名称:faces,代码行数:25,代码来源:frontend.py

示例13: get_hosted_registry_insecure

# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import RawConfigParser [as 别名]
def get_hosted_registry_insecure():
    """ Parses OPTIONS from /etc/sysconfig/docker to determine if the
        registry is currently insecure.
    """
    hosted_registry_insecure = None
    if os.path.exists('/etc/sysconfig/docker'):
        try:
            ini_str = unicode('[root]\n' + open('/etc/sysconfig/docker', 'r').read(), 'utf-8')
            ini_fp = io.StringIO(ini_str)
            config = ConfigParser.RawConfigParser()
            config.readfp(ini_fp)
            options = config.get('root', 'OPTIONS')
            if 'insecure-registry' in options:
                hosted_registry_insecure = True
        except:
            pass
    return hosted_registry_insecure 
开发者ID:openshift,项目名称:origin-ci-tool,代码行数:19,代码来源:openshift_facts.py

示例14: make_config

# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import RawConfigParser [as 别名]
def make_config(confpath=None):
    conf = configparser.RawConfigParser()
    if not confpath: confpath = os.path.expanduser('~/.nxt-python')
    print("Welcome to the nxt-python config file generator!")
    print("This function creates an example file which find_one_brick uses to find a brick.")
    try:
        if os.path.exists(confpath): input("File already exists at %s. Press Enter to overwrite or Ctrl+C to abort." % confpath)
    except KeyboardInterrupt:
        print("Not writing file.")
        return
    conf.add_section('Brick')
    conf.set('Brick', 'name', 'MyNXT')
    conf.set('Brick', 'host', '54:32:59:92:F9:39')
    conf.set('Brick', 'strict', 0)
    conf.set('Brick', 'method', 'usb=True, bluetooth=False')
    conf.write(open(confpath, 'w'))
    print("The file has been written at %s" % confpath)
    print("The file contains less-than-sane default values to get you started.")
    print("You must now edit the file with a text editor and change the values to match what you would pass to find_one_brick")
    print("The fields for name, host, and strict correspond to the similar args accepted by find_one_brick")
    print("The method field contains the string which would be passed to Method()")
    print("Any field whose corresponding option does not need to be passed to find_one_brick should be commented out (using a # at the start of the line) or simply removed.")
    print("If you have questions, check the wiki and then ask on the mailing list.") 
开发者ID:Eelviny,项目名称:nxt-python,代码行数:25,代码来源:locator.py

示例15: _check_file

# 需要导入模块: import configparser [as 别名]
# 或者: from configparser import RawConfigParser [as 别名]
def _check_file(self):
        """
        Check if the file exists and has the expected password reference.
        """
        if not os.path.exists(self.file_path):
            return False
        self._migrate()
        config = configparser.RawConfigParser()
        config.read(self.file_path)
        try:
            config.get(
                escape_for_ini('keyring-setting'), escape_for_ini('password reference')
            )
        except (configparser.NoSectionError, configparser.NoOptionError):
            return False
        try:
            self._check_scheme(config)
        except AttributeError:
            # accept a missing scheme
            return True
        return self._check_version(config) 
开发者ID:jaraco,项目名称:keyrings.alt,代码行数:23,代码来源:file.py


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