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


Python ConfigParser.ConfigParser方法代码示例

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


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

示例1: write_config

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import ConfigParser [as 别名]
def write_config(self):
    """Write user's configuration file."""

    logging.debug('[VT Plugin] Writing user config file: %s', self.vt_cfgfile)

    try:
      parser = configparser.ConfigParser()
      config_file = open(self.vt_cfgfile, 'w')
      parser.add_section('General')
      parser.set('General', 'auto_upload', str(self.auto_upload))
      parser.write(config_file)
      config_file.close()
    except:
      logging.error('[VT Plugin] Error while creating the user config file.')
      return False
    return True 
开发者ID:VirusTotal,项目名称:vt-ida-plugin,代码行数:18,代码来源:plugin_loader.py

示例2: __init__

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import ConfigParser [as 别名]
def __init__(self, openedConfigFile, section, defaultDict=None):
        """

        @param openedConfigFile:
        @param section:
        @param defaultDict: if mapping not present in the config file, this mapping is used
        @return:
        """
        self._config = ConfigParser.ConfigParser()
        self._config.readfp(openedConfigFile)
        self._section = section
        self._configFilePath = openedConfigFile.name
        if defaultDict is not None:
            self._defaultDict = defaultDict
        else:
            self._defaultDict = dict() 
开发者ID:CAMI-challenge,项目名称:CAMISIM,代码行数:18,代码来源:config.py

示例3: copy_dependencies

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import ConfigParser [as 别名]
def copy_dependencies(f):
    config_path = '/etc/yangcatalog/yangcatalog.conf'
    config = ConfigParser.ConfigParser()
    config._interpolation = ConfigParser.ExtendedInterpolation()
    config.read(config_path)
    yang_models = config.get('Directory-Section', 'save-file-dir')
    tmp = config.get('Directory-Section', 'temp')
    out = f.getvalue()
    letters = string.ascii_letters
    suffix = ''.join(random.choice(letters) for i in range(8))
    dep_dir = '{}/yangvalidator-dependencies-{}'.format(tmp, suffix)
    os.mkdir(dep_dir)
    dependencies = out.split(':')[1].strip().split(' ')
    for dep in dependencies:
        for file in glob.glob(r'{}/{}*.yang'.format(yang_models, dep)):
            shutil.copy(file, dep_dir)
    return dep_dir 
开发者ID:YangCatalog,项目名称:bottle-yang-extractor-validator,代码行数:19,代码来源:views.py

示例4: parse

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import ConfigParser [as 别名]
def parse(self, filepath=None):
        result = dict()
        result['errors'] = list()
        if filepath:
            appconf = filepath
        else:
            appconf =None
        if appconf:
            try:
                appconfig = ConfigParser.ConfigParser()
                appconfig.readfp(open(appconf))
                self.__add_checks__(appconfig, result) 
                self.__read_config__(appconfig, result)
            except Exception:
                raise Exception('Cannot read config file ' + str(appconf))
        self.options = result
        return self 
开发者ID:koenbuyens,项目名称:securityheaders,代码行数:19,代码来源:optionparser.py

示例5: read_profiles

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import ConfigParser [as 别名]
def read_profiles(basepath, list_profiles):
    """
    Parse Firefox profiles in provided location.
    If list_profiles is true, will exit after listing available profiles.
    """
    profileini = os.path.join(basepath, "profiles.ini")

    LOG.debug("Reading profiles from %s", profileini)

    if not os.path.isfile(profileini):
        LOG.warning("profile.ini not found in %s", basepath)
        raise Exit(Exit.MISSING_PROFILEINI)

    # Read profiles from Firefox profile folder
    profiles = ConfigParser()
    profiles.read(profileini)

    LOG.debug("Read profiles %s", profiles.sections())

    if list_profiles:
        LOG.debug("Listing available profiles...")
        print_sections(get_sections(profiles), sys.stdout)
        raise Exit(0)

    return profiles 
开发者ID:unode,项目名称:firefox_decrypt,代码行数:27,代码来源:firefox_decrypt.py

