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


Python config.Config类代码示例

本文整理汇总了Python中kamaki.cli.config.Config的典型用法代码示例。如果您正苦于以下问题:Python Config类的具体用法?Python Config怎么用?Python Config使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: test_keys

    def test_keys(self, _get_dict):
        from kamaki.cli.config import Config
        _cnf = Config(path=self.f.name)

        self.assertEqual(
            sorted(['k1', 'k2']), sorted(_cnf.keys('opt', 'boolean')))
        _get_dict.assert_called_once_with('opt', 'boolean')
开发者ID:Erethon,项目名称:kamaki,代码行数:7,代码来源:test.py

示例2: test_reload

    def test_reload(self):
        from kamaki.cli.config import Config
        _cnf = Config(path=self.f.name)

        with patch('kamaki.cli.config.Config.__init__') as i:
            _cnf.reload()
            i.assert_called_once_with(self.f.name)
开发者ID:Erethon,项目名称:kamaki,代码行数:7,代码来源:test.py

示例3: test_write

 def test_write(self, stp):
     from kamaki.cli.config import Config
     _cnf = Config(path=self.f.name)
     exp = '%s%s' % (HEADER, 'rv')
     _cnf.write()
     self.f.seek(0)
     self.assertEqual(self.f.read(), exp)
     stp.assert_called_once_with()
     del _cnf
开发者ID:grnet,项目名称:kamaki,代码行数:9,代码来源:test.py

示例4: test_get

 def test_get(self, get_cloud):
     from kamaki.cli.config import Config
     _cnf = Config(path=self.f.name)
     self.assertEqual('pithos', _cnf.get('global', 'file_cli'))
     self.assertEqual(get_cloud.mock_calls, [])
     for opt, sec in (('cloud', 'non-existing'), ('non-opt', 'exists')):
         self.assertEqual(None, _cnf.get(opt, sec))
         self.assertEqual(get_cloud.mock_calls, [])
     self.assertEqual('get cloud', _cnf.get('cloud.demo', 'url'))
     self.assertEqual(get_cloud.mock_calls[-1], call('demo', 'url'))
开发者ID:Erethon,项目名称:kamaki,代码行数:10,代码来源:test.py

示例5: test_remove_from_cloud

    def test_remove_from_cloud(self):
        from kamaki.cli.config import Config, CLOUD_PREFIX
        _cnf = Config(path=self.f.name)

        d = dict(k1='v1', k2='v2')
        with patch('kamaki.cli.config.Config.get', return_value=d) as get:
            _cnf.remove_from_cloud('cld', 'k1')
            self.assertEqual(d, dict(k2='v2'))
            self.assertRaises(KeyError, _cnf.remove_from_cloud, 'cld', 'opt')
            self.assertEqual(get.mock_calls, 2 * [call(CLOUD_PREFIX, 'cld')])
开发者ID:Erethon,项目名称:kamaki,代码行数:10,代码来源:test.py

示例6: __init__

    def __init__(self, *args, **kwargs):
        """Enhance Config to read SYNC sections"""
        Config.__init__(self, *args, **kwargs)

        for section in self.sections():
            r = self.sync_name(section)
            if r:
                for k, v in self.items(section):
                    self.set_sync(r, k, v)
                self.remove_section(section)
开发者ID:jaeko44,项目名称:agkyra,代码行数:10,代码来源:config.py

示例7: test__load_defaults

    def test__load_defaults(self):
        from kamaki.cli.config import Config, DEFAULTS
        _cnf = Config(path=self.f.name)

        with patch('kamaki.cli.config.Config.set') as c_set:
            _cnf._load_defaults()
            for i, (section, options) in enumerate(DEFAULTS.items()):
                for j, (option, val) in enumerate(options.items()):
                    self.assertEqual(
                        c_set.mock_calls[(i + 1) * j],
                        call(section, option, val))
开发者ID:Erethon,项目名称:kamaki,代码行数:11,代码来源:test.py

