2016-10-03 08:13:46 +00:00
|
|
|
import _judger
|
2016-10-27 10:38:04 +00:00
|
|
|
import hashlib
|
2018-03-18 00:19:44 +00:00
|
|
|
import logging
|
2017-05-30 05:14:49 +00:00
|
|
|
import os
|
2018-03-18 00:19:44 +00:00
|
|
|
import socket
|
2016-10-22 13:22:20 +00:00
|
|
|
|
2018-03-18 00:19:44 +00:00
|
|
|
import psutil
|
2016-10-27 10:38:04 +00:00
|
|
|
|
2018-03-18 00:19:44 +00:00
|
|
|
from config import SERVER_LOG_PATH
|
|
|
|
from exception import JudgeClientError
|
2016-10-27 10:38:04 +00:00
|
|
|
|
|
|
|
logger = logging.getLogger(__name__)
|
2018-03-18 00:19:44 +00:00
|
|
|
handler = logging.FileHandler(SERVER_LOG_PATH)
|
2016-10-27 10:38:04 +00:00
|
|
|
formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
|
|
|
|
handler.setFormatter(formatter)
|
|
|
|
logger.addHandler(handler)
|
|
|
|
logger.setLevel(logging.WARNING)
|
2016-10-22 13:22:20 +00:00
|
|
|
|
|
|
|
|
2016-10-03 08:13:46 +00:00
|
|
|
def server_info():
|
|
|
|
ver = _judger.VERSION
|
|
|
|
return {"hostname": socket.gethostname(),
|
|
|
|
"cpu": psutil.cpu_percent(),
|
|
|
|
"cpu_core": psutil.cpu_count(),
|
|
|
|
"memory": psutil.virtual_memory().percent,
|
2016-11-17 12:08:27 +00:00
|
|
|
"judger_version": ".".join([str((ver >> 16) & 0xff), str((ver >> 8) & 0xff), str(ver & 0xff)])}
|
2016-10-03 08:13:46 +00:00
|
|
|
|
|
|
|
|
|
|
|
def get_token():
|
2017-10-31 11:51:42 +00:00
|
|
|
token = os.environ.get("TOKEN")
|
2017-05-30 05:14:49 +00:00
|
|
|
if token:
|
|
|
|
return token
|
|
|
|
else:
|
2018-03-18 00:19:44 +00:00
|
|
|
raise JudgeClientError("env 'TOKEN' not found")
|
2016-10-04 05:24:50 +00:00
|
|
|
|
2016-10-27 10:38:04 +00:00
|
|
|
|
2019-03-13 07:48:14 +00:00
|
|
|
class ProblemIOMode:
|
|
|
|
standard = "Standard IO"
|
|
|
|
file = "File IO"
|
|
|
|
|
|
|
|
|
2018-03-18 00:19:44 +00:00
|
|
|
token = hashlib.sha256(get_token().encode("utf-8")).hexdigest()
|