示例6: __init__

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import ConfigParser [as 别名]
def __init__(self, author_filename, default_address, only_addresses = None, update_interval=timedelta(hours=1)):
    from ConfigParser import ConfigParser

    self.author_filename = author_filename
    self.default_address = default_address
    self.only_addresses = only_addresses
    self.update_interval = update_interval

    self.config_parser = ConfigParser()
    self.config_parser.read(self.author_filename)

    self.time_checked = datetime.utcnow()
    self.time_loaded  = datetime.utcfromtimestamp(os.path.getmtime(self.author_filename))

    if only_addresses:
      import re
      self.address_match_p = re.compile(only_addresses).match
    else:
      self.address_match_p = lambda addr: True 
开发者ID:llvm,项目名称:llvm-zorg,代码行数:21,代码来源:ConfigEmailLookup.py

示例7: main

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import ConfigParser [as 别名]
def main():
    if len(sys.argv) < 2:
        usage()

    hashed_password = hashpw(sys.argv[1], gensalt(log_rounds=DEFAULT_ROUNDS))

    configparser = ConfigParser.ConfigParser()
    configparser.add_section('config')
    configparser.set('config', 'password_hash', hashed_password)
    
    try:
        config_file = open('config.ini', 'w')
        configparser.write(config_file)
    except Exception as err:
        print "[!] Error creating config file: %s" % err
        sys.exit()
        
    print "[+] Configuration file created successfully."
    config_file.close() 
开发者ID:juliocesarfort,项目名称:nukemyluks,代码行数:21,代码来源:generateconfig.py

示例8: __init__

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import ConfigParser [as 别名]
def __init__(self, results_queue, thread_pool, use_file=True, use_database=True, filename="proxy-ip-list.csv"):
        self.use_file = use_file
        self.use_database = use_database
        self.filename = filename
        self.results_queue = results_queue
        self.thread_pool = thread_pool

        if use_database:
            try:
                cf = ConfigParser.ConfigParser()
                cf.read("config.ini")
                db_name = cf.get("Pansidong", "database")
                username = cf.get(db_name, "username")
                password = cf.get(db_name, "password")
                host = cf.get(db_name, "host")
                database = cf.get(db_name, "database")
            except AttributeError, e:
                logger.fatal(e.message)
                sys.exit(1)
            self.engine = create_engine("mysql://" + username + ":" + password + "@" +
                                        host + "/" + database + "?charset=utf8")
            self.db_session = sessionmaker(bind=self.engine)
            self.session = self.db_session() 
开发者ID:lightless233,项目名称:Pansidong,代码行数:25,代码来源:SaveData.py

示例9: install_hg

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import ConfigParser [as 别名]
def install_hg(path):
    """ Install hook in Mercurial repository. """
    hook = op.join(path, 'hgrc')
    if not op.isfile(hook):
        open(hook, 'w+').close()

    c = ConfigParser()
    c.readfp(open(hook, 'r'))
    if not c.has_section('hooks'):
        c.add_section('hooks')

    if not c.has_option('hooks', 'commit'):
        c.set('hooks', 'commit', 'python:pylama.hooks.hg_hook')

    if not c.has_option('hooks', 'qrefresh'):
        c.set('hooks', 'qrefresh', 'python:pylama.hooks.hg_hook')

    c.write(open(hook, 'w+')) 
开发者ID:AtomLinter,项目名称:linter-pylama,代码行数:20,代码来源:hook.py

示例10: create_server_conf

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import ConfigParser [as 别名]
def create_server_conf(data, version):
    """Create (or edit) default configuration file of odoo
    :params data: Dict with all info to save in file"""
    fname_conf = os.path.expanduser('~/.openerp_serverrc')
    if not os.path.exists(fname_conf):
        # If not exists the file then is created
        fconf = open(fname_conf, "w")
        fconf.close()
    config = ConfigParser.ConfigParser()
    config.read(fname_conf)
    if not config.has_section('options'):
        config.add_section('options')
    for key, value in data.items():
        config.set('options', key, value)
    with open(fname_conf, 'w') as configfile:
        config.write(configfile) 
