# Path: binstar_client/utils/config.py
# SEARCH_PATH = (
#     dirs.site_data_dir,
#     '/etc/anaconda-client/',
#     '$CONDA_ROOT/etc/anaconda-client/',
#     dirs.user_data_dir,
#     '~/.continuum/anaconda-client/',
#     '$CONDA_PREFIX/etc/anaconda-client/',
# )
# 
# USER_CONFIG = join(dirs.user_data_dir, 'config.yaml')
# 
# SYSTEM_CONFIG = SITE_CONFIG
# 
# CONFIGURATION_KEYS = [
#     'auto_register',
#     'default_site',
#     'upload_user',
#     'sites',
#     'url',
#     'verify_ssl',
#     'ssl_verify',
# ]
# 
# def get_config(site=None):
#     config = DEFAULT_CONFIG.copy()
# 
#     file_configs = load_file_configs(SEARCH_PATH)
#     for fn in file_configs:
#         recursive_update(config, file_configs[fn])
# 
#     site = site or config.get('default_site')
#     sites = config.get('sites', {})
# 
#     if site:
#         site = str(site)
# 
#         if site not in sites:
#             logger.warning('Site alias "%s" does not exist in the config file', site)
#         else:
#             # This takes whatever keys are set for the site into the top level of the config dict
#             recursive_update(config, sites.get(site, {}))
# 
#     return config
# 
# def save_config(data, config_file):
#     data_dir = dirname(config_file)
# 
#     try:
#         if not exists(data_dir):
#             os.makedirs(data_dir)
# 
#         with open(config_file, 'w') as fd:
#             yaml_dump(data, stream=fd)
#     except EnvironmentError as exc:
#         raise BinstarError('%s: %s' % (exc.filename, exc.strerror,))
# 
# def load_config(config_file):
#     if exists(config_file):
#         with open(config_file) as fd:
#             data = yaml_load(fd)
#             if data:
#                 return data
# 
#     return {}
# 
# def load_file_configs(search_path):
#     def _file_yaml_loader(fullpath):
#         assert fullpath.endswith(".yml") or fullpath.endswith(".yaml") or fullpath.endswith("anacondarc"), fullpath
#         yield fullpath, load_config(fullpath)
# 
#     def _dir_yaml_loader(fullpath):
#         for filename in os.listdir(fullpath):
#             if filename.endswith(".yml") or filename.endswith(".yaml"):
#                 filepath = join(fullpath, filename)
#                 yield filepath, load_config(filepath)
# 
#     # map a stat result to a file loader or a directory loader
#     _loader = {
#         stat.S_IFREG: _file_yaml_loader,
#         stat.S_IFDIR: _dir_yaml_loader,
#     }
# 
#     def _get_st_mode(path):
#         # stat the path for file type, or None if path doesn't exist
#         try:
#             return stat.S_IFMT(os.stat(path).st_mode)
#         except OSError:
#             return None
# 
#     expanded_paths = [expand(path) for path in search_path]
#     stat_paths = (_get_st_mode(path) for path in expanded_paths)
#     load_paths = (_loader[st_mode](path)
#                   for path, st_mode in zip(expanded_paths, stat_paths)
#                   if st_mode is not None)
#     raw_data = collections.OrderedDict(kv for kv in itertools.chain.from_iterable(load_paths))
# 
#     return raw_data
# 
# Path: binstar_client/utils/yaml.py
# def yaml_load(stream):
# def yaml_dump(data, stream=None):


import logging
from argparse import RawDescriptionHelpFormatter
from six import text_type
from binstar_client.errors import ShowHelp
from binstar_client.utils.config import (SEARCH_PATH, USER_CONFIG, SYSTEM_CONFIG, CONFIGURATION_KEYS,
                                         get_config, save_config, load_config, load_file_configs)
from ..utils.yaml import yaml_dump, safe_load
        logger.warning('"%s" is not a known configuration key', key)

    if key in DEPRECATED.keys():
        message = "{} is deprecated: {}".format(key, DEPRECATED[key])
        logger.warning(message)

    config_data[key] = type_(value)


def recursive_remove(config_data, key):
    while '.' in key:
        if not config_data:
            return
        prefix, key = key.split('.', 1)
        config_data = config_data.get(prefix, {})

    del config_data[key]


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)

