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


Python configobj.ConfigObj方法代码示例

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


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

示例1: vReadIniFile

# 需要导入模块: import configobj [as 别名]
# 或者: from configobj import ConfigObj [as 别名]
def vReadIniFile(self):
        assert self.sIniFile, "ERROR: No INI file defined"
        sIniFile = self.sIniFile
        if not os.path.isabs(sIniFile):
            sIniFile = os.path.join(os.path.dirname(__file__), self.sIniFile)
        assert os.path.isfile(sIniFile)
        if os.path.isfile(sIniFile) and not self.oConfigObj:
            oConfigObj = ConfigObj(sIniFile, unrepr=True)
            self.oFd.write("INFO: Read INI file: " +oConfigObj.filename +'\n')
            self.oConfigObj = oConfigObj
            for sKey, gValue in oConfigObj['default'].items():
                setattr(self, sKey, gValue)

            self.lRequiredFeeds = [oConfigObj[s] for s in
                                   self.lRequiredFeedParams]
            self.lRequiredDishes = [oConfigObj[s] for s in
                                   self.lRequiredDishesParams]
            # eliminate
            self.lRequiredIngredients = []
            for sElt in self.lRequiredIngredients:
                self.lRequiredDishes += [sElt]
                for sKey in oConfigObj[sElt].keys():
                    if sKey not in self.lRequiredIngredients:
                        self.lRequiredIngredients += [sKey] 
开发者ID:OpenTrading,项目名称:OpenTrader,代码行数:26,代码来源:Recipe.py

示例2: initialize

# 需要导入模块: import configobj [as 别名]
# 或者: from configobj import ConfigObj [as 别名]
def initialize(self, options):
		self.options = options
		self.mon_interface = options.interface
		self.aircfg = options.aircfg
		self.dnspwn = options.dnspwn

		if os.geteuid() != 0:
			sys.exit("[-] AirPwn plugin requires root privileges")

		if not self.mon_interface:
			sys.exit("[-] AirPwn plugin requires --miface argument")

		try:
			self.aircfg = ConfigObj("./config/airpwn.cfg")
			#Here we compile the regexes for faster performance when injecting packets
			for rule in self.aircfg.items():
				rule[1]['match'] = re.compile(r'%s' % rule[1]['match'])
				if 'ignore' in rule[1].keys():
					rule[1]['ignore'] = re.compile(r'%s' % rule[1]['ignore'])

		except Exception, e:
			sys.exit("[-] Error parsing airpwn config file: %s" % e) 
开发者ID:byt3bl33d3r,项目名称:MITMf-opt-plugins,代码行数:24,代码来源:AirPwn.py

示例3: parse_service_info

# 需要导入模块: import configobj [as 别名]
# 或者: from configobj import ConfigObj [as 别名]
def parse_service_info(service):
    service = service or os.getenv("PGSERVICE")
    service_file = os.getenv("PGSERVICEFILE")
    if not service_file:
        # try ~/.pg_service.conf (if that exists)
        if platform.system() == "Windows":
            service_file = os.getenv("PGSYSCONFDIR") + "\\pg_service.conf"
        elif os.getenv("PGSYSCONFDIR"):
            service_file = os.path.join(os.getenv("PGSYSCONFDIR"), ".pg_service.conf")
        else:
            service_file = expanduser("~/.pg_service.conf")
    if not service:
        # nothing to do
        return None, service_file
    service_file_config = ConfigObj(service_file)
    if service not in service_file_config:
        return None, service_file
    service_conf = service_file_config.get(service)
    return service_conf, service_file 
开发者ID:dbcli,项目名称:pgcli,代码行数:21,代码来源:main.py

示例4: _get_zookeeper_servers

