Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
adc2019-system
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
adc2019
adc2019-system
Commits
9bbcc8e9
Commit
9bbcc8e9
authored
Aug 19, 2019
by
Kento HASEGAWA
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support adccli (but not tested)
parent
84df0094
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
102 additions
and
0 deletions
+102
-0
host.py
roles/host.py
+43
-0
adcclilib.py
utils/adcclilib.py
+59
-0
No files found.
roles/host.py
View file @
9bbcc8e9
...
@@ -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
...
...
utils/adcclilib.py
0 → 100644
View file @
9bbcc8e9
#!/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
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment