<commit_before>import os
from django.template.loader import render_to_string
from django.conf import settings


class ConfigManager(object):
    def __init__(self):
        self.supervisor_dir = settings.SUPERVISOR_CONFIGS_PATH
        self.nginx_dir = settings.NGINX_CONFIGS_PATH
        self.deploy_environment = settings.DEPLOY_ENVIRONMENT

        if not os.path.exists(self.supervisor_dir):
            os.makedirs(self.supervisor_dir)

        if not os.path.exists(self.nginx_dir):
            os.makedirs(self.nginx_dir)

    def write_frontend_supervisor(self, app_type, country):
        frontend_supervisor_content = render_to_string(
            'configs/frontend.supervisor.conf', {
                'app_type': app_type,
                'country': country.lower(),
            }
        )

        filepath = os.path.join(
            self.supervisor_dir,
            'frontend_%(app_type)s_%(country)s.conf' % {
                'app_type': app_type,
                'country': country.lower(),
            }
        )

        with open(filepath, 'w') as config_file:
            config_file.write(frontend_supervisor_content)

    def write_cms_supervisor(self, app_type, country):
        cms_supervisor_content = render_to_string(
            'configs/cms.supervisor.conf', {
                'app_type': app_type,
                'country': country.lower(),
            }
        )

        filepath = os.path.join(
            self.supervisor_dir,
            'cms_%(app_type)s_%(country)s.conf' % {
                'app_type': app_type,
                'country': country.lower(),
            }
        )

        with open(filepath, 'w') as config_file:
            config_file.write(cms_supervisor_content)

    def write_frontend_nginx(self, app_type, country):
        frontend_nginx_content = render_to_string(
            'configs/frontend.nginx.conf', {
                'deploy_environment': settings.DEPLOY_ENVIRONMENT,
                'app_type': app_type,
                'country': country.lower(),
            }
        )

        filepath = os.path.join(
            self.nginx_dir,
            'frontend_%(app_type)s_%(country)s.conf' % {
                'app_type': app_type,
                'country': country.lower(),
            }
        )

        with open(filepath, 'w') as config_file:
            config_file.write(frontend_nginx_content)

    def write_cms_nginx(self, app_type, country):
        cms_nginx_content = render_to_string(
            'configs/cms.nginx.conf', {
                'deploy_environment': self.deploy_environment,
                'app_type': app_type,
                'country': country.lower(),
            }
        )

        filepath = os.path.join(
            self.nginx_dir,
            'cms_%(app_type)s_%(country)s.conf' % {
                'app_type': app_type,
                'country': country.lower(),
            }
        )

        with open(filepath, 'w') as config_file:
            config_file.write(cms_nginx_content)


