Generate a valid Apache configuration file, based on the given settings.

def apache_config(config, outputfile):
    '''
        Generate a valid Apache configuration file, based on the given settings.
    '''
    if os.path.exists(outputfile):
        os.rename(outputfile, outputfile + ".old")
        print("Renamed existing Apache config file to " + outputfile + ".old")

    from django.conf import settings
    f = open(outputfile, 'w')
    print("Generating Apache configuration in " + outputfile)
    subdir = (len(settings.HOST_DIR) > 0)
    text = """
    # OpenSubmit Configuration for Apache 2.4
    # These directives are expected to live in some <VirtualHost> block
    """
    if subdir:
        text += "Alias /%s/static/ %s\n" % (settings.HOST_DIR,
                                            settings.STATIC_ROOT)
        text += "    WSGIScriptAlias /%s %s/wsgi.py\n" % (
            settings.HOST_DIR, settings.SCRIPT_ROOT)
    else:
        text += "Alias /static/ %s\n" % (settings.STATIC_ROOT)
        text += "    WSGIScriptAlias / %s/wsgi.py" % (settings.SCRIPT_ROOT)
    text += """
    WSGIPassAuthorization On
    <Directory {static_path}>
         Require all granted
    </Directory>
    <Directory {install_path}>
         <Files wsgi.py>
              Require all granted
         </Files>
    </Directory>
    """.format(static_path=settings.STATIC_ROOT, install_path=settings.SCRIPT_ROOT)

    f.write(text)
    f.close()