<commit_before>import ConfigParser
import contextlib

from . import exc


class _TrimIndentFile(object):
    def __init__(self, fp):
        self.fp = fp

    def readline(self):
        line = self.fp.readline()
        return line.lstrip(' \t')


def _optionxform(s):
    s = s.replace('_', ' ')
    s = '_'.join(s.split())
    return s


def parse(fp):
    cfg = ConfigParser.RawConfigParser()
    cfg.optionxform = _optionxform
    ifp = _TrimIndentFile(fp)
    cfg.readfp(ifp)
    return cfg


def load(args):
    path = '{cluster}.conf'.format(cluster=args.cluster)
    try:
        f = file(path)
    except IOError as e:
        raise exc.ConfigError(e)
    else:
        with contextlib.closing(f):
            return parse(f)


def write_conf(cluster, conf, overwrite):
    import os<commit_msg>add a docstring for logging in write_conf<commit_after>import ConfigParser
import contextlib

from . import exc


class _TrimIndentFile(object):
    def __init__(self, fp):
        self.fp = fp

    def readline(self):
        line = self.fp.readline()
        return line.lstrip(' \t')


def _optionxform(s):
    s = s.replace('_', ' ')
    s = '_'.join(s.split())
    return s


def parse(fp):
    cfg = ConfigParser.RawConfigParser()
    cfg.optionxform = _optionxform
    ifp = _TrimIndentFile(fp)
    cfg.readfp(ifp)
    return cfg


def load(args):
    path = '{cluster}.conf'.format(cluster=args.cluster)
    try:
        f = file(path)
    except IOError as e:
        raise exc.ConfigError(e)
    else:
        with contextlib.closing(f):
            return parse(f)


def write_conf(cluster, conf, overwrite):
    """ write cluster configuration to /etc/ceph/{cluster}.conf """
    import os
{'fraction_non_alphanumeric': 0.12075029308323564, 'fraction_numerical': 0.0, 'mean_word_length': 2.6319148936170214, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1957257', 'n_tokens_mistral': 579, 'n_tokens_neox': 558, 'n_words': 138}