示例8: test_get_cloud

    def test_get_cloud(self):
        from kamaki.cli.config import Config, CLOUD_PREFIX

        _cnf = Config(path=self.f.name)
        d = dict(opt1='v1', opt2='v2')
        with patch('kamaki.cli.config.Config.get', return_value=d) as get:
            self.assertEqual('v1', _cnf.get_cloud('mycloud', 'opt1'))
            self.assertEqual(
                get.mock_calls[-1], call(CLOUD_PREFIX, 'mycloud'))
            self.assertRaises(KeyError, _cnf.get_cloud, 'mycloud', 'opt3')
        with patch('kamaki.cli.config.Config.get', return_value=0) as get:
            self.assertRaises(KeyError, _cnf.get_cloud, 'mycloud', 'opt1')
开发者ID:Erethon,项目名称:kamaki,代码行数:12,代码来源:test.py

示例9: test_set

    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'))
开发者ID:Erethon,项目名称:kamaki,代码行数:25,代码来源:test.py

示例10: test_set_cloud

    def test_set_cloud(self, c_set):
        from kamaki.cli.config import Config, CLOUD_PREFIX
        _cnf = Config(path=self.f.name)

        d = dict(k='v')
        with patch('kamaki.cli.config.Config.get', return_value=d) as get:
            _cnf.set_cloud('mycloud', 'opt', 'val')
            get.assert_called_once_with(CLOUD_PREFIX, 'mycloud')
            d['opt'] = 'val'
            self.assertEqual(
                c_set.mock_calls[-1], call(CLOUD_PREFIX, 'mycloud', d))

        with patch('kamaki.cli.config.Config.get', return_value=None) as get:
            _cnf.set_cloud('mycloud', 'opt', 'val')
            get.assert_called_once_with(CLOUD_PREFIX, 'mycloud')
            d = dict(opt='val')
            self.assertEqual(
                c_set.mock_calls[-1], call(CLOUD_PREFIX, 'mycloud', d))

        with patch(
                'kamaki.cli.config.Config.get', side_effect=KeyError()) as get:
            _cnf.set_cloud('mycloud', 'opt', 'val')
            get.assert_called_once_with(CLOUD_PREFIX, 'mycloud')
            d = dict(opt='val')
            self.assertEqual(
                c_set.mock_calls[-1], call(CLOUD_PREFIX, 'mycloud', d))
开发者ID:Erethon,项目名称:kamaki,代码行数:26,代码来源:test.py

示例11: safe_to_print

 def safe_to_print(self):
     """Enhance Config.safe_to_print to handle syncs"""
     dump = Config.safe_to_print(self)
     for r, d in self.items(SYNC_PREFIX, include_defaults=False):
         dump += u'\n[%s "%s"]\n' % (SYNC_PREFIX, escape_ctrl_chars(r))
         for k, v in d.items():
             dump += u'%s = %s\n' % (
                 escape_ctrl_chars(k), escape_ctrl_chars(v))
     return dump
开发者ID:jaeko44,项目名称:agkyra,代码行数:9,代码来源:config.py

示例12: test__get_dict

    def test__get_dict(self):
        from kamaki.cli.config import Config, CLOUD_PREFIX, DEFAULTS

        def make_file(lines):
            f = NamedTemporaryFile()
            f.writelines(lines)
            f.flush()
            return f

        with make_file([]) as f:
            _cnf = Config(path=f.name)
            for term in ('global', CLOUD_PREFIX):
                self.assertEqual(DEFAULTS[term], _cnf._get_dict(term))
            for term in ('nosection', ''):
                self.assertEqual({}, _cnf._get_dict(term))

        with make_file(self.config_file_content) as f:
            _cnf = Config(path=f.name)
            for term in ('global', CLOUD_PREFIX):
                self.assertNotEqual(DEFAULTS[term], _cnf._get_dict(term))
开发者ID:Erethon,项目名称:kamaki,代码行数:20,代码来源:test.py

