# Path: datafs/_compat.py
# @contextmanager
# def open_filelike(filelike, mode='r'):
# 
#     if hasattr(filelike, 'read'):
#         yield filelike
# 
#     else:
#         with open(filelike, mode) as f:
#             yield f


from datafs._compat import open_filelike
import yaml
import os
import click
    def parse_configfile_contents(self, config):
        if 'profiles' not in config:
            config = {'profiles': {'default': config}}

        self.default_profile = config.get(
            'default-profile', self.config['default-profile'])

        self.config['default-profile'] = self.default_profile

        self.config['requirements'] = config.get(
            'requirements', self.config['requirements'])

        self.config['profiles'].update(config['profiles'])

    def read_config(self):

        with open_filelike(self.config_file, 'r') as f:
            config = yaml.load(f)

        self.parse_configfile_contents(config)

    def edit_config_file(self):

        click.edit(filename=self.config_file)

    def write_config(self, fp=None):

        if fp is None:
            fp = os.path.join(click.get_app_dir('datafs'), 'config.yml')


# Path: datafs/_compat.py
# @contextmanager
# def open_filelike(filelike, mode='r'):
# 
#     if hasattr(filelike, 'read'):
#         yield filelike
# 
#     else:
#         with open(filelike, mode) as f:
#             yield f


# Path: datafs/config/config_file.py
from datafs._compat import open_filelike
import yaml
import os
import click

    def parse_configfile_contents(self, config):
        if 'profiles' not in config:
            config = {'profiles': {'default': config}}

        self.default_profile = config.get(
            'default-profile', self.config['default-profile'])

        self.config['default-profile'] = self.default_profile

        self.config['requirements'] = config.get(
            'requirements', self.config['requirements'])

        self.config['profiles'].update(config['profiles'])

    def read_config(self):

        with open_filelike(self.config_file, 'r') as f:
            config = yaml.load(f)

        self.parse_configfile_contents(config)

    def edit_config_file(self):

        click.edit(filename=self.config_file)

    def write_config(self, fp=None):

        if fp is None:
            fp = os.path.join(click.get_app_dir('datafs'), 'config.yml')


        with open_filelike(fp, 'w+') as f: