def test_merge(self):
        user_dir, system_dir = self.create_config_dirs()
        with open(join(system_dir, 'config.yaml'), 'wb') as fd:
            fd.write(b'''
ssl_verify: false
sites:
    develop:
        url: http://develop.anaconda.org
            ''')

        with open(join(user_dir, 'config.yaml'), 'wb') as fd:
            fd.write(b'''
ssl_verify: true
sites:
    develop:
        ssl_verify: false
            ''')

        with mock.patch('binstar_client.utils.config.SEARCH_PATH', [system_dir, user_dir]), \
                mock.patch('binstar_client.utils.config.DEFAULT_CONFIG', {}):
            cfg = config.get_config()

            self.assertEqual(cfg, {
                'ssl_verify': True,
                'sites': {
                    'develop': {
                        'url': 'http://develop.anaconda.org',
                        'ssl_verify': False,
                    }
                }
            })
    def test_support_tags(self):
        user_dir, system_dir = self.create_config_dirs()
        with open(join(user_dir, 'config.yaml'), 'wb') as fd:
            fd.write(b'''
!!python/unicode 'sites':
   !!python/unicode 'alpha': {!!python/unicode 'url': !!python/unicode 'foobar'}
   !!python/unicode 'binstar': {!!python/unicode 'url': !!python/unicode 'barfoo'}
ssl_verify: False
''')

        with mock.patch('binstar_client.utils.config.SEARCH_PATH', [user_dir]), \
                mock.patch('binstar_client.utils.config.DEFAULT_CONFIG', {}):
            cfg = config.get_config()

            self.assertEqual(cfg, {
                'ssl_verify': False,
                'sites': {
                    'alpha': {
                        'url': 'foobar',
                    },
                    'binstar': {
                        'url': 'barfoo',
                    },
                }
            })
Ejemplo n.º 3
0
    def test_merge(self):
        user_dir, system_dir = self.create_config_dirs()
        with open(join(system_dir, 'config.yaml'), 'wb') as fd:
            fd.write(b'''
ssl_verify: false
sites:
    develop:
        url: http://develop.anaconda.org
            ''')

        with open(join(user_dir, 'config.yaml'), 'wb') as fd:
            fd.write(b'''
ssl_verify: true
sites:
    develop:
        ssl_verify: false
            ''')

        with mock.patch('binstar_client.utils.config.SEARCH_PATH', [system_dir, user_dir]), \
                mock.patch('binstar_client.utils.config.DEFAULT_CONFIG', {}):
            cfg = config.get_config()

            self.assertEqual(
                cfg, {
                    'ssl_verify': True,
                    'sites': {
                        'develop': {
                            'url': 'http://develop.anaconda.org',
                            'ssl_verify': False,
                        }
                    }
                })
Ejemplo n.º 4
0
    def test_support_tags(self):
        user_dir, system_dir = self.create_config_dirs()
        with open(join(user_dir, 'config.yaml'), 'wb') as fd:
            fd.write(b'''
!!python/unicode 'sites':
   !!python/unicode 'alpha': {!!python/unicode 'url': !!python/unicode 'foobar'}
   !!python/unicode 'binstar': {!!python/unicode 'url': !!python/unicode 'barfoo'}
ssl_verify: False
''')

        with mock.patch('binstar_client.utils.config.SEARCH_PATH', [user_dir]), \
                mock.patch('binstar_client.utils.config.DEFAULT_CONFIG', {}):
            cfg = config.get_config()

            self.assertEqual(
                cfg, {
                    'ssl_verify': False,
                    'sites': {
                        'alpha': {
                            'url': 'foobar',
                        },
                        'binstar': {
                            'url': 'barfoo',
                        },
                    }
                })
Ejemplo n.º 5
0
    def test_support_tags(self):
        tmpdir = tempfile.mkdtemp()
        self.addCleanup(shutil.rmtree, tmpdir)

        user_dir = join(tmpdir, 'user')
        os.mkdir(user_dir)

        with open(join(user_dir, 'config.yaml'), 'wb') as fd:
            fd.write(b'''
!!python/unicode 'sites':
   !!python/unicode 'alpha': {!!python/unicode 'url': !!python/unicode 'foobar'}
   !!python/unicode 'binstar': {!!python/unicode 'url': !!python/unicode 'barfoo'}
ssl_verify: False
''')

        with mock.patch('binstar_client.utils.config.SEARCH_PATH', [user_dir]), \
                mock.patch('binstar_client.utils.config.DEFAULT_CONFIG', {}):
            cfg = config.get_config()

            self.assertEqual(
                cfg, {
                    'ssl_verify': False,
                    'sites': {
                        'alpha': {
                            'url': 'foobar',
                        },
                        'binstar': {
                            'url': 'barfoo',
                        },
                    }
                })
    def test_defaults(self):
        user_dir, system_dir = self.create_config_dirs()
        with open(join(user_dir, 'config.yaml'), 'wb') as fd:
            fd.write(b'')

        with mock.patch('binstar_client.utils.config.SEARCH_PATH',
                        [system_dir, user_dir]):
            cfg = config.get_config()
            self.assertEqual(cfg, config.DEFAULT_CONFIG)
