Commit 9bbcc8e9 authored by Kento HASEGAWA's avatar Kento HASEGAWA

Support adccli (but not tested)

parent 84df0094
...@@ -6,6 +6,7 @@ import time ...@@ -6,6 +6,7 @@ import time
import requests import requests
from utils import Problem from utils import Problem
import utils.adcclilib as adccli
class Host(object): class Host(object):
...@@ -149,6 +150,48 @@ class Host(object): ...@@ -149,6 +150,48 @@ class Host(object):
problem_key = params['problem'] problem_key = params['problem']
solution_id = params['solution'] solution_id = params['solution']
return self.get_solution_for_viewer(problem_key, solution_id) return self.get_solution_for_viewer(problem_key, solution_id)
elif cmd == 'adccli/login':
with open('path-to-adccli-login', 'r') as fp:
d = json.load(fp)
r = adccli.login(d['url'], d['username'], d['password'])
res = {'message': r}
return json.dumps(res)
elif cmd == 'adccli/logout':
r = adccli.logout()
res = {'message': r}
return json.dumps(res)
elif cmd == 'adccli/whoami':
with open('path-to-adccli-login', 'r') as fp:
d = json.load(fp)
r = adccli.whoami()
res = {'message': r, 'status': r == d['username']}
return json.dumps(res)
elif cmd == 'adccli/download-problem':
out_abspath = os.path.abspath(self.config['problem_path'])
r = adccli.get_q_all(out_abspath)
self._load_problems(self.config['problem_path'])
res = {'message': r}
return json.dumps(res)
elif cmd == 'adccli/upload-solution':
qname = params['problem']
if not "best_json" in questions[qname]:
res = {'message': "Required to 'save' before submission"}
else:
out_path = "{}/{}".format(self.config['solution_path'], "submit")
# qnumber = qname.replace("NL_Q", "").replace(".txt", "")
# ans_file_path = "{}/T01_A{}.txt".format(out_path, qnumber)
# ans_file_abspath = os.path.abspath(ans_file_path)
# r = adccli.put_a(qnumber, ans_file_abspath)
# mes = r + "\n"
# json_name = questions[qname]['best_json']
# data = questions[qname]['answers'][json_name]
# r = adccli.put_a_info(qnumber, data['cputime'], "0", "Test")
# mes += r
mes = ''
res = {'message': mes}
return json.dumps(res)
else: else:
return None return None
......
#!/usr/bin/env python3
import subprocess
PYTHON2 = "/usr/bin/python"
ADCCLI = "/home/pi/adc2018/conmgr/client/adccli"
def _exec_adccli(cmd):
exec_cmd = "{} {} {}".format(PYTHON2, ADCCLI, cmd).strip()
print("ADCCLI: {}".format(exec_cmd))
p = subprocess.run(exec_cmd, stdout=subprocess.PIPE, shell=True)
res = p.stdout.decode().strip()
print(res)
return res
def login(url, username, password):
cmd = "--URL='{}' --username='{}' --password='{}' login".format(url, username, password)
return _exec_adccli(cmd)
def logout():
cmd = "logout"
return _exec_adccli(cmd)
def whoami():
cmd = "whoami"
return _exec_adccli(cmd)
def put_message(message):
cmd = "put-user-alive '{}'"
return _exec_adccli(cmd)
def post_user_q(qnum, filepath):
cmd = "post-user-q {} {}".format(qnum, filepath)
return _exec_adccli(cmd)
def get_q_all(outpath):
cmd = "get-q"
question_list = _exec_adccli(cmd).split("\n")
print("--- ADCCLI questions ---")
print(question_list)
for v in question_list:
if v.startswith("Q"):
qnumber = int(v.replace("Q", ""))
out_file_path = "{}/NL_Q{:02d}.txt".format(outpath, qnumber)
cmd = "--output {} get-q {}".format(out_file_path, qnumber)
r = _exec_adccli(cmd)
return question_list
def put_a(qnum, filepath):
cmd = "put-a {} {}".format(qnum, filepath)
return _exec_adccli(cmd)
def put_a_info(qnum, cpu, mem, misc):
cmd = "put-a-info {} {} {} '{}'".format(qnum, cpu, mem, misc)
return _exec_adccli(cmd)
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment