<commit_before>#!/usr/bin/env python
from __future__ import print_function

from argparse import ArgumentParser
import os
import sys
from textwrap import dedent

import yaml

from jujuconfig import get_environments
from jujupy import (
    JujuData,
    )
from tests.test_jujupy import fake_juju_client


def write_new_config(env, out):
    client = fake_juju_client(env=env)
    out.write('# cloud/region: {}\n'.format(client.get_cloud_region(
        client.env.get_cloud(), client.env.get_region())))
    config = client.make_model_config()
    if 'agent-version' in env.config:
        config['agent-version'] = env.config['agent-version']
    else:
        config.pop('agent-version', None)
    yaml.dump(config, out, default_flow_style=False)


def main():
    parser = ArgumentParser(
        description=dedent('''\
            Convert environment.yaml to 2.0 format.

            environments.yaml from JUJU_HOME will be used.
            Existing configs in the output directory will be overwritten.
            '''))
    parser.add_argument('config_dir', metavar='OUTPUT_DIR',
                        help='Directory to write updated configs to.')
    args = parser.parse_args()
    clouds_credentials = JujuData('', {})
    clouds_credentials.load_yaml()
    for environment, config in get_environments().items():
        if config['type'] == 'local':
            continue
        env = JujuData(environment, config)
        env.clouds = clouds_credentials.clouds
        env.credentials = clouds_credentials.credentials
        print(environment)
        sys.stdout.flush()
        out_path = os.path.join(args.config_dir,
                                '{}.yaml'.format(environment))
        with open(out_path, 'w') as out_file:
            write_new_config(env, out_file)


if __name__ == '__main__':
    main()<commit_msg>Cleanups<commit_after>#!/usr/bin/env python
from __future__ import print_function

from argparse import ArgumentParser
import os
import sys
from textwrap import dedent

import yaml

from jujuconfig import get_environments
from jujupy import (
    JujuData,
    )
from tests.test_jujupy import fake_juju_client


def write_new_config(env, out):
    client = fake_juju_client(env=env)
    out.write('# cloud/region: {}\n'.format(client.get_cloud_region(
        client.env.get_cloud(), client.env.get_region())))
    config = client.make_model_config()
    if 'agent-version' in env.config:
        config['agent-version'] = env.config['agent-version']
    else:
        config.pop('agent-version', None)
    yaml.dump(config, out, default_flow_style=False)


def main():
    parser = ArgumentParser(
        description=dedent('''\
            Convert environments.yaml to 2.0 format.

            environments.yaml from JUJU_HOME will be used.
            Existing configs in the output directory will be overwritten.

            Does not support configs of type 'local'.
            '''))
    parser.add_argument('config_dir', metavar='OUTPUT_DIR',
                        help='Directory to write updated configs to.')
    args = parser.parse_args()
    clouds_credentials = JujuData('', {})
    clouds_credentials.load_yaml()
    for environment, config in get_environments().items():
        if config['type'] == 'local':
            continue
        env = JujuData(environment, config)
        env.clouds = clouds_credentials.clouds
        env.credentials = clouds_credentials.credentials
        print(environment)
        sys.stdout.flush()
        out_path = os.path.join(args.config_dir,
                                '{}.yaml'.format(environment))
        with open(out_path, 'w') as out_file:
            write_new_config(env, out_file)


if __name__ == '__main__':
    main()
{'fraction_non_alphanumeric': 0.10533369069954436, 'fraction_numerical': 0.0010720986330742428, 'mean_word_length': 2.8004073319755602, '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': '5170373', 'n_tokens_mistral': 1115, 'n_tokens_neox': 1091, 'n_words': 258}