# 需要导入模块: import configobj [as 别名]
# 或者: from configobj import ConfigObj [as 别名]
def _get_zookeeper_servers(self, config):
        """
        This method parses and stores the ZooKeeper servers to be used by the system

        Args:
            config (ConfigObj): The ConfigObj that holds the configuration

        Returns:
            None
        """
        zookeeper_servers = set()
        for zookeeper_server_id in config[u'zookeeper'][u'servers']:
            zookeeper_server = config[u'zookeeper'][u'servers'][zookeeper_server_id][u'host'] + u':' + \
                               str(config[u'zookeeper'][u'servers'][zookeeper_server_id][u'port'])
            zookeeper_servers.add(zookeeper_server)

        self._zookeeper_servers = zookeeper_servers 
开发者ID:yahoo,项目名称:panoptes,代码行数:19,代码来源:configuration_manager.py

示例5: _get_kafka_brokers

# 需要导入模块: import configobj [as 别名]
# 或者: from configobj import ConfigObj [as 别名]
def _get_kafka_brokers(self, config):
        """
        This method parses and stores the Kafka brokers to be used by the system

        Args:
            config (ConfigObj): The ConfigObj that holds the configuration

        Returns:
            None
        """
        kafka_brokers = set()
        for kafka_broker_id in config[u'kafka'][u'brokers']:
            kafka_broker = config[u'kafka'][u'brokers'][kafka_broker_id][u'host'] + u':' + \
                           str(config[u'kafka'][u'brokers'][kafka_broker_id][u'port'])

            kafka_brokers.add(kafka_broker)

        self._kafka_brokers = kafka_brokers 
开发者ID:yahoo,项目名称:panoptes,代码行数:20,代码来源:configuration_manager.py

示例6: test_polling_no_matching_transform_type

# 需要导入模块: import configobj [as 别名]
# 或者: from configobj import ConfigObj [as 别名]
def test_polling_no_matching_transform_type(self, message_producer, message_producer_property, kv_store):

        mock_panoptes_plugin = MockPanoptesObject()
        mock_panoptes_plugin.config = ConfigObj(
            pwd + u'/config_files/test_panoptes_polling_plugin_conf_diff_transform_callback.ini')
        kv_store.return_value = PanoptesMockRedis()

        mock_message_producer = MockPanoptesMessageProducer()

        message_producer.return_value = mock_message_producer
        message_producer_property.return_value = message_producer_property

        panoptes_context = PanoptesContext(config_file=os.path.join(path, u'config_files/test_panoptes_config.ini'))

        for i in range(1, 9):
            panoptes_metrics = self.prepare_panoptes_metrics_group_set(
                u'{}/metric_group_sets/interface_plugin_counter_{}.json'.format(pwd, i))
            _process_metrics_group_set(context=panoptes_context, results=panoptes_metrics, plugin=mock_panoptes_plugin)

        self.assertEqual(
            panoptes_context.message_producer.messages,
            []
        ) 
开发者ID:yahoo,项目名称:panoptes,代码行数:25,代码来源:test_plugin_agent.py

示例7: write_voice_ini

# 需要导入模块: import configobj [as 别名]
# 或者: from configobj import ConfigObj [as 别名]
def write_voice_ini():
    """Read the voices folder and write the result to voices.ini."""
    def get_immediate_subdirectories(a_dir):
        """Return the immediate subdirs."""
        return [name for name in os.listdir(a_dir)
                if os.path.isdir(os.path.join(a_dir, name))]

    program_path = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
    voices_path = program_path + os.sep + 'talker' + os.sep + 'voices'
    config = ConfigObj(voices_path + os.sep + 'voices.ini', indent_type='    ')

    lang_list = get_immediate_subdirectories(voices_path)
    for lang_dir_name in lang_list:
        print(lang_dir_name)
        config[lang_dir_name] = {}
        speak_list = get_immediate_subdirectories(voices_path + os.sep + lang_dir_name)
        for speak_dir_name in speak_list:
            config[lang_dir_name][speak_dir_name] = {}
            config[lang_dir_name][speak_dir_name]['small'] = speak_dir_name[:6]
            config[lang_dir_name][speak_dir_name]['medium'] = speak_dir_name[:8].title()
            config[lang_dir_name][speak_dir_name]['large'] = speak_dir_name[:11].title()
    config.write() 
开发者ID:jromang,项目名称:picochess,代码行数:24,代码来源:voices.py

示例8: load_conf_from_file

