<commit_before>from logging import handlers, DEBUG
import logging
import os
import sys
import cherrypy
from dependency_injection import wire_dependencies


def run_server(primordial_logger=None, enable_file_logging=False):
    """
    Run the server which proxies requests from:
        python/<package>
    to:
        https://pypi.python.org/simple/<package>

    And requests from:
        python/<package>/<filename>
    to:
        https://pypi.python.org/<path-to-filename>
    """
    if primordial_logger is None:
        primordial_logger = _create_console_logger()

    root = wire_dependencies()

    cherrypy_config_path = _config_path('pypi_redirect.conf')

    primordial_logger.info(
        'CherryPy config path: {}'.format(cherrypy_config_path))

    app = cherrypy.tree.mount(
        root,
        script_name='/',
        config=cherrypy_config_path)

    cherrypy.config.update(cherrypy_config_path)

    if enable_file_logging:
        _enable_file_logging(app, primordial_logger=primordial_logger)

    cherrypy.engine.start()
    cherrypy.engine.block()
<commit_msg>If an existing CherryPy config file does not exist, but a template does, one is created from the template.<commit_after>from logging import handlers, DEBUG
import logging
import os
import shutil
import sys
import cherrypy
from dependency_injection import wire_dependencies


def run_server(primordial_logger=None, enable_file_logging=False):
    """
    Run the server which proxies requests from:
        python/<package>
    to:
        https://pypi.python.org/simple/<package>

    And requests from:
        python/<package>/<filename>
    to:
        https://pypi.python.org/<path-to-filename>
    """
    if primordial_logger is None:
        primordial_logger = _create_console_logger()

    root = wire_dependencies()

    cherrypy_config_path = _get_cherrypy_config_file(primordial_logger)

    app = cherrypy.tree.mount(
        root,
        script_name='/',
        config=cherrypy_config_path)

    cherrypy.config.update(cherrypy_config_path)

    if enable_file_logging:
        _enable_file_logging(app, primordial_logger=primordial_logger)

    cherrypy.engine.start()
    cherrypy.engine.block()


def _get_cherrypy_config_file(primordial_logger):
    cherrypy_config_path = _config_path('pypi_redirect.conf')

    if not os.path.exists(cherrypy_config_path):
        template_path = _config_path('pypi_redirect.conf.template')

        assert os.path.exists(template_path), \
            'Neither the CherryPy config file ("{}") nor a suitable ' \
            'template ("{}") were found.'.format(
                cherrypy_config_path,
                template_path)

        shutil.copyfile(template_path, cherrypy_config_path)

        primordial_logger.info(
            'Created CherryPy config file "{}" from template "{}"'.format(
                cherrypy_config_path,
                template_path))

    primordial_logger.info(
        'Using CherryPy config file "{}"'.format(cherrypy_config_path))

    return cherrypy_config_path

{'fraction_non_alphanumeric': 0.08947885939036382, 'fraction_numerical': 0.0, 'mean_word_length': 3.1980742778541953, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 13, 'https://': 4, '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': '2007192', 'n_tokens_mistral': 970, 'n_tokens_neox': 890, 'n_words': 185}