# Path: binstar_client/utils/config.py
# SEARCH_PATH = (
#     dirs.site_data_dir,
#     '/etc/anaconda-client/',
#     '$CONDA_ROOT/etc/anaconda-client/',
#     dirs.user_data_dir,
#     '~/.continuum/anaconda-client/',
#     '$CONDA_PREFIX/etc/anaconda-client/',
# )
# 
# USER_CONFIG = join(dirs.user_data_dir, 'config.yaml')
# 
# SYSTEM_CONFIG = SITE_CONFIG
# 
# CONFIGURATION_KEYS = [
#     'auto_register',
#     'default_site',
#     'upload_user',
#     'sites',
#     'url',
#     'verify_ssl',
#     'ssl_verify',
# ]
# 
# def get_config(site=None):
#     config = DEFAULT_CONFIG.copy()
# 
#     file_configs = load_file_configs(SEARCH_PATH)
#     for fn in file_configs:
#         recursive_update(config, file_configs[fn])
# 
#     site = site or config.get('default_site')
#     sites = config.get('sites', {})
# 
#     if site:
#         site = str(site)
# 
#         if site not in sites:
#             logger.warning('Site alias "%s" does not exist in the config file', site)
#         else:
#             # This takes whatever keys are set for the site into the top level of the config dict
#             recursive_update(config, sites.get(site, {}))
# 
#     return config
# 
# def save_config(data, config_file):
#     data_dir = dirname(config_file)
# 
#     try:
#         if not exists(data_dir):
#             os.makedirs(data_dir)
# 
#         with open(config_file, 'w') as fd:
#             yaml_dump(data, stream=fd)
#     except EnvironmentError as exc:
#         raise BinstarError('%s: %s' % (exc.filename, exc.strerror,))
# 
# def load_config(config_file):
#     if exists(config_file):
#         with open(config_file) as fd:
#             data = yaml_load(fd)
#             if data:
#                 return data
# 
#     return {}
# 
# def load_file_configs(search_path):
#     def _file_yaml_loader(fullpath):
#         assert fullpath.endswith(".yml") or fullpath.endswith(".yaml") or fullpath.endswith("anacondarc"), fullpath
#         yield fullpath, load_config(fullpath)
# 
#     def _dir_yaml_loader(fullpath):
#         for filename in os.listdir(fullpath):
#             if filename.endswith(".yml") or filename.endswith(".yaml"):
#                 filepath = join(fullpath, filename)
#                 yield filepath, load_config(filepath)
# 
#     # map a stat result to a file loader or a directory loader
#     _loader = {
#         stat.S_IFREG: _file_yaml_loader,
#         stat.S_IFDIR: _dir_yaml_loader,
#     }
# 
#     def _get_st_mode(path):
#         # stat the path for file type, or None if path doesn't exist
#         try:
#             return stat.S_IFMT(os.stat(path).st_mode)
#         except OSError:
#             return None
# 
#     expanded_paths = [expand(path) for path in search_path]
#     stat_paths = (_get_st_mode(path) for path in expanded_paths)
#     load_paths = (_loader[st_mode](path)
#                   for path, st_mode in zip(expanded_paths, stat_paths)
#                   if st_mode is not None)
#     raw_data = collections.OrderedDict(kv for kv in itertools.chain.from_iterable(load_paths))
# 
#     return raw_data
# 
# Path: binstar_client/utils/yaml.py
# def yaml_load(stream):
# def yaml_dump(data, stream=None):


# Path: binstar_client/commands/config.py
import logging
from argparse import RawDescriptionHelpFormatter
from six import text_type
from binstar_client.errors import ShowHelp
from binstar_client.utils.config import (SEARCH_PATH, USER_CONFIG, SYSTEM_CONFIG, CONFIGURATION_KEYS,
                                         get_config, save_config, load_config, load_file_configs)
from ..utils.yaml import yaml_dump, safe_load

        logger.warning('"%s" is not a known configuration key', key)

    if key in DEPRECATED.keys():
        message = "{} is deprecated: {}".format(key, DEPRECATED[key])
        logger.warning(message)

    config_data[key] = type_(value)


def recursive_remove(config_data, key):
    while '.' in key:
        if not config_data:
            return
        prefix, key = key.split('.', 1)
        config_data = config_data.get(prefix, {})

    del config_data[key]


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]))