# 需要导入模块: import configobj [as 别名]
# 或者: from configobj import ConfigObj [as 别名]
def load_conf_from_file(path=None, section='marvin'):
    data = {}
    config_path = path  # try to get config path from args
    if not config_path:  # try to get config file from env
        config_path = os.getenv('MARVIN_CONFIG_FILE') or os.getenv('CONFIG_FILE')
    if not config_path:  # use default file
        config_path = os.getenv("DEFAULT_CONFIG_PATH")
    logger.info('Loading configuration values from "{path}"...'.format(path=config_path))
    config_parser = ConfigObj(config_path)
    try:
        data = config_parser[section]
    except NoSectionError:
        logger.warn('Couldn\'t find "{section}" section in "{path}"'.format(
            section=section, path=config_path
        ))

    return data 
开发者ID:marvin-ai,项目名称:marvin-python-toolbox,代码行数:19,代码来源:config.py

示例9: test_validate_profile_infos

# 需要导入模块: import configobj [as 别名]
# 或者: from configobj import ConfigObj [as 别名]
def test_validate_profile_infos(tmpdir, false_plugin_with_holder):
    """Test validating a profile.

    """
    i = ProfileInfos(path=PROFILE_PATH, plugin=false_plugin_with_holder)
    r, msg = validate_profile_infos(i)
    assert r

    for p, m in [(os.path.join(str(tmpdir), 'd_%s.instr.ini' % m), m)
                 for m in ('id', 'model_id', 'connections', 'settings')]:
        c = ConfigObj(PROFILE_PATH)
        del c[m]
        with open(p, 'wb') as f:
            c.write(f)
        i = ProfileInfos(path=p, plugin=false_plugin_with_holder)
        r, msg = validate_profile_infos(i)
        assert not r
        assert m in msg 
开发者ID:Exopy,项目名称:exopy,代码行数:20,代码来源:test_infos.py

示例10: instr_task_workbench

# 需要导入模块: import configobj [as 别名]
# 或者: from configobj import ConfigObj [as 别名]
def instr_task_workbench(instr_workbench):
    """Workbench with instrument and task support and patched task.

    """
    w = instr_workbench
    w.register(InstrContributor())
    c = ConfigObj(PROFILE_PATH, encoding='utf-8')
    add_profile(instr_workbench, c, ['fp1', 'fp2', 'fp3', 'fp4'])
    w.register(TasksManagerManifest())
    p = w.get_plugin('exopy.tasks')
    infos = TaskInfos(cls=InterInstrTask,
                      instruments=['tasks.test.FalseDriver'])
    infos.interfaces = \
        {'test.I': InterfaceInfos(cls=TaskInterface, parent=infos,
                                  instruments=['tasks.test.FalseDriver4',
                                               'tasks.test.FalseDriver2']
                                  )
         }
    p._tasks.contributions['exopy.InstrumentTask'] = infos

    return w 
开发者ID:Exopy,项目名称:exopy,代码行数:23,代码来源:test_instr_view.py

示例11: test_app_startup3

# 需要导入模块: import configobj [as 别名]
# 或者: from configobj import ConfigObj [as 别名]
def test_app_startup3(pref_workbench, tmpdir, exopy_qtbot):
    """Test app start-up when a preference file already exists.

    """
    manifest = PreferencesManifest()
    pref_workbench.register(manifest)

    # Create a trash app_directory.ini file. The global fixture ensure
    # that it cannot be a user file. Don't use app_dir fixture as I need to
    # test directory creation.
    app_pref = os.path.join(exopy_path(), APP_PREFERENCES, APP_DIR_CONFIG)
    app_dir = str(tmpdir.join('exopy'))
    conf = ConfigObj(encoding='utf8')
    conf.filename = app_pref
    conf['app_path'] = app_dir
    conf.write()

    assert not os.path.isdir(app_dir)

    # Start the app and fake a user answer.
    app = pref_workbench.get_plugin('exopy.app')

    app.run_app_startup(object())

    assert os.path.isdir(app_dir) 
