Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
A
adc2018-system
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
adc2018
adc2018-system
Commits
e3011371
Commit
e3011371
authored
Aug 16, 2018
by
Kento HASEGAWA
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add adcclilib.py module to access the adc server (#14)
parent
f2bdebe1
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
126 additions
and
0 deletions
+126
-0
adcclilib.py
comm/server/adcclilib.py
+50
-0
main.py
comm/server/main.py
+34
-0
pynq-manager.js
comm/server/static/js/pynq-manager.js
+37
-0
part_client_table.html
comm/server/templates/part_client_table.html
+5
-0
No files found.
comm/server/adcclilib.py
0 → 100644
View file @
e3011371
#!/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
()
p
=
subprocess
.
run
(
exec_cmd
,
stdout
=
subprocess
.
PIPE
,
shell
=
True
)
res
=
p
.
stdout
.
decode
()
.
strip
()
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
"
)
for
v
in
question_list
:
out_file_path
=
"{}/NL_Q{:02d}.txt"
.
format
(
outpath
,
int
(
v
))
cmd
=
"--output {} get-q {}"
.
format
(
out_file_path
,
v
.
rstrip
())
_exec_adccli
(
cmd
)
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
)
comm/server/main.py
View file @
e3011371
...
@@ -22,6 +22,8 @@ from queue import Queue
...
@@ -22,6 +22,8 @@ from queue import Queue
sys
.
path
.
append
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
+
'/../../solver'
)
sys
.
path
.
append
(
os
.
path
.
dirname
(
os
.
path
.
abspath
(
__file__
))
+
'/../../solver'
)
import
BoardStr
import
BoardStr
import
adcclilib
app
=
Flask
(
__name__
)
app
=
Flask
(
__name__
)
app_args
=
{}
app_args
=
{}
questions
=
None
questions
=
None
...
@@ -440,6 +442,37 @@ def get_clients():
...
@@ -440,6 +442,37 @@ def get_clients():
return
json
.
dumps
(
res
)
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
(
"/board-viewer"
,
methods
=
[
"GET"
])
@
app
.
route
(
"/board-viewer"
,
methods
=
[
"GET"
])
def
show_board_viewer
():
def
show_board_viewer
():
...
@@ -524,6 +557,7 @@ if __name__ == "__main__":
...
@@ -524,6 +557,7 @@ if __name__ == "__main__":
parser
=
argparse
.
ArgumentParser
(
description
=
"PYNQ control panel."
)
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
(
"-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
(
"-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
(
"-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."
)
parser
.
add_argument
(
"--debug"
,
action
=
"store_true"
,
default
=
False
,
help
=
"Debug mode."
)
...
...
comm/server/static/js/pynq-manager.js
View file @
e3011371
...
@@ -145,6 +145,43 @@ $(function(){
...
@@ -145,6 +145,43 @@ $(function(){
}).
done
(
function
(
d
){
}).
done
(
function
(
d
){
$
(
"#client-control-pane"
).
html
(
""
);
$
(
"#client-control-pane"
).
html
(
""
);
$
(
"#client-control-pane"
).
html
(
d
);
$
(
"#client-control-pane"
).
html
(
d
);
$
(
"#adccli-login-button"
).
click
(
function
(){
var
$obj
=
$
(
this
);
$obj
.
prop
(
"disabled"
,
"disabled"
);
$
.
ajax
({
type
:
"GET"
,
url
:
"/adccli-login"
,
dataType
:
"json"
,
}).
done
((
data
)
=>
{
$obj
.
prop
(
"disabled"
,
false
);
alert
(
data
[
'message'
]);
});
});
$
(
"#adccli-logout-button"
).
click
(
function
(){
var
$obj
=
$
(
this
);
$obj
.
prop
(
"disabled"
,
"disabled"
);
$
.
ajax
({
type
:
"GET"
,
url
:
"/adccli-logout"
,
dataType
:
"json"
,
}).
done
((
data
)
=>
{
$obj
.
prop
(
"disabled"
,
false
);
alert
(
data
[
'message'
]);
});
});
$
.
ajax
({
type
:
"GET"
,
url
:
"/adccli-whoami"
,
dataType
:
"json"
,
}).
done
((
data
)
=>
{
if
(
data
[
'status'
])
$
(
"#adccli-status"
).
text
(
"ログイン中"
);
else
$
(
"#adccli-status"
).
text
(
"ログアウト"
);
});
pm
.
getStatus
();
pm
.
getStatus
();
});
});
}
}
...
...
comm/server/templates/part_client_table.html
View file @
e3011371
...
@@ -9,6 +9,11 @@ Viewer Mode
...
@@ -9,6 +9,11 @@ Viewer Mode
{% endif %}
{% endif %}
</p>
</p>
<h4>
自動運営システム
</h4>
<button
type=
"button"
class=
"btn btn-primary"
id=
"adccli-login-button"
>
Login
</button>
<button
type=
"button"
class=
"btn btn-light"
id=
"adccli-logout-button"
>
Logout
</button>
<span
id=
"adccli-status"
></span>
<h4>
クライアント
</h4>
<h4>
クライアント
</h4>
<table
class=
"table table-bordered"
id=
"clients-table"
>
<table
class=
"table table-bordered"
id=
"clients-table"
>
<tr>
<tr>
...
...
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