def check_output(request):
    """Check the output of a running process."""
    received_json = json.loads(request.body)
    identifier = received_json['identifier']

    p = process_handling.ProcessReader(
        os.path.join(tempfile.gettempdir(), identifier))

    print received_json['already_read']
    lines = p.read_lines(received_json['already_read'])

    # Remove some noise from the gnatprove output
    lines = [l.strip() for l in lines if not l.startswith("Summary logged")]

    returncode = p.poll()
    if returncode is None:
        # The program is still running: transmit the current lines
        return CrossDomainResponse({
            'output_lines': lines,
            'status': 0,
            'completed': False,
            'message': "running"
        })

    else:
        return CrossDomainResponse({
            'output_lines': lines,
            'status': returncode,
            'completed': True,
            'message': "completed"
        })
def run_program(request):

    # Sanity check for the existence of gnatprove

    received_json = json.loads(request.body)
    e = get_example(received_json)
    if not e:
        return CrossDomainResponse({
            'identifier': '',
            'message': "example not found"
        })

    tempd, message = prep_example_directory(e, received_json)
    if message:
        return CrossDomainResponse({'identifier': '', 'message': message})

    main = get_main(received_json)

    if not main:
        return CrossDomainResponse({
            'identifier': '',
            'message': "main not specified"
        })

    # Check whether we have too many processes running
    if not resources_available():
        return CrossDomainResponse({
            'identifier':
            '',
            'message':
            "the machine is busy processing too many requests"
        })

    doctor_main_gpr(tempd, main)

    # Run the command(s) to check the program
    commands = [
        # Build the program
        ["gprbuild", "-q", "-P", "main"],
        # Launch the program via "safe_run", to sandbox it
        [
            "python",
            os.path.join(os.path.dirname(__file__), 'safe_run.py'),
            os.path.join(tempd, main[:-4])
        ],
    ]

    print commands

    try:
        p = process_handling.SeparateProcess(commands, tempd)
        stored_run = ProgramRun(working_dir=p.working_dir)
        stored_run.save()
        message = "running gnatprove"

    except subprocess.CalledProcessError, exception:
        message = exception.output
def check_program(request):

    # Sanity check for the existence of gnatprove

    if not check_gnatprove():
        return CrossDomainResponse({
            'identifier': '',
            'message': "gnatprove not found"
        })

    received_json = json.loads(request.body)
    e = get_example(received_json)
    if not e:
        return CrossDomainResponse({
            'identifier': '',
            'message': "example not found"
        })

    # Check whether we have too many processes running
    if not resources_available():
        return CrossDomainResponse({
            'identifier':
            '',
            'message':
            "the machine is busy processing too many requests"
        })

    tempd, message = prep_example_directory(e, received_json)
    if message:
        return CrossDomainResponse({'identifier': '', 'message': message})

    main = get_main(received_json)
    doctor_main_gpr(tempd, main, True)

    # Run the command(s) to check the program
    command = [
        "gnatprove", "-P", "main", "--checks-as-errors", "--level=0",
        "--no-axiom-guard"
    ]

    # Process extra_args
    if 'extra_args' in received_json:
        extra_args = received_json['extra_args']
        if extra_args:
            if extra_args not in ALLOWED_EXTRA_ARGS:
                return CrossDomainResponse({
                    'identifier': '',
                    'message': "extra_args not known"
                })
            command.append(ALLOWED_EXTRA_ARGS[extra_args])
    print " ".join(command)
    try:
        p = process_handling.SeparateProcess([command], tempd)
        message = "running gnatprove"

    except subprocess.CalledProcessError, exception:
        message = exception.output
Beispiel #4
0
def run_program(request):
    received_json = json.loads(request.body)
    e = get_example()
    if not e:
        return CrossDomainResponse(
            {'identifier': '', 'message': "example not found"})

    tempd, message = prep_example_directory(e, received_json)
    if message:
        return CrossDomainResponse({'identifier': '', 'message': message})

    print received_json
    mode = received_json['mode']

    # Check whether we have too many processes running
    if not resources_available():
        return CrossDomainResponse(
            {'identifier': '',
             'message': "the machine is busy processing too many requests"})

    # Push the code to the container

    try:
        subprocess.check_call(["lxc", "file", "push", "--recursive", tempd,
                               "safecontainer/workspace/sessions/"])
        subprocess.check_call(["lxc", "exec", "safecontainer", "--",
                               "chown", "-R", "runner",
                               "/workspace/sessions/{}".format
                               (os.path.basename(tempd))])
        subprocess.check_call(["lxc", "exec", "safecontainer", "--",
                               "chmod", "-R", "a+rx",
                               "/workspace/sessions/{}".format
                               (os.path.basename(tempd))])
    except subprocess.CalledProcessError, exception:
        result = {'message': "error transferring the program"}
        return CrossDomainResponse(result)
                    'identifier': '',
                    'message': "extra_args not known"
                })
            command.append(ALLOWED_EXTRA_ARGS[extra_args])
    print " ".join(command)
    try:
        p = process_handling.SeparateProcess([command], tempd)
        message = "running gnatprove"

    except subprocess.CalledProcessError, exception:
        message = exception.output

    # Send the result
    result = {'identifier': os.path.basename(tempd), 'message': message}

    return CrossDomainResponse(result)


@api_view(['POST'])
def run_program(request):

    # Sanity check for the existence of gnatprove

    received_json = json.loads(request.body)
    e = get_example(received_json)
    if not e:
        return CrossDomainResponse({
            'identifier': '',
            'message': "example not found"
        })