开发者ID:Exopy,项目名称:exopy,代码行数:27,代码来源:test_prefs.py

示例12: test_load_defaultini

# 需要导入模块: import configobj [as 别名]
# 或者: from configobj import ConfigObj [as 别名]
def test_load_defaultini(pref_workbench, app_dir):
    """Test that a default.ini file found in the app folder under prefs
    is loaded on startup.

    """
    prefs_path = os.path.join(app_dir, 'preferences')
    os.mkdir(os.path.join(app_dir, 'preferences'))

    conf = ConfigObj(os.path.join(prefs_path, 'default.ini'))
    c_man = PrefContributor()
    conf[c_man.id] = {}
    conf[c_man.id]['string'] = 'This is a test'
    conf.write()

    pref_man = PreferencesManifest()
    pref_workbench.register(pref_man)
    pref_workbench.register(c_man)

    c_pl = pref_workbench.get_plugin(c_man.id)

    assert c_pl.string == 'This is a test' 
开发者ID:Exopy,项目名称:exopy,代码行数:23,代码来源:test_prefs.py

示例13: test_auto_sync

# 需要导入模块: import configobj [as 别名]
# 或者: from configobj import ConfigObj [as 别名]
def test_auto_sync(pref_workbench, app_dir):
    """Check that auito_sync members are correctly handled.

    """
    pref_workbench.register(PreferencesManifest())
    c_man = PrefContributor()
    pref_workbench.register(c_man)

    contrib = pref_workbench.get_plugin(c_man.id)
    contrib.auto = 'test_auto'

    ref = {c_man.id: {'auto': 'test_auto'}}
    path = os.path.join(app_dir, 'preferences', 'default.ini')
    assert os.path.isfile(path)
    assert ConfigObj(path).dict() == ref

    contrib.auto = 'test'

    ref = {c_man.id: {'auto': 'test'}}
    path = os.path.join(app_dir, 'preferences', 'default.ini')
    assert os.path.isfile(path)
    assert ConfigObj(path).dict() == ref 
开发者ID:Exopy,项目名称:exopy,代码行数:24,代码来源:test_prefs.py

示例14: test_save1

# 需要导入模块: import configobj [as 别名]
# 或者: from configobj import ConfigObj [as 别名]
def test_save1(pref_workbench, app_dir):
    """Test saving to the default file.

    """
    pref_workbench.register(PreferencesManifest())
    c_man = PrefContributor()
    pref_workbench.register(c_man)

    contrib = pref_workbench.get_plugin(c_man.id)
    contrib.string = 'test_save'

    core = pref_workbench.get_plugin('enaml.workbench.core')
    core.invoke_command('exopy.app.preferences.save', {}, pref_workbench)

    path = os.path.join(app_dir, 'preferences', 'default.ini')
    ref = {c_man.id: {'string': 'test_save', 'auto': ''}}
    assert os.path.isfile(path)
    assert ConfigObj(path).dict() == ref 
开发者ID:Exopy,项目名称:exopy,代码行数:20,代码来源:test_prefs.py

示例15: test_load1

# 需要导入模块: import configobj [as 别名]
# 或者: from configobj import ConfigObj [as 别名]
def test_load1(pref_workbench, app_dir):
    """Test loading default preferences for unstarted plugin.

    """
    # Register and start preferences plugin
    pref_workbench.register(PreferencesManifest())
    pref_workbench.get_plugin(PLUGIN_ID)

    c_man = PrefContributor()
    pref_workbench.register(c_man)

    path = os.path.join(app_dir, 'preferences', 'default.ini')
    conf = ConfigObj(path)
    conf[c_man.id] = {}
    conf[c_man.id]['string'] = 'test'
    conf.write()

    core = pref_workbench.get_plugin('enaml.workbench.core')
    core.invoke_command('exopy.app.preferences.load', {})
    assert pref_workbench.get_plugin(c_man.id, False) is None
    contrib = pref_workbench.get_plugin(c_man.id)

    assert contrib.string == 'test' 
开发者ID:Exopy,项目名称:exopy,代码行数:25,代码来源:test_prefs.py


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