<commit_before>from flask import current_app as app
from .ext import db
from os import path
from .models import Challenge
from core import hash_fleg
import json


def build_challenges():
    chal_path = path.join(app.root_path, "../",
                          app.config['CTF']['challenges'])
    categories = app.config['CTF']['categories']
    for c in categories:
        problem_config = path.join(chal_path, c, "problems.json")
        with open(problem_config, 'r') as config_file:
            try:
                config = json.load(config_file)
            except ValueError:
                print "here"
                raise ValueError("%s was malformed" % config_file)
            for problem in config["problems"]:
                # We put this first to avoid circular dependancies
                prereqs = set()
                if len(problem["prerequisites"]) > 0:
                    prereqs = Challenge.query.filter(
                        Challenge.title.in_(problem["prerequisites"])).all()
                    if len(prereqs) != len(problem["prerequisites"]):
                        print "Prereq mismatch on %s, probably due to a typo\
                               in prereq name or ordering" % problem["title"]
                        continue
                challenge = Challenge(title=problem["title"],
                                      description=problem["description"],
                                      category=c,
                                      points=problem["points"],
                                      fleg_hash=hash_fleg(problem["fleg"]),
                                      prerequisites=set(prereqs))
                db.session.add(challenge)
                try:
                    db.session.commit()
                except:
                    print "Something went wrong with challenge %s, skipping" \
                     % problem["title"]
                    db.session.rollback()<commit_msg>Removed debug statement<commit_after>from flask import current_app as app
from .ext import db
from os import path
from .models import Challenge
from core import hash_fleg
import json


def build_challenges():
    chal_path = path.join(app.root_path, "../",
                          app.config['CTF']['challenges'])
    categories = app.config['CTF']['categories']
    for c in categories:
        problem_config = path.join(chal_path, c, "problems.json")
        with open(problem_config, 'r') as config_file:
            try:
                config = json.load(config_file)
            except ValueError:
                raise ValueError("%s was malformed" % config_file)
            for problem in config["problems"]:
                # We put this first to avoid circular dependancies
                prereqs = set()
                if len(problem["prerequisites"]) > 0:
                    prereqs = Challenge.query.filter(
                        Challenge.title.in_(problem["prerequisites"])).all()
                    if len(prereqs) != len(problem["prerequisites"]):
                        print "Prereq mismatch on %s, probably due to a typo\
                               in prereq name or ordering" % problem["title"]
                        continue
                challenge = Challenge(title=problem["title"],
                                      description=problem["description"],
                                      category=c,
                                      points=problem["points"],
                                      fleg_hash=hash_fleg(problem["fleg"]),
                                      prerequisites=set(prereqs))
                db.session.add(challenge)
                try:
                    db.session.commit()
                except:
                    print "Something went wrong with challenge %s, skipping" \
                     % problem["title"]
                    db.session.rollback()
{'fraction_non_alphanumeric': 0.09218950064020487, 'fraction_numerical': 0.0005121638924455825, 'mean_word_length': 1.3977900552486189, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2070808', 'n_tokens_mistral': 981, 'n_tokens_neox': 881, 'n_words': 233}