<commit_before>#! /usr/bin/env python
from __future__ import absolute_import
import os
from string import Template
from collections import OrderedDict

from wmt.site import Site


def setup(prefix, options={}):
    site = Site(prefix, options=options)
    site.create()


def main():
    import argparse
    parser = argparse.ArgumentParser('Setup wmt at a site.')
    parser.add_argument('prefix', help='path to the wmt project')
    parser.add_argument('--name', default='<your-name>',
                        help='name of contact')
    parser.add_argument('--email', default='<your-email>',
                        help='name of contact')
    parser.add_argument('--host', default='localhost',
                        help='name of the host running wmt')

    args = parser.parse_args()

    setup(args.prefix, OrderedDict([('name', args.name),
                                    ('email', args.email),
                                    ('host', args.host)]))

    epilog = Template(
"""
A CMT project has been created for you under:

    ${prefix}

To finish the installation you'll have to do the following:

1. If you're using Apache, add the following lines to httpd.conf:

    WSGIScriptAlias /wmt/ ${prefix}/bin/wmt_wsgi_main.py/

    Alias /wmt/static ${prefix}/static
    AddType text/html .py
    <Directory ${prefix}/>
      Order deny,allow
      148   Allow from all
    </Directory>

2. Be sure the permissions and ownership are correct for the database files.

    > chown -R nobody:nobody ${prefix}/db

3. Restart Apache:<commit_msg>Changed to read config vars from file and then command line.<commit_after>#! /usr/bin/env python
from __future__ import absolute_import
import os
from string import Template
from collections import OrderedDict

from wmt.site import Site


def setup(prefix, options={}):
    site = Site(prefix, options=options)
    site.create()


def collect_user_vars(arg_values):
    values = []
    for value in arg_values:
        values.extend(value.split(','))
    return [value.split('=') for value in values]


def read_site_vars(filename):
    from ConfigParser import ConfigParser, NoSectionError

    parser = ConfigParser()
    parser.read([filename])

    try:
        return dict(parser.items('wmt'))
    except NoSectionError:
        return dict()


def main():
    import argparse

    parser = argparse.ArgumentParser('Setup wmt at a site.')
    parser.add_argument('prefix', help='path to the wmt project')
    parser.add_argument('--name', default='<your-name>',
                        help='name of contact')
    parser.add_argument('--email', default='<your-email>',
                        help='name of contact')
    parser.add_argument('--host', default='localhost',
                        help='name of the host running wmt')
    parser.add_argument('--conf', action='append', default=[],
                        help='give a custom configuration value')
    parser.add_argument('--file', default='site.cfg',
                        help='read options from a files')

    args = parser.parse_args()

    user_vars = read_site_vars(args.file)
    user_vars.update(collect_user_vars(args.conf))
    user_vars.update([('name', args.name),
                      ('email', args.email),
                      ('host', args.host)])

    setup(args.prefix, user_vars)

    epilog = Template(
"""
A CMT project has been created for you under:

    ${prefix}

To finish the installation you'll have to do the following:

1. If you're using Apache, add the following lines to httpd.conf:

    WSGIScriptAlias /wmt/ ${prefix}/bin/wmt_wsgi_main.py/

    Alias /wmt/static ${prefix}/static
    AddType text/html .py
    <Directory ${prefix}/>
      Order deny,allow
      148   Allow from all
    </Directory>

2. Be sure the permissions and ownership are correct for the database files.

    > chown -R nobody:nobody ${prefix}/db

3. Restart Apache:
{'fraction_non_alphanumeric': 0.11632077888803484, 'fraction_numerical': 0.0030745580322828594, 'mean_word_length': 2.6830188679245284, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1050925', 'n_tokens_mistral': 1133, 'n_tokens_neox': 1085, 'n_words': 343}