コード例 #1
0
    def test_problem(self):
        """test the problem table"""
        # add problem type
        PROBLEM_TYPE_ARGS = {
            "name": "input/output",
            "eval_script": "#!/bin/bash\nexit 0",
        }
        problem_type = model.ProblemType(**PROBLEM_TYPE_ARGS)
        db_session.add(problem_type)
        db_session.commit()

        PROBLEM_ARGS = {
            "problem_type": problem_type,
            "slug": "ioprob",
            "name": "The Input/Output Problem",
            "problem_statement": "Print the string 'Hello, World!' n times",
            "sample_input": "3",
            "sample_output": "Hello, World!Hello, World!Hello, World!",
            "secret_input": "4",
            "secret_output": "Hello, World!Hello, World!Hello, World!Hello, World!",
        }

        # create and add contest
        problem = model.Problem(**PROBLEM_ARGS)
        db_session.add(problem)
        db_session.commit()

        # fetch contest
        results = model.Problem.query.filter_by(name=PROBLEM_ARGS["name"]).all()

        self.assertEqual(len(results), 1)
コード例 #2
0
def get_problem_type():
    """returns a test ProblemType"""
    PROBLEM_TYPE_ARGS = {"name": "input/output", "eval_script": "#!/bin/bash\nexit 0"}
    problem_type = model.ProblemType(**PROBLEM_TYPE_ARGS)
    db_session.add(problem_type)
    db_session.commit()

    return PROBLEM_TYPE_ARGS, problem_type
コード例 #3
0
ファイル: model_test.py プロジェクト: payne/code_court
    def test_problem_type(self):
        """test the problem_type table"""
        PROBLEM_TYPE_ARGS = {
            "name": "input/output",
            "eval_script": "#!/bin/bash\nexit 0",
        }

        # create and add contest
        problem_type = model.ProblemType(**PROBLEM_TYPE_ARGS)
        db_session.add(problem_type)
        db_session.commit()

        # fetch contest
        results = model.ProblemType.query.filter_by(
            name=PROBLEM_TYPE_ARGS["name"]).all()

        self.assertEqual(len(results), 1)
コード例 #4
0
ファイル: web.py プロジェクト: a-hodges/code_court
def populate_db():
    """Performs the initial database setup for the application
    """
    current_app.logger.info("Initializing db tables")

    db_session.add_all([
        model.UserRole("defendant"),
        model.UserRole("operator"),
        model.UserRole("judge"),
        model.UserRole("executioner"),
        model.UserRole("observer")
    ])

    # TODO: extract these out into a folder
    db_session.add_all([
        model.Language("python", "python", True,
                       textwrap.dedent('''
                                    #!/bin/bash
                                    cat $1 | python3 $2
                                    exit $?''').strip()),
        model.Language("python2", "python", True,
                       textwrap.dedent('''
                                    #!/bin/bash
                                    cat $1 | python2 $2
                                    exit $?''').strip()),
        model.Language("perl", "perl", True,
                       textwrap.dedent('''
                                    #!/bin/bash
                                    cat $1 | perl $2
                                    exit $?''').strip()),
        model.Language("lua", "lua", True,
                       textwrap.dedent('''
                                    #!/bin/bash
                                    cat $1 | lua $2
                                    exit $?''').strip()),
        model.Language("nodejs", "javascript", True,
                       textwrap.dedent('''
                                    #!/bin/bash
                                    cat $1 | node $2
                                    exit $?''').strip()),
        model.Language("guile", "scheme", True,
                       textwrap.dedent('''
                                    #!/bin/bash
                                    cat $1 | guile --no-auto-compile $2
                                    exit $?''').strip()),
        model.Language("fortran", "fortran", True,
                       textwrap.dedent('''
                                #!/bin/bash
                                cp /share/program /scratch/program.f

                                cd /scratch

                                gfortran -o program /scratch/program.f

                                if [[ $? != 0 ]]; then
                                  exit $?
                                fi

                                cat $1 | ./program

                                exit $?''').strip()),
        model.Language("c", "clike", True,
                       textwrap.dedent('''
                                #!/bin/bash
                                cp /share/program /scratch/program.c

                                cd /scratch

                                gcc -o program /scratch/program.c

                                if [[ $? != 0 ]]; then
                                  exit $?
                                fi

                                cat $1 | ./program

                                exit $?''').strip(),
                       textwrap.dedent('''
                                #include <stdio.h>

                                int main(int argc, const char* argv[]) {
                                }''')),
        model.Language("c++", "clike", True,
                       textwrap.dedent('''
                                #!/bin/bash
                                cp /share/program /scratch/program.cpp

                                cd /scratch

                                g++ -o program /scratch/program.cpp

                                if [[ $? != 0 ]]; then
                                  exit $?
                                fi

                                cat $1 | ./program

                                exit $?''').strip(),
                       textwrap.dedent('''
                                #include <iostream>

                                int main() {
                                  std::cout << "Hello World!";
                                }''')),
        model.Language("java", "clike", True,
                       textwrap.dedent('''
                                #!/bin/bash
                                cp /share/program /scratch/Main.java

                                cd /scratch

                                /usr/lib/jvm/java-1.8-openjdk/bin/javac Main.java

                                if [[ $? != 0 ]]; then
                                  exit $?
                                fi

                                cat $1 | /usr/lib/jvm/java-1.8-openjdk/bin/java Main

                                exit $?''').strip(),
                       textwrap.dedent('''
                                public class Main {
                                    public static void main(String[] args) {

                                    }
                                }''')),
        model.Language("ruby", "ruby", True,
                       textwrap.dedent('''
                                        #!/bin/bash
                                        cat $1 | ruby $2
                                        exit $?''').strip()),
        model.Language("rust", "rust", True,
                       textwrap.dedent('''
                                        #!/bin/bash
                                        cp /share/program /scratch/main.rs

                                        cd /scratch

                                        rustc /scratch/main.rs

                                        if [[ $? != 0 ]]; then
                                          exit $?
                                        fi

                                        cat $1 | ./main
                                        exit $?''').strip())
    ])

    db_session.add_all([
        model.Configuration("strict_whitespace_diffing", "False", "bool",
                            "admin"),
        model.Configuration("contestants_see_sample_output", "True",
                            "bool", "defendant"),
        model.Configuration("max_user_submissions", "5", "integer",
                            "defendant"),
        model.Configuration("user_submission_time_limit", "1", "integer",
                            "defendant"),
        model.Configuration("max_output_length",
                            str(10 * 1024), "integer", "defendant")
    ])

    db_session.add_all([
        model.ProblemType("input-output", '#!/bin/bash\ntest "$1" = "$2"')
    ])
    db_session.commit()

    roles = {x.name: x for x in model.UserRole.query.all()}
    db_session.add_all([
        model.User(
            "*****@*****.**",
            "Admin",
            "pass",
            user_roles=[roles['operator']]),
        model.User(
            "*****@*****.**",
            "Executioner",
            "epass",
            user_roles=[roles['executioner']])
    ])

    db_session.commit()
