diff --git a/comm/server/adcclilib.py b/comm/server/adcclilib.py new file mode 100644 index 0000000000000000000000000000000000000000..fb03db34b7bf8148f0a26f4a642c203c20353d31 --- /dev/null +++ b/comm/server/adcclilib.py @@ -0,0 +1,59 @@ +#!/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) + diff --git a/comm/server/main.py b/comm/server/main.py index 4511d98918889a253d7493895878e66dd51b1cb4..68157a4bdcef71640336aba841d9c5378f451665 100644 --- a/comm/server/main.py +++ b/comm/server/main.py @@ -22,6 +22,8 @@ from queue import Queue sys.path.append(os.path.dirname(os.path.abspath(__file__)) + '/../../solver') import BoardStr +import adcclilib + app = Flask(__name__) app_args = {} questions = None @@ -440,6 +442,76 @@ def get_clients(): return json.dumps(res) +@app.route("/adccli-login") +def adccli_login(): + + global app_args + + with open(app_args['adccli'], 'r') as fp: + d = json.load(fp) + + r = adcclilib.login(d['url'], d['username'], d['password']) + res = {'message': r} + + return json.dumps(res) + +@app.route("/adccli-logout") +def adccli_logout(): + r = adcclilib.logout() + res = {'message': r} + return json.dumps(res) + +@app.route("/adccli-whoami") +def adccli_whoami(): + global app_args + + with open(app_args['adccli'], 'r') as fp: + d = json.load(fp) + + r = adcclilib.whoami() + + res = {'message': r, 'status': r == d['username']} + return json.dumps(res) + +@app.route("/adccli-get-all-q") +def adccli_get_all_q(): + global app_args + + out_abspath = os.path.abspath(app_args['question']) + r = adcclilib.get_q_all(out_abspath) + + load_questions() + + res = {'message': r} + return json.dumps(res) + +@app.route("/adccli-put-a", methods=["POST"]) +def adccli_put_a(): + global app_args + global questions + + qname = request.form["qname"] + + if not "best_json" in questions[qname]: + res = {'message': "Required to 'save' before submission"} + else: + out_path = "{}/{}".format(app_args['out'], "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 = adcclilib.put_a(qnumber, ans_file_abspath) + mes = r + "\n" + + json_name = questions[qname]['best_json'] + data = questions[qname]['answers'][json_name] + r = adcclilib.put_a_info(qnumber, data['cputime'], "0", "Test") + mes += r + + res = {'message': mes} + + return json.dumps(res) + @app.route("/board-viewer", methods=["GET"]) def show_board_viewer(): @@ -524,6 +596,7 @@ if __name__ == "__main__": parser = argparse.ArgumentParser(description="PYNQ control panel.") parser.add_argument("-c", "--client", action="store", type=str, default=None, required=True, help="Client list.") + parser.add_argument("-a", "--adccli", action="store", type=str, default="./adccli.json", help="Path to the ADCCLI configuration json file.") parser.add_argument("-q", "--question", action="store", type=str, default="./problems", help="Path to the question folder.") parser.add_argument("-o", "--out", action="store", type=str, default="./answers", help="Path to the output folder.") parser.add_argument("--debug", action="store_true", default=False, help="Debug mode.") diff --git a/comm/server/static/js/pynq-manager.js b/comm/server/static/js/pynq-manager.js index a48aa8de3f611bb030d2fd48bbf4d8eee68578e5..995d93ca348f7431e90838ad183f351b16e38e39 100644 --- a/comm/server/static/js/pynq-manager.js +++ b/comm/server/static/js/pynq-manager.js @@ -145,6 +145,40 @@ $(function(){ }).done(function(d){ $("#client-control-pane").html(""); $("#client-control-pane").html(d); + + var button_action_with_ajax = function($obj, url){ + $obj.prop("disabled", "disabled"); + $.ajax({ + type: "GET", + url: url, + dataType: "json", + }).done((data)=>{ + $obj.prop("disabled", false); + alert(data['message']); + }); + }; + + $("#adccli-login-button").click(function(){ + button_action_with_ajax($(this), "/adccli-login"); + }); + $("#adccli-logout-button").click(function(){ + button_action_with_ajax($(this), "/adccli-logout"); + }); + $("#adccli-get-all-q").click(function(){ + button_action_with_ajax($(this), "/adccli-get-all-q"); + }); + + $.ajax({ + type: "GET", + url: "/adccli-whoami", + dataType: "json", + }).done((data)=>{ + if(data['status']) + $("#adccli-status").text("ログイン中"); + else + $("#adccli-status").text("ログアウト"); + }); + pm.getStatus(); }); } @@ -177,6 +211,17 @@ $(function(){ alert(data['status']); }); }); + $("#client-control-pane").find(".submit-button").eq(0).click(function(){ + var qname = $(this).data("qname"); + $.ajax({ + type: "POST", + dataType: "json", + url: "/adccli-put-a", + data: {qname: qname} + }).done((data) => { + alert(data['message']); + }); + }); $(".answer-detail-row td").click(function(){ var json_name = $(this).parent("tr").data("json"); diff --git a/comm/server/templates/part_client_table.html b/comm/server/templates/part_client_table.html index 6211db7a81feb30a171696ac0c605c2153922d12..7386b49fabcd3f66e5f4b18208e50f950b937557 100644 --- a/comm/server/templates/part_client_table.html +++ b/comm/server/templates/part_client_table.html @@ -9,6 +9,13 @@ Viewer Mode {% endif %}

+

自動運営システム

+ + + +
+ +

クライアント

diff --git a/comm/server/templates/part_question_status.html b/comm/server/templates/part_question_status.html index 225e00ec2829eb14717cbe0e2357dd759521938f..a6f634cd7df0708d1510b6629e52078ecfc9b7f8 100644 --- a/comm/server/templates/part_question_status.html +++ b/comm/server/templates/part_question_status.html @@ -3,8 +3,11 @@

【{{qname}}】

-
+ +

+

+