Newer
Older
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
from paramiko import RSAKey
key_class = RSAKey
prv = key_class.generate(bits=2048)
import six
prv_bio = six.BytesIO()
prv.write_private_key(prv_bio)
prv_bio_read = six.BytesIO(prv_bio.getvalue())
pub = key_class.from_private_key(prv_bio_read)
pub_bio = six.BytesIO()
pub_bio.write("%s %s relate-course-key" % (pub.get_name(), pub.get_base64()))
return render(request, "course/keypair.html", {
"public_key": prv_bio.getvalue().decode(),
"private_key": pub_bio.getvalue().decode(),
})
# }}}
# {{{ celery task monitoring
def monitor_task(request, task_id):
from celery.result import AsyncResult
async_res = AsyncResult(task_id)
progress_percent = None
progress_statement = None
if async_res.state == "PROGRESS":
meta = async_res.info
current = meta["current"]
total = meta["total"]
if total > 0:
progress_percent = 100 * (current / total)
progress_statement = (
_("%(current)d out of %(total)d items processed.")
% {"current": current, "total": total})
if async_res.state == "SUCCESS":
if (isinstance(async_res.result, dict)
and "message" in async_res.result):
progress_statement = async_res.result["message"]
traceback = None
if request.user.is_staff and async_res.state == "FAILURE":
traceback = async_res.traceback
return render(request, "course/task-monitor.html", {
"state": async_res.state,
"progress_percent": progress_percent,
"progress_statement": progress_statement,
"traceback": traceback,
})
# }}}