예제 #1
0
def compile_with_cmake(object_id):
    os.chdir(sandbox_path)
    code_doc = db.get_full_code(object_id)
    if not os.path.exists(object_id):
        os.mkdir(object_id)
    code_dir_path = os.path.abspath(object_id)
    code_file_name = os.path.join(code_dir_path, 'test.cxx')
    cmake_file_name = os.path.join(code_dir_path, 'CMakeLists.txt')
    with open(code_file_name, 'w') as outfile:
        outfile.write(code_doc['code'])
    with open(cmake_file_name, 'w') as outfile:
        outfile.write(code_doc['cmake'])
    for cur_input in code_doc['inputs']:
        cur_file_name = os.path.join(code_dir_path, cur_input['name'])
        with open(cur_file_name, 'w') as outfile:
            outfile.write(cur_input['contents'])

    os.chdir(code_dir_path)
    cmake_runner = subprocess.Popen(['/usr/local/bin/cmake', code_dir_path],
        stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    make_runner = subprocess.Popen(['/usr/bin/make'],
        stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    cmake_output = cmake_runner.communicate()[0]
    make_output = make_runner.communicate()[0]
    return "%s\n%s" % (cmake_output, make_output)
예제 #2
0
def output_image(cur_id=None):
    if cur_id:
        full_code = db.get_full_code(cur_id)
        img_doc = full_code['outputs'][0]
        resp = make_response(img_doc['content'])
        resp.headers['Content-Type'] = 'image/png'
        return resp
    else:
        abort(404)
예제 #3
0
def output_image(cur_id=None):
    if cur_id:
        full_code = db.get_full_code(cur_id)
        img_doc = full_code['outputs'][0]
        resp = make_response(img_doc['content'])
        resp.headers['Content-Type'] = 'image/png'
        return resp
    else:
        abort(404)
예제 #4
0
def run_from_cmake(object_id):
    code_doc = db.get_full_code(object_id)
    os.chdir(sandbox_path)
    code_dir_path = os.path.abspath(object_id)
    os.chdir(code_dir_path)
    params = ['./test']
    if 'run_parameters' in code_doc:
        params = code_doc['run_parameters'].split()
        print params
    test_runner = subprocess.Popen(params,
        stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    run_output = test_runner.communicate()[0]
    output_image_path = os.path.join(code_dir_path, 'output.png')  # Magic val
    if os.path.exists(output_image_path):
        db.set_output(object_id, output_image_path)
    return run_output
예제 #5
0
    test_runner = subprocess.Popen(params,
        stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
    run_output = test_runner.communicate()[0]
    output_image_path = os.path.join(code_dir_path, 'output.png')  # Magic val
    if os.path.exists(output_image_path):
        db.set_output(object_id, output_image_path)
    return run_output

while True:
    message = socket.recv()
    request = json.loads(message)

    request_type = request['type']
    code_id = request['id']

    code_doc = db.get_full_code(code_id)

    if request_type == 'compile':

        if 'cmake' in code_doc:
            compile_output = compile_with_cmake(code_id)
        else:
            code = code_doc['code']
            print code  # DEBUG

            code_file_name = '%s.cpp' % code_id
            code_file = file(code_file_name, 'w')
            code_file.write(code)
            code_file.close()

            compile_runner = subprocess.Popen(['/usr/bin/gcc', code_file_name,