class SettingsManager(object):
    def __init__(self):
        self.settings_dir = settings.SETTINGS_OUTPUT_PATH
        self.deploy_environment = settings.DEPLOY_ENVIRONMENT

        if not os.path.exists(settings.SETTINGS_OUTPUT_PATH):
            os.makedirs(self.settings_dir)

    def write_frontend_settings(
            self, app_type, country, clone_url, available_languages):
        if self.deploy_environment == 'qa':
            raven_dsn = (
                'http://3403146e923c400e9dbdc25f0ca2bf89:'
                '4a9a59b5a75142028f81381e97fb173e@'
                'prd-sentry.za.prk-host.net/70')
        else:
            raven_dsn = (
                'http://ae24b1ca62c14e3187409be94bde6828:'
                'abf0b78210874deba6e58ccac08188b0@'
                'prd-sentry.za.prk-host.net/71')

        languages = []
        for l in available_languages:
            languages.append("('%s', '%s')" % (l.get_code(), str(l)))

        frontend_settings_content = render_to_string(
            'configs/pyramid.ini', {
                'app_type': app_type,
                'country': country.lower(),
                'available_languages': '[%s]' % ', '.join(languages),
                'git_repo_uri': clone_url,
                'raven_dsn_uri': raven_dsn<commit_msg>more readable<commit_after>import os
from django.template.loader import render_to_string
from django.conf import settings


class ConfigManager(object):
    def __init__(self):
        self.supervisor_dir = settings.SUPERVISOR_CONFIGS_PATH
        self.nginx_dir = settings.NGINX_CONFIGS_PATH
        self.deploy_environment = settings.DEPLOY_ENVIRONMENT

        if not os.path.exists(self.supervisor_dir):
            os.makedirs(self.supervisor_dir)

        if not os.path.exists(self.nginx_dir):
            os.makedirs(self.nginx_dir)

    def write_frontend_supervisor(self, app_type, country):
        frontend_supervisor_content = render_to_string(
            'configs/frontend.supervisor.conf', {
                'app_type': app_type,
                'country': country.lower(),
            }
        )

        filepath = os.path.join(
            self.supervisor_dir,
            'frontend_%(app_type)s_%(country)s.conf' % {
                'app_type': app_type,
                'country': country.lower(),
            }
        )

        with open(filepath, 'w') as config_file:
            config_file.write(frontend_supervisor_content)

    def write_cms_supervisor(self, app_type, country):
        cms_supervisor_content = render_to_string(
            'configs/cms.supervisor.conf', {
                'app_type': app_type,
                'country': country.lower(),
            }
        )

        filepath = os.path.join(
            self.supervisor_dir,
            'cms_%(app_type)s_%(country)s.conf' % {
                'app_type': app_type,
                'country': country.lower(),
            }
        )

        with open(filepath, 'w') as config_file:
            config_file.write(cms_supervisor_content)

    def write_frontend_nginx(self, app_type, country):
        frontend_nginx_content = render_to_string(
            'configs/frontend.nginx.conf', {
                'deploy_environment': settings.DEPLOY_ENVIRONMENT,
                'app_type': app_type,
                'country': country.lower(),
            }
        )

        filepath = os.path.join(
            self.nginx_dir,
            'frontend_%(app_type)s_%(country)s.conf' % {
                'app_type': app_type,
                'country': country.lower(),
            }
        )

        with open(filepath, 'w') as config_file:
            config_file.write(frontend_nginx_content)

    def write_cms_nginx(self, app_type, country):
        cms_nginx_content = render_to_string(
            'configs/cms.nginx.conf', {
                'deploy_environment': self.deploy_environment,
                'app_type': app_type,
                'country': country.lower(),
            }
        )

        filepath = os.path.join(
            self.nginx_dir,
            'cms_%(app_type)s_%(country)s.conf' % {
                'app_type': app_type,
                'country': country.lower(),
            }
        )

        with open(filepath, 'w') as config_file:
            config_file.write(cms_nginx_content)


class SettingsManager(object):
    def __init__(self):
        self.settings_dir = settings.SETTINGS_OUTPUT_PATH
        self.deploy_environment = settings.DEPLOY_ENVIRONMENT

        if not os.path.exists(settings.SETTINGS_OUTPUT_PATH):
            os.makedirs(self.settings_dir)

    def write_frontend_settings(
            self, app_type, country, clone_url, available_languages):
        if self.deploy_environment == 'qa':
            raven_dsn = (
                'http://3403146e923c400e9dbdc25f0ca2bf89:'
                '4a9a59b5a75142028f81381e97fb173e@'
                'prd-sentry.za.prk-host.net/70')
        else:
            raven_dsn = (
                'http://ae24b1ca62c14e3187409be94bde6828:'
                'abf0b78210874deba6e58ccac08188b0@'
                'prd-sentry.za.prk-host.net/71')

        languages = []
        for lang in available_languages:
            languages.append("('%s', '%s')" % (lang.get_code(), str(lang)))

        frontend_settings_content = render_to_string(
            'configs/pyramid.ini', {
                'app_type': app_type,
                'country': country.lower(),
                'available_languages': '[%s]' % ', '.join(languages),
                'git_repo_uri': clone_url,
                'raven_dsn_uri': raven_dsn
{'fraction_non_alphanumeric': 0.10693943973032663, 'fraction_numerical': 0.019760548645821226, 'mean_word_length': 1.8795180722891567, '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': '2445553', 'n_tokens_mistral': 2861, 'n_tokens_neox': 2639, 'n_words': 372}