本文整理汇总了Python中kamaki.cli.config.Config.set方法的典型用法代码示例。如果您正苦于以下问题:Python Config.set方法的具体用法?Python Config.set怎么用?Python Config.set使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类kamaki.cli.config.Config
的用法示例。
在下文中一共展示了Config.set方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_set
# 需要导入模块: from kamaki.cli.config import Config [as 别名]
# 或者: from kamaki.cli.config.Config import set [as 别名]
def test_set(self):
from kamaki.cli.config import Config, CLOUD_PREFIX
_cnf = Config(path=self.f.name)
with patch(
'kamaki.cli.config.Config._cloud_name',
return_value='cn') as _cloud_name:
with patch(
'kamaki.cli.config.Config.set_cloud',
return_value='sc') as set_cloud:
self.assertEqual(
'sc', _cnf.set('%s.sec' % CLOUD_PREFIX, 'opt', 'val'))
self.assertEqual(
_cloud_name.mock_calls[-1],
call('%s "sec"' % CLOUD_PREFIX))
self.assertEqual(
set_cloud.mock_calls[-1], call('cn', 'opt', 'val'))
self.assertTrue(len(_cnf.items('global')) > 0)
self.assertEqual(None, _cnf.set('global', 'opt', 'val'))
self.assertTrue(('opt', 'val') in _cnf.items('global'))
self.assertTrue(len(_cnf.items('new')) == 0)
self.assertEqual(None, _cnf.set('new', 'opt', 'val'))
self.assertTrue(('opt', 'val') in _cnf.items('new'))
示例2: test_remove_option
# 需要导入模块: from kamaki.cli.config import Config [as 别名]
# 或者: from kamaki.cli.config.Config import set [as 别名]
def test_remove_option(self):
from kamaki.cli.config import Config
_cnf = Config(path=self.f.name)
self.assertEqual(len(_cnf.items('no-section')), 0)
_cnf.remove_option('no-section', 'opt', False)
self.assertEqual(len(_cnf.items('no-section')), 0)
_cnf.remove_option('no-section', 'opt', True)
self.assertEqual(len(_cnf.items('no-section')), 0)
opt_num = len(_cnf.items('global'))
self.assertTrue(opt_num > 0)
_cnf.remove_option('global', 'file_cli', False)
self.assertEqual(len(_cnf.items('global')), opt_num)
_cnf.remove_option('global', 'file_cli', True)
self.assertEqual(len(_cnf.items('global')), opt_num - 1)
_cnf.set('global', 'server_cli', 'alt-server')
self.assertTrue(('server_cli', 'alt-server') in _cnf.items('global'))
self.assertFalse(('server_cli', 'cyclades') in _cnf.items('global'))
_cnf.remove_option('global', 'server_cli', False)
self.assertFalse(('server_cli', 'alt-server') in _cnf.items('global'))
self.assertTrue(('server_cli', 'cyclades') in _cnf.items('global'))
_cnf.remove_option('global', 'server_cli', True)
self.assertFalse(('server_cli', 'alt-server') in _cnf.items('global'))
self.assertFalse(('server_cli', 'cyclades') in _cnf.items('global'))
示例3: get_config
# 需要导入模块: from kamaki.cli.config import Config [as 别名]
# 或者: from kamaki.cli.config.Config import set [as 别名]
def get_config(cls):
okeanos_ssh_key_path = os.environ.get('OKEANOS_SSH_KEY')
if not okeanos_ssh_key_path:
raise ConfigError("Please set the OKEANOS_SSH_KEY with the path to your public ssh key")
kamakirc_path = os.environ.get('OKEANOS_KAMAKIRC')
okeanos_config = Config(kamakirc_path)
# This is debian specific... for now...
okeanos_config.set('global', 'ca_certs', '/etc/ssl/certs/ca-certificates.crt')
cloud_name = okeanos_config.get('global', 'default_cloud')
auth_url = okeanos_config.get_cloud(cloud_name, 'url')
auth_token = okeanos_config.get_cloud(cloud_name, 'token')
if (not cloud_name or not auth_url or not auth_token):
raise ConfigError("Wrong okeanos configuration")
return okeanos_config
示例4: test_write
# 需要导入模块: from kamaki.cli.config import Config [as 别名]
# 或者: from kamaki.cli.config.Config import set [as 别名]
def test_write(self):
from kamaki.cli.config import Config, DEFAULTS
_cnf = Config(path=self.f.name)
exp = '%s[global]\n' % HEADER
exp += ''.join([
'%s = %s\n' % (k, v) for k, v in DEFAULTS['global'].items()])
exp += '\n'
_cnf.write()
self.f.seek(0)
self.assertEqual(self.f.read(), exp)
del _cnf
with NamedTemporaryFile() as f:
f.write('\n'.join(self.config_file_content))
f.flush()
_cnf = Config(path=f.name)
f.seek(0)
self.assertEqual(f.read(), '\n'.join(self.config_file_content))
_cnf.write()
f.seek(0)
file_contents = f.read()
for line in self.config_file_content:
self.assertTrue(line in file_contents)
_cnf.set('sec', 'opt', 'val')
_cnf.set('global', 'opt', 'val')
_cnf.set('global', 'file_cli', 'val')
_cnf.write()
f.seek(0)
file_contents = f.read()
for line in ('file_cli = val\n', '[sec]\n', 'opt = val\n'):
self.assertTrue(line in file_contents)