<commit_before>import django
import os
import yaml
from backend.settings import BASE_DIR
from django.db import IntegrityError

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')
django.setup()

from breach.models import Target


def create_target(target):
    method = ''
    for m in Target.METHOD_CHOICES:
        if target['method'] == m[1]:
            method = m[0]
            break
    if method:
        target['method'] = method
    else:
        print '[!] Invalid method for target "{}".'.format(target['name'])
        return

    target_args = {
        'name': target['name'],
        'endpoint': target['endpoint'],
        'prefix': target['prefix'],
        'alphabet': target['alphabet'],
        'secretlength': target['secretlength'],
        'alignmentalphabet': target['alignmentalphabet'],
        'recordscardinality': target['recordscardinality'],
        'method': target['method']
    }

    t = Target(**target_args)
    t.save()
    print '''Created Target:
             \tname: {}
             \tendpoint: {}
             \tprefix: {}
             \talphabet: {}
             \tsecretlength: {}
             \talignmentalphabet: {}
             \trecordscardinality: {}
             \tmethod: {}'''.format(
                t.name,
                t.endpoint,
                t.prefix,
                t.alphabet,
                t.secretlength,
                t.alignmentalphabet,
                t.recordscardinality,
                t.method
            )

if __name__ == '__main__':
    try:
        with open(os.path.join(BASE_DIR, 'target_config.yml'), 'r') as ymlconf:
            cfg = yaml.load(ymlconf)
    except IOError, err:<commit_msg>Set maxreflectionlength on target population if given<commit_after>import django
import os
import yaml
from backend.settings import BASE_DIR
from django.db import IntegrityError

os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')
django.setup()

from breach.models import Target


def create_target(target):
    method = ''
    for m in Target.METHOD_CHOICES:
        if target['method'] == m[1]:
            method = m[0]
            break
    if method:
        target['method'] = method
    else:
        print '[!] Invalid method for target "{}".'.format(target['name'])
        return

    target_args = {
        'name': target['name'],
        'endpoint': target['endpoint'],
        'prefix': target['prefix'],
        'alphabet': target['alphabet'],
        'secretlength': target['secretlength'],
        'alignmentalphabet': target['alignmentalphabet'],
        'recordscardinality': target['recordscardinality'],
        'method': target['method']
    }

    if 'maxreflectionlength' in target:
        target_args['maxreflectionlength'] = target['maxreflectionlength']

    t = Target(**target_args)
    t.save()
    print '''Created Target:
             \tname: {}
             \tendpoint: {}
             \tprefix: {}
             \talphabet: {}
             \tsecretlength: {}
             \talignmentalphabet: {}
             \trecordscardinality: {}
             \tmethod: {}'''.format(
                t.name,
                t.endpoint,
                t.prefix,
                t.alphabet,
                t.secretlength,
                t.alignmentalphabet,
                t.recordscardinality,
                t.method
            )

if __name__ == '__main__':
    try:
        with open(os.path.join(BASE_DIR, 'target_config.yml'), 'r') as ymlconf:
            cfg = yaml.load(ymlconf)
    except IOError, err:
{'fraction_non_alphanumeric': 0.1273957158962796, 'fraction_numerical': 0.0011273957158962795, 'mean_word_length': 1.95503746877602, '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': '4410657', 'n_tokens_mistral': 1032, 'n_tokens_neox': 988, 'n_words': 213}