如题。
山东省第三轮省队集训题目现只对潍坊一中内部用户开放。
如题。
山东省第三轮省队集训题目现只对潍坊一中内部用户开放。
本机
import os
WYOJ_HOST = "192.168.137.4"
print ("上传 PDF 题面。")
print ("原有的题面会完全丢失!!!")
print ("不能使用网页端更改题面!!!")
pidst = int (input ("题目编号起始值(含):"))
pided = int (input ("题目编号终止值(含):"))
lpath = input ("PDF 题面路径:")
if not os.path.exists (lpath):
raise Exception ("没有这个文件,唐氏儿")
def execute (s):
print ("运行本机命令:%s" % s)
if os.system (s):
raise Exception ("本机命令运行错误")
for pid in range (pidst, pided + 1):
rpath = "pdfstat%d.pdf" % pid
execute ("scp %s ryp@%s:/home/ryp/%s" % (lpath, WYOJ_HOST, rpath))
execute ("ssh ryp@%s ./pdf-update %d %s" % (WYOJ_HOST, pid, rpath))
远端
#!/bin/python3
import os
import sys
if len (sys.argv) != 3:
raise Exception ("参数数量错误")
pid = int (sys.argv[1])
lpath = sys.argv[2]
if not os.path.exists (lpath):
raise Exception ("文件未找到")
def execute (s):
print ("执行远端命令:%s" % s, file=sys.stderr)
if os.system (s):
raise Exception ("远端命令运行失败", file=sys.stderr)
rpath = "/opt/uoj/web/upload/statement%s.pdf" % pid
execute ("sudo docker cp %s uoj-web:%s" % (lpath, rpath))
execute ("sudo docker exec uoj-db mysql -proot app_uoj233 -e \"update problems_contents set statement_md = "
"'<iframe src=\"/upload/statement%d.pdf\" width=\"100%%\" height=\"1000\"></iframe>' where id = %d;\"" % (pid, pid))
execute ("sudo docker exec uoj-db mysql -proot app_uoj233 -e \"update problems_contents set statement = statement_md where id = %d;\"" % pid)
execute ("rm %s" % lpath)
自动将 subXX_XX.in/out 转化为 subtaskX/X.in 格式脚本
带有 WyOJ 前缀的,是只有在机房的路由机器(也就是那台 Windows 10)上才可以运行的。
import re
import os
# 输入、输出文件后缀。可更改
insuf, outsuf = "in", "out"
print ("problem.conf 自助配置")
path = input ("输入数据目录:")
os.chdir (path)
spjp, stdp, valp, subtaskp = False, False, False, False
def continuep ():
s = input ("要继续吗?(y/N)")
if s != "y":
exit (1)
for s in os.listdir ("."):
if s == 'problem.conf':
print ("警告:problem.conf 已存在,将会被覆盖")
continuep ()
if s == 'chk.cpp':
spjp = True
if s == 'std.cpp':
stdp = True
if s == 'val.cpp':
valp = True
if os.path.isdir (s) and re.match ("subtask[0-9]*", s):
subtaskp = True
output = open ("problem.conf", "w")
chker = None
if spjp:
print ("识别到 chk.cpp,已启用 Special Judge")
else:
chker = input ("未识别到 chk.cpp,请输入自定义校验器类型:")
print ("use_builtin_judger on", file=output)
if chker:
print ("use_builtin_checker %s" % chker, file=output)
if subtaskp:
print ("识别到 subtaskX 目录,自动识别 Subtask 中")
else:
print ("未识别到 subtaskX 目录,自动尝试普通配置(如果你认为 Subtask 存在,但文件名格式为 subXX_XX.in/out,尝试使用 subxx2datax.py 脚本)")
tlim = int (input ("时间限制(秒):"))
mlim = int (input ("空间限制(MB):"))
print ("time_limit %d\nmemory_limit %d" % (tlim, mlim), file=output)
patt = re.compile ("([A-Z]*[a-z]*[A-Z]*)([0-9]+).(%s|%s)" % (insuf, outsuf))
def processdir (path):
tcases = 0
pre = None
for s in os.listdir (path):
if os.path.isdir (s):
continue
q = re.findall (patt, s)
if len (q) != 1:
continue
print ("识别到数据文件 %s" % s)
q = q[0]
if not pre:
pre = q[0]
elif pre != q[0]:
raise Exception ("数据文件前缀不相同!同时找到了 %s 与 %s,自动配置失败。" % (pre, q[0]))
if int (q[1]) > tcases:
tcases = int (q[1])
if tcases == 0 or not pre:
raise Exception ("无法自动识别数据文件")
return (tcases, pre)
if not subtaskp:
tcases, pre = processdir (".")
print ("找到 %d 个测试点" % tcases)
print ("n_tests %d" % tcases, file=output)
print ("n_ex_tests 0\nn_sample_tests 0", file=output)
print ("input_pre %s\ninput_suf %s" % (pre, insuf), file=output)
print ("output_pre %s\noutput_suf %s" % (pre, outsuf), file=output)
print ("自动配置结束!")
else:
tcases, subs = 0, 0
pre = None
subtptt = re.compile ("subtask([0-9]*)")
end = { }
for s in os.listdir ("."):
if os.path.isdir (s):
q = re.findall (subtptt, s)
if len (q) != 1:
print ("忽略非 Subtask 目录 %s" % s)
continue
print ("找到 subtask 目录 %s" % s)
subs += 1
nc, spre = processdir (s)
if not pre:
pre = spre
elif pre != spre:
raise Exception ("Subtask 间文件前缀不同!同时找到了 %s 与 %s,自动配置失败。" % (pre, spre))
end[int (q[0])] = nc
if nc > tcases:
tcases = nc
print ("n_tests %d\nn_ex_tests 0\nn_sample_tests 0" % tcases, file=output)
print ("input_pre %s\ninput_suf %s" % (pre, insuf), file=output)
print ("output_pre %s\noutput_suf %s" % (pre, outsuf), file=output)
print ("找到 %d 个 Subtask,共 %d 个测试点" % (subs, tcases))
scs = 100.0 / subs
print ("正在按照每个 Subtask 等分配置(%.2f 分)" % scs)
print ("n_subtasks %d" % subs, file=output)
for i in range (1, subs + 1):
print ("subtask_end_%d %d" % (i, end[i]), file=output)
print ("subtask_score_%d %.2f" % (i, scs), file=output)
output.close ()
本机:
import os
import random
rhost = "ryp@192.168.137.4"
def upload (pid, path):
if not os.path.exists (path):
raise Exception ("文件不存在。")
rpath = "upload%d-%d.zip" % (pid, random.randint (1, 32767))
print ("上传数据中")
if os.system ("scp %s %s:%s" % (path, rhost, rpath)):
raise Exception ("上传数据失败")
print ("数据上传完毕。正在处理")
if os.system ("ssh %s ./upload %d %s" % (rhost, pid, rpath)):
raise Exception ("解压失败")
print ("完毕!现在请在网页端题目管理界面单击 校验配置并同步数据。")
os.system ("pause")
print ("选项(1:上传单个数据;2:上传一组数据(要求题目编号连续、ZIP 存档名称格式为 题目编号.zip)):")
opt = int (input ())
if opt == 1:
pid = int (input ("题目 ID:"))
path = input ("数据存档(必须是包含 problem.conf 的 ZIP 存档;子文件夹中的文件将会被移动到根,其中的同名文件会随机覆盖,):")
upload (pid, path)
elif opt == 2:
fails = []
st = int (input ("编号区间起始值(含)"))
ed = int (input ("编号区间结束值(含)"))
for i in range (st, ed + 1):
if not os.path.exists ("%d.zip" % i):
raise Exception ("未找到文件 %d.zip" % i)
for i in range (st, ed + 1):
print ("上传数据 %d 中" % i)
try:
upload (i, "%d.zip" % i)
except Exception:
print ("上传 %d 数据失败。尝试下一道题目……" % i)
fails.append (i)
else:
print ("上传 %d 数据成功" % i)
print ("上传结束。共有 %d 道题失败(%.3f%%)" % (len (fails), 100.0 * len (fails) / (ed - st + 1)))
print ("失败题目:")
if len (fails) == 0:
print ("(无)")
else:
for i in fails:
print (i, end="; ")
else:
raise Exception ("无效选项")
远端:
#!/bin/python3
import os
import sys
import random
def exec (s):
print ("执行远端命令:%s" % s, file=sys.stderr)
if os.system (s):
raise Exception ("远端命令执行失败!")
def info (s):
print (s, file=sys.stderr)
if len (sys.argv) != 3:
raise Exception ("参数数量错误")
pid = int (sys.argv[1])
lpath = sys.argv[2]
rpath = "data%d-%d.zip" % (pid, random.randint (1, 32767))
info ("正在复制到容器")
exec ("sudo docker cp %s uoj-web:/tmp/%s" % (lpath, rpath))
info ("正在清空原数据")
exec ("sudo docker exec uoj-web rm -rf /var/uoj_data/upload/%d" % pid)
exec ("sudo docker exec uoj-web rm -rf /var/uoj_data/%d" % pid)
info ("正在解压数据")
exec ("sudo docker exec uoj-web unzip -q /tmp/%s -d /var/uoj_data/upload/%d" % (rpath, pid))
exec ("sudo docker exec uoj-web unzip -q /tmp/%s -d /var/uoj_data/%d" % (rpath, pid))
exec ("sudo docker exec uoj-web rm /tmp/%s" % rpath)
info ("正在展开数据(第一次)")
exec ("sudo docker exec uoj-web bash -c \'"
"cd /var/uoj_data/upload/%d; "
"for f in `find -type f`; do mv $f `basename $f`; done;"
"for f in `find -type f -maxdepth 1 ! -name '.'`; do rm -rfv $f; done;\'" % pid)
info ("正在展开数据(第二次)")
exec ("sudo docker exec uoj-web bash -c \'"
"cd /var/uoj_data/%d; "
"for f in `find -type f`; do mv $f `basename $f`; done;"
"for f in `find -type f -maxdepth 1 ! -name '.'`; do rm -rfv $f; done;\'" % pid)
print ("删除临时数据包")
exec ("rm %s" % lpath)
print ("完毕!")