def runc(): contest_id = 'c_dOHYbn' #Get c_id from session #contest_id=session['c_id'] question = get_question(contest_id) if request.method == 'POST': code = request.form['code'] print(code) resinput = format(request.form['resinput']) global Index Index += 1 ID = Index instr = "./running/input" + str(ID) + ".txt" f = open(instr, "w") f.write(resinput) f.close() run = runcode.RunCCode(question, code, Index) rescompil, resrun = run.run_c_code() if not resrun: resrun = 'No result!' else: code = default_c_code resrun = 'No result!' rescompil = '' return render_template("main.html", question=question, code=code, target="runc", resrun=resrun, rescomp=rescompil, rows=default_rows, cols=default_cols)
def runc(): if request.method == 'POST': code = request.form['code'] resinput = format(request.form['resinput']) global Index Index += 1 ID = Index instr = "./running/input" + str(ID) + ".txt" f = open(instr, "w") f.write(resinput) f.close() run = runcode.RunCCode(code, Index) rescompil, resrun, test_case_output = run.run_c_code() print(test_case_output) if not resrun: resrun = 'No result!' else: code = default_c_code resrun = 'No result!' rescompil = '' test_case_output = "" return render_template("main.html", code=code, target="runc", resrun=resrun, test_case_output=test_case_output, rescomp=rescompil, rows=default_rows, cols=default_cols)
def run3(): if request.method == 'POST': code = request.form['code'] ip = request.form['ip'] fp = open("./running/ip.txt", 'w') fp.write(ip) fp.close() run = runcode.RunCCode(code) rescompil, resrun = run.run_c_code() if not resrun: resrun = 'No result!' else: code = default_c_code3 resrun = 'No result!' rescompil = '' next = "run4" return render_template("main.html", statement=statement3, code=code, target="run3", next=next, resrun=resrun, rescomp=rescompil, rows=default_rows, cols=default_cols)
def submission(): output = runcode.RunCCode(question="") test_case_output = output.all_submissions() if (test_case_output == None): return render_template("Table/table.html", output={ "status": "No submissions to show", "score": "", "test_case_status": "", "submit_time": "" }) return render_template("Table/table.html", output=test_case_output)
def runc(): if request.method == 'POST': code = request.form['code'] run = runcode.RunCCode(code) rescompil, resrun = run.run_c_code() if not resrun: resrun = 'No result!' else: code = default_c_code resrun = 'No result!' rescompil = '' return render_template("main.html", code=code, target="runc", resrun=resrun, rescomp=rescompil, rows=default_rows, cols=default_cols)
def route_submission(): output = runcode.RunCCode(question="") test_case_output = output.all_submissions() print(test_case_output) if (test_case_output == None): global qid return render_template("Table/table.html", output=[{ "status": "No submissions to show", "score": "", "test_case_status": "", "submit_time": "" }], qid=qid) #global qid return render_template("Table/table.html", output=test_case_output, qid=qid)
def submission(): output = runcode.RunCCode() test_case_output = output.all_submissions() l = test_case_output.split('\n') print(l) return render_template("Table/table.html", output=l)
def route_runc(q_id): #The q_id here is the question id which the student clicked on, I have verfied it and it is the right id. #You can also access q_id with session['q_id'] #the control here is passed from show_question print("------------------------------------") print("Session in route_runc ", session) print("------------------------------------") print(q_id) global qid if (qid == 0 or q_id != "1"): qid = q_id question = db.get_question_details(qid) if request.method == 'POST': custom_input = False resinput = format(request.form['resinput']) if request.form['submit'] == "Run Code": print("custom_input is TRUE") custom_input = True if (len(resinput) < 1): resinput = "No input!!" code = request.form['code'] print(code) global Index Index += 1 ID = Index instr = "./running/input" + str(ID) + ".txt" f = open(instr, "w") f.write(resinput) f.close() os.chmod(os.getcwd(), 0o777) for root, dirs, f in os.walk(os.getcwd()): for d in dirs: try: os.chmod(os.path.join(root, d), 0o777) except PermissionError: continue for file in f: try: os.chmod(os.path.join(root, file), 0o777) except: continue run = runcode.RunCCode(question, code, custom_input, Index) rescompil, resrun, display_outputi, status, test_case_output = run.run_c_code( ) print(test_case_output) if not resrun: resrun = 'No result! no run yet.' else: code = default_c_code resrun = 'No result! no run yet.' rescompil = '' display_outputi = {} status = "" test_case_output = "None" return render_template("main.html", c_id=session['c_id'], question=question, code=code, target="runc", resrun=resrun, rescomp=rescompil, test_case_output=test_case_output, display_output=display_outputi, status=status, rows=default_rows, cols=default_cols)