Ejemplo n.º 7
0
    def test_defaults(self):
        user_dir, system_dir = self.create_config_dirs()
        with open(join(user_dir, 'config.yaml'), 'wb') as fd:
            fd.write(b'')

        with mock.patch('binstar_client.utils.config.SEARCH_PATH',
                        [system_dir, user_dir]):
            cfg = config.get_config()
            self.assertEqual(cfg, config.DEFAULT_CONFIG)
Ejemplo n.º 8
0
def main(args):
    config = get_config()

    if args.show:
        log.info(yaml.safe_dump(config, default_flow_style=False))
        return

    if args.show_sources:
        config_files = load_file_configs(SEARCH_PATH)
        for path in config_files:
            log.info('==> %s <==', path)
            log.info(
                yaml.safe_dump(config_files[path], default_flow_style=False))
        return

    if args.get:
        if args.get in config:
            log.info(config[args.get])
        else:
            log.info("The value of '%s' is not set." % args.get)
        return

    if args.files:
        log.info('User Config: %s' % USER_CONFIG)
        log.info('System Config: %s' % SYSTEM_CONFIG)
        return

    config_file = USER_CONFIG if args.user else SYSTEM_CONFIG

    config = load_config(config_file)

    for key, value in args.set:
        recursive_set(config, key, value, args.type)

    for key in args.remove:
        try:
            recursive_remove(config, key)
        except KeyError:
            log.error("Key %s does not exist" % key)

    if not (args.set or args.remove):
        raise ShowHelp()

    save_config(config, config_file)
    def test_global_url(self):
        """
        Test regression reported on:

        https://github.com/Anaconda-Platform/anaconda-client/issues/464
        """
        user_dir, system_dir = self.create_config_dirs()
        with open(join(user_dir, 'config.yaml'), 'wb') as fd:
            fd.write(b'')

        url_data = {'url': 'https://blob.org'}
        config_data = config.DEFAULT_CONFIG.copy()
        config_data.update(url_data)

        with mock.patch('binstar_client.utils.config.SEARCH_PATH',
                        [system_dir, user_dir]):
            config.save_config(url_data, join(user_dir, 'config.yaml'))
            cfg = config.get_config()
            self.assertEqual(cfg, config_data)
Ejemplo n.º 10
0
    def test_global_url(self):
        """
        Test regression reported on:

        https://github.com/Anaconda-Platform/anaconda-client/issues/464
        """
        user_dir, system_dir = self.create_config_dirs()
        with open(join(user_dir, 'config.yaml'), 'wb') as fd:
            fd.write(b'')

        url_data = {'url': 'https://blob.org'}
        config_data = config.DEFAULT_CONFIG.copy()
        config_data.update(url_data)

        with mock.patch('binstar_client.utils.config.SEARCH_PATH',
                        [system_dir, user_dir]):
            config.save_config(url_data, join(user_dir, 'config.yaml'))
            cfg = config.get_config()
            self.assertEqual(cfg, config_data)
Ejemplo n.º 11
0
def main(args):
    config = get_config()

    if args.show:
        logger.info(yaml_dump(config))
        return

    if args.show_sources:
        config_files = load_file_configs(SEARCH_PATH)
        for path in config_files:
            logger.info('==> %s <==', path)
            logger.info(yaml_dump(config_files[path]))
        return

    if args.get:
        if args.get in config:
            logger.info(config[args.get])
        else:
            logger.info("The value of '%s' is not set." % args.get)
        return

    if args.files:
        logger.info('User Config: %s' % USER_CONFIG)
        logger.info('System Config: %s' % SYSTEM_CONFIG)
        return

    config_file = USER_CONFIG if args.user else SYSTEM_CONFIG

    config = load_config(config_file)

    for key, value in args.set:
        recursive_set(config, key, value, args.type)

    for key in args.remove:
        try:
            recursive_remove(config, key)
        except KeyError:
            logger.error("Key %s does not exist" % key)

    if not (args.set or args.remove):
        raise ShowHelp()

    save_config(config, config_file)
Ejemplo n.º 12
0
    def test_merge(self):
        tmpdir = tempfile.mkdtemp()
        self.addCleanup(shutil.rmtree, tmpdir)

        system_dir = join(tmpdir, 'system')
        user_dir = join(tmpdir, 'user')
        os.mkdir(system_dir)
        os.mkdir(user_dir)

        with open(join(system_dir, 'config.yaml'), 'wb') as fd:
            fd.write(b'''
ssl_verify: false
sites:
    develop:
        url: http://develop.anaconda.org
            ''')

        with open(join(user_dir, 'config.yaml'), 'wb') as fd:
            fd.write(b'''
ssl_verify: true
sites:
    develop:
        ssl_verify: false
            ''')


        with mock.patch('binstar_client.utils.config.SEARCH_PATH', [system_dir, user_dir]), \
                mock.patch('binstar_client.utils.config.DEFAULT_CONFIG', {}):
            cfg = config.get_config()

            self.assertEqual(cfg, {
                'ssl_verify': True,
                'sites': {
                    'develop': {
                        'url': 'http://develop.anaconda.org',
                        'ssl_verify': False,
                    }
                }
            })