コード例 #5
0
ファイル: web.py プロジェクト: pgayee694/code_court
def populate_db():
    """Performs the initial database setup for the application
    """
    current_app.logger.info("Initializing db tables")

    db_session.add_all([
        model.UserRole("defendant"),
        model.UserRole("operator"),
        model.UserRole("judge"),
        model.UserRole("executioner"),
        model.UserRole("observer"),
    ])

    # TODO: extract these out into a folder
    db_session.add_all([
        model.Language(
            "python",
            "python",
            True,
            textwrap.dedent("""
                                    #!/bin/bash
                                    cat $input_file | python3 $program_file
                                    exit $?""").strip(),
        ),
        model.Language(
            "python2",
            "python",
            True,
            textwrap.dedent("""
                                    #!/bin/bash
                                    cat $input_file | python2 $program_file
                                    exit $?""").strip(),
        ),
        model.Language(
            "perl",
            "perl",
            True,
            textwrap.dedent("""
                                    #!/bin/bash
                                    cat $input_file | perl $program_file
                                    exit $?""").strip(),
        ),
        model.Language(
            "lua",
            "lua",
            True,
            textwrap.dedent("""
                                    #!/bin/bash
                                    cat $input_file | lua $program_file
                                    exit $?""").strip(),
        ),
        model.Language(
            "nodejs",
            "javascript",
            True,
            textwrap.dedent("""
                                    #!/bin/bash
                                    cat $input_file | node $program_file
                                    exit $?""").strip(),
        ),
        model.Language(
            "guile",
            "scheme",
            True,
            textwrap.dedent("""
                                    #!/bin/bash
                                    cat $input_file | guile --no-auto-compile $program_file
                                    exit $?""").strip(),
        ),
        model.Language(
            "fortran",
            "fortran",
            True,
            textwrap.dedent("""
                                #!/bin/bash
                                cp /share/program $scratch_dir/program.f

                                cd $scratch_dir

                                gfortran -o program $scratch_dir/program.f

                                if [[ $? != 0 ]]; then
                                  exit $?
                                fi

                                cat $input_file | ./program

                                exit $?""").strip(),
        ),
        model.Language(
            "c",
            "clike",
            True,
            textwrap.dedent("""
                                #!/bin/bash
                                cp $program_file $scratch_dir/program.c

                                cd $3

                                gcc -o program $scratch_dir/program.c

                                if [[ $? != 0 ]]; then
                                  exit $?
                                fi

                                cat $input_file | ./program

                                exit $?""").strip(),
            textwrap.dedent("""
                                #include <stdio.h>

                                int main(int argc, const char* argv[]) {
                                }"""),
        ),
        model.Language(
            "c++",
            "clike",
            True,
            textwrap.dedent("""
                                #!/bin/bash
                                cp $program_file $scratch_dir/program.cpp

                                cd $scratch_dir

                                g++ -o program $scratch_dir/program.cpp

                                if [[ $? != 0 ]]; then
                                  exit $?
                                fi

                                cat $input_file | ./program

                                exit $?""").strip(),
            textwrap.dedent("""
                                #include <iostream>

                                int main() {
                                  std::cout << "Hello World!";
                                }"""),
        ),
        model.Language(
            "java",
            "clike",
            True,
            textwrap.dedent("""
                                #!/bin/bash
                                export PATH=$PATH:/usr/lib/jvm/java-1.8-openjdk/bin

                                cp $program_file $scratch_dir/Main.java

                                cd $scratch_dir

                                javac Main.java

                                if [[ $? != 0 ]]; then
                                  exit $?
                                fi

                                cat $input_file | java Main

                                exit $?""").strip(),
            textwrap.dedent("""
                                public class Main {
                                    public static void main(String[] args) {

                                    }
                                }"""),
        ),
        model.Language(
            "ruby",
            "ruby",
            True,
            textwrap.dedent("""
                                        #!/bin/bash
                                        cat $input_file | ruby $program_file
                                        exit $?""").strip(),
        ),
        model.Language(
            "rust",
            "rust",
            True,
            textwrap.dedent("""
                                        #!/bin/bash
                                        cp /share/program $scratch_dir/main.rs

                                        cd $scratch_dir

                                        rustc $scratch_dir/main.rs

                                        if [[ $? != 0 ]]; then
                                          exit $?
                                        fi

                                        cat $input_file | ./main
                                        exit $?""").strip(),
            textwrap.dedent("""
                                        fn main() {
                                        }
                        """).strip(),
        ),
    ])

    db_session.add_all([
        model.Configuration("strict_whitespace_diffing", "False", "bool",
                            "admin"),
        model.Configuration("contestants_see_sample_output", "True", "bool",
                            "defendant"),
        model.Configuration("max_user_submissions", "5", "integer",
                            "defendant"),
        model.Configuration("user_submission_time_limit", "1", "integer",
                            "defendant"),
        model.Configuration("max_output_length", str(10 * 1024), "integer",
                            "defendant"),
        model.Configuration("run_refresh_interval_millseconds", 5000,
                            "integer", "defendant"),
        model.Configuration("score_refresh_interval_millseconds", 30000,
                            "integer", "defendant"),
        model.Configuration("misc_refresh_interval_millseconds", 12000,
                            "integer", "defendant"),
        model.Configuration("extra_signup_fields", "[]", "json", "defendant"),
    ])

    db_session.add_all(
        [model.ProblemType("input-output", '#!/bin/bash\ntest "$1" = "$2"')])
    db_session.commit()

    roles = {x.name: x for x in model.UserRole.query.all()}
    db_session.add_all([
        model.User("admin", "Admin", "pass", user_roles=[roles["operator"]]),
        model.User("exec",
                   "Executioner",
                   "epass",
                   user_roles=[roles["executioner"]]),
    ])

    db_session.commit()

    # Version scraper run

    with open("init_data/printver.py", "r") as f:
        src_code = "\n".join(f.readlines())

    executioner_user = model.User.query.filter_by(username="******").scalar()

    python = model.Language.query.filter_by(name="python").scalar()
    empty_input = ""

    version_contest = model.Contest(
        name="version_contest",
        start_time=datetime.datetime.utcnow(),
        end_time=datetime.datetime.utcnow() + datetime.timedelta(hours=1),
        is_public=True,
        activate_time=datetime.datetime.utcnow(),
        freeze_time=None,
        deactivate_time=None,
    )

    db_session.add(version_contest)
    db_session.commit()

    verscrape_run = model.Run(
        executioner_user,
        version_contest,
        python,
        None,
        datetime.datetime.utcnow(),
        src_code,
        empty_input,
        empty_input,
        True,
        None,
    )

    db_session.add(verscrape_run)

    db_session.commit()