<commit_before>from __future__ import with_statement
import os
import re
import sys
import shutil
from idiokit import jid

def dummy(_repr):
    class _dummy(object):
        def __repr__(self):
            return _repr
    return _dummy()

NOT_GIVEN = dummy("<not given>")

def input(name, default=NOT_GIVEN, parser=NOT_GIVEN):
    prompt = name
    if default is not NOT_GIVEN:
        prompt += " [" + repr(default) + "]"
    prompt += ": "

    while True:
        result = raw_input(prompt).strip()
        if not result:
            if default is NOT_GIVEN:
                continue
            return default

        if parser is NOT_GIVEN:
            return result

        try:
            return parser(result)
        except Exception, error:
            print >> sys.stderr, "Invalid value for " + name + ":", error

def replace(string, values):
    replace_rex = "(?P<open>[\"\'])@(.*?)@(?P=open)"
    def _sub(match):
        return repr(values[match.group(2).strip()])
    return re.sub(replace_rex, _sub, string)

def parse_jid(string):
    value = jid.JID(string)
    if value.node is None:
        raise jid.JIDError("JID has to be of form node@domain")

    value = unicode(value)
    try:
        return str(value)
    except UnicodeDecodeError:
        return value

dirname = os.path.dirname(__file__)

if len(sys.argv) != 2:
    print >> sys.stderr, "USAGE:", sys.argv[0], "CONFIGDIR"
    sys.exit(1)

src = os.path.join(dirname, "config-template")
dst = sys.argv[1]

try:
    shutil.copytree(src, dst)
    try:
        replaces = dict(XMPP_JID=input("XMPP JID", parser=parse_jid),
                        XMPP_PASSWORD=input("XMPP password"),
                        SERVICE_ROOM=input("Lobby"),<commit_msg>confgen fix: don't copy .svn dirs<commit_after>from __future__ import with_statement
import os
import re
import sys
import shutil
from idiokit import jid

def dummy(_repr):
    class _dummy(object):
        def __repr__(self):
            return _repr
    return _dummy()

NOT_GIVEN = dummy("<not given>")
IGNORE_FILES = (".svn")

def input(name, default=NOT_GIVEN, parser=NOT_GIVEN):
    prompt = name
    if default is not NOT_GIVEN:
        prompt += " [" + repr(default) + "]"
    prompt += ": "

    while True:
        result = raw_input(prompt).strip()
        if not result:
            if default is NOT_GIVEN:
                continue
            return default

        if parser is NOT_GIVEN:
            return result

        try:
            return parser(result)
        except Exception, error:
            print >> sys.stderr, "Invalid value for " + name + ":", error

def replace(string, values):
    replace_rex = "(?P<open>[\"\'])@(.*?)@(?P=open)"
    def _sub(match):
        return repr(values[match.group(2).strip()])
    return re.sub(replace_rex, _sub, string)

def parse_jid(string):
    value = jid.JID(string)
    if value.node is None:
        raise jid.JIDError("JID has to be of form node@domain")

    value = unicode(value)
    try:
        return str(value)
    except UnicodeDecodeError:
        return value

dirname = os.path.dirname(__file__)

if len(sys.argv) != 2:
    print >> sys.stderr, "USAGE:", sys.argv[0], "CONFIGDIR"
    sys.exit(1)

src = os.path.join(dirname, "config-template")
dst = sys.argv[1]

try:
    shutil.copytree(src, dst, ignore=shutil.ignore_patterns(IGNORE_FILES))
    try:
        replaces = dict(XMPP_JID=input("XMPP JID", parser=parse_jid),
                        XMPP_PASSWORD=input("<PASSWORD>"),
                        SERVICE_ROOM=input("Lobby"),
{'fraction_non_alphanumeric': 0.12387387387387387, 'fraction_numerical': 0.002815315315315315, 'mean_word_length': 2.4765166340508804, 'pattern_counts': {'":': 4, '<': 8, '<?xml version=': 0, '>': 16, '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': '1973599', 'n_tokens_mistral': 1186, 'n_tokens_neox': 1150, 'n_words': 288}