示例13: test_safe_to_print

    def test_safe_to_print(self):
        itemsd = {
            'global': {
                'opt1': 'v1',
                'opt2': 2,
                'opt3': u'\u03c4\u03b9\u03bc\u03ae',
                'opt4': 'un\b\bdeleted'
            }, 'cloud': {
                'cld1': {'url': 'url1', 'token': 'token1'},
                'cld2': {'url': u'\u03bf\u03c5\u03b1\u03c1\u03ad\u03bb'}
            }
        }

        from kamaki.cli.config import Config
        _cnf = Config(path=self.f.name)
        bu_func = Config.items
        try:
            Config.items = (
                lambda cls, opt, include_defaults: itemsd[opt].items())
            saved = _cnf.safe_to_print().split('\n')
            glb, cld = saved[:5], saved[6:]
            self.assertEqual(u'[global]', glb[0])
            self.assertTrue(u'opt1 = v1' in glb)
            self.assertTrue(u'opt2 = 2' in glb)
            self.assertTrue(u'opt3 = \u03c4\u03b9\u03bc\u03ae' in glb)
            self.assertTrue(u'opt4 = un\\x08\\x08deleted' in glb)

            self.assertTrue('[cloud "cld1"]' in cld)
            cld1_i = cld.index('[cloud "cld1"]')
            cld1 = cld[cld1_i: cld1_i + 3]
            self.assertTrue('url = url1' in cld1)
            self.assertTrue('token = token1' in cld1)

            self.assertTrue('[cloud "cld2"]' in cld)
            cld2_i = cld.index('[cloud "cld2"]')
            self.assertEqual(
                u'url = \u03bf\u03c5\u03b1\u03c1\u03ad\u03bb', cld[cld2_i + 1])
        finally:
            Config.items = bu_func
开发者ID:grnet,项目名称:kamaki,代码行数:39,代码来源:test.py

示例14: __init__

    def __init__(self, auth_token, cloud_name=None):

        if auth_token is None and cloud_name is not None:

            # Load .kamakirc configuration
            logger.info("Retrieving .kamakirc configuration")
            self.config = KamakiConfig()
            patch_certs(self.config.get('global', 'ca_certs'))
            cloud_section = self.config._sections['cloud'].get(cloud_name)
            if not cloud_section:
                message = "Cloud '%s' was not found in you .kamakirc configuration file. " \
                          "Currently you have availablie in your configuration these clouds: %s"
                raise KeyError(message % (cloud_name, self.config._sections['cloud'].keys()))

            # Get the authentication url and token
            auth_url, auth_token = cloud_section['url'], cloud_section['token']

        else:
            auth_url = "https://accounts.okeanos.grnet.gr/identity/v2.0"

        logger.info("Initiating Astakos Client")
        self.astakos = astakos.AstakosClient(auth_url, auth_token)

        logger.info("Retrieving cyclades endpoint url")
        compute_url = self.astakos.get_endpoint_url(
            cyclades.CycladesComputeClient.service_type)
        logger.info("Initiating Cyclades client")
        self.cyclades = cyclades.CycladesComputeClient(compute_url, auth_token)

        # Create the network client
        networkURL = self.astakos.get_endpoint_url(
            cyclades.CycladesNetworkClient.service_type)
        self.network_client = cyclades.CycladesNetworkClient(networkURL, auth_token)

        # Constants
        self.Bytes_to_GB = 1024 * 1024 * 1024
        self.Bytes_to_MB = 1024 * 1024

        self.master = None
        self.ips = None
        self.slaves = None
        self.vpn = None
        self.subnet = None
        self.private_key = None
        self.image_id = 'c6f5adce-21ad-4ce3-8591-acfe7eb73c02'
开发者ID:grnet,项目名称:okeanos-LoD,代码行数:45,代码来源:provisioner.py

示例15: get_config

    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
开发者ID:ktsakalozos,项目名称:juju-okeanos-provider,代码行数:17,代码来源:provider.py


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