开发者ID:OCA,项目名称:maintainer-quality-tools,代码行数:18,代码来源:test_server.py

示例11: dashboard_at

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import ConfigParser [as 别名]
def dashboard_at(api, filename, datetime=None, revision=None):
    if datetime:
        revision = revision_at(api, datetime)
    if not revision:
        return revision

    content = api.pseudometa_file_load(filename, revision)
    if filename in ('ignored_requests'):
        if content:
            return yaml.safe_load(content)
        return {}
    elif filename in ('config'):
        if content:
            # TODO re-use from osclib.conf.
            from ConfigParser import ConfigParser
            import io

            cp = ConfigParser()
            config = '[remote]\n' + content
            cp.readfp(io.BytesIO(config))
            return dict(cp.items('remote'))
        return {}

    return content 
开发者ID:openSUSE,项目名称:openSUSE-release-tools,代码行数:26,代码来源:metrics.py

示例12: __init__

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import ConfigParser [as 别名]
def __init__(self, configpath):
        # Import config parser
        try:
            from ConfigParser import ConfigParser
        except ImportError:
            from configparser import ConfigParser

        # Read the configuration file
        config = ConfigParser()
        config.read(configpath)
        self._config = config

        self._check_inpaths()
        self._check_methods('opne')
        self._check_methods('other')
        self._checkparams()
        self._check_edges()
        self._check_task() 
开发者ID:Dru-Mara,项目名称:EvalNE,代码行数:20,代码来源:pipeline.py

示例13: _read_board

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import ConfigParser [as 别名]
def _read_board(self):
        board = ''

        # -- Read config file: old JSON format
        with open(PROJECT_FILENAME, 'r') as f:
            try:
                data = json.loads(f.read())
                board = data.get('board')
            except Exception:
                pass

        # -- Read config file: new CFG format
        if board == '':
            try:
                config = ConfigParser.ConfigParser()
                config.read(PROJECT_FILENAME)
                board = config.get('env', 'board')
            except Exception:
                print('Error: invalid {} project file'.format(
                    PROJECT_FILENAME))
                sys.exit(1)

        return board 
开发者ID:FPGAwars,项目名称:apio,代码行数:25,代码来源:project.py

示例14: config_get

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import ConfigParser [as 别名]
def config_get(section, option, raise_exception=True, default=None):
    """
    Return the string value for a given option in a section

    :param section: the named section.
    :param option: the named option.
    :param raise_exception: Boolean to raise or not NoOptionError or NoSectionError.
    :param default: the default value if not found.
.
    :returns: the configuration value.
    """
    try:
        return get_config().get(section, option)
    except (ConfigParser.NoOptionError, ConfigParser.NoSectionError) as err:
        if raise_exception and default is None:
            raise err
        return default 
开发者ID:rucio,项目名称:rucio,代码行数:19,代码来源:config.py

示例15: __init__

# 需要导入模块: import ConfigParser [as 别名]
# 或者: from ConfigParser import ConfigParser [as 别名]
def __init__(self):
        if sys.version_info < (3, 2):
            self.parser = ConfigParser.SafeConfigParser(os.environ)
        else:
            self.parser = ConfigParser.ConfigParser(defaults=os.environ)

        if 'RUCIO_CONFIG' in os.environ:
            self.configfile = os.environ['RUCIO_CONFIG']
        else:
            configs = [os.path.join(confdir, 'rucio.cfg') for confdir in get_config_dirs()]
            self.configfile = next(iter(filter(os.path.exists, configs)), None)
            if self.configfile is None:
                raise RuntimeError('Could not load Rucio configuration file. '
                                   'Rucio looked in the following paths for a configuration file, in order:'
                                   '\n\t' + '\n\t'.join(configs))

        if not self.parser.read(self.configfile) == [self.configfile]:
            raise RuntimeError('Could not load Rucio configuration file. '
                               'Rucio tried loading the following configuration file:'
                               '\n\t' + self.configfile) 
开发者ID:rucio,项目名称:rucio,代码行数:22,代码来源:config.py


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