73 lines
2.6 KiB
Python
73 lines
2.6 KiB
Python
from PySide6.QtWidgets import QWidget, QApplication, QFileDialog
|
|
from Ui_修改metadata import Ui_Form
|
|
import os
|
|
from database_tools_2 import *
|
|
|
|
|
|
class MyWindow_tjzd(QWidget,Ui_Form):
|
|
def __init__(self,database_name):
|
|
super().__init__()
|
|
self.database_name = database_name
|
|
self.setupUi(self)
|
|
self.bind()
|
|
|
|
def setdbname(self,string):
|
|
self.database_name = string
|
|
# print(self.database_name)
|
|
|
|
|
|
def bind(self):
|
|
self.metadatafilepath = "文本文件/metadata.txt"
|
|
self.pushButton_exec.clicked.connect(self.exec)
|
|
self.pushButton_open.clicked.connect(self.openmeta)
|
|
self.pushButton_exec.setEnabled(False)
|
|
def openmeta(self):
|
|
os.system(f"code -w {self.metadatafilepath}")
|
|
self.pushButton_exec.setEnabled(True)
|
|
|
|
|
|
|
|
|
|
def exec(self):
|
|
mydb = connect(hostname = db_host, port = db_port, username=db_user, pwd=db_pwd, db = self.database_name)
|
|
|
|
|
|
changedids = ImportMetadata(mydb,self.metadatafilepath)
|
|
print(changedids)
|
|
|
|
if len(changedids) > 0:
|
|
mycursor = mydb.cursor()
|
|
configjson = BuildFullScheme
|
|
latexbody = "\\begin{enumerate}\n\n"
|
|
for id in sorted(list(set(changedids))):
|
|
latexbody += generateLaTeXBodyContentfromMariaDB(mycursor,id,configjson) + "\n\n"
|
|
latexbody += "\\end{enumerate}"
|
|
latex_raw = ReadTextFile("模板文件/讲义模板.txt")
|
|
if configjson["教师版"] == True:
|
|
latex_raw = latex_raw.replace(r"学号\blank{50} \ 姓名\blank{80}","上海市控江中学")
|
|
|
|
if sys.platform != "win32": #非win系统用默认字体
|
|
latex_raw = re.sub(r"fontset[\s]*=[\s]*none","fontset = fandol",latex_raw)
|
|
latex_raw = re.sub(r"\\setCJKmainfont",r"% \\setCJKmainfont",latex_raw)
|
|
latex_data = StringSubstitute(r"<<[\s\S]*?待替换[\s\S]*?>>",latex_raw,("试编译",latexbody)) #替换标题和bodystring
|
|
outputdir = os.path.join(os.getcwd(),"临时文件")
|
|
outputfilepath = os.path.join(outputdir,"试编译.tex")
|
|
SaveTextFile(latex_data,outputfilepath)
|
|
if XeLaTeXCompile(outputdir,"试编译.tex",times=1):
|
|
print("修改后检验成功, 已导入数据库.")
|
|
mydb.commit()
|
|
else:
|
|
print("修改后检验失败, 已回滚.")
|
|
mydb.rollback()
|
|
else:
|
|
print("未作修改.")
|
|
self.pushButton_exec.setEnabled(False)
|
|
|
|
|
|
|
|
|
|
mydb.commit()
|
|
mydb.close()
|
|
|
|
|