本机
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)