优化批量收录新题的流程, 终端会显示存在错误的地方
This commit is contained in:
parent
5459ec264e
commit
eaa944e7eb
|
|
@ -438,6 +438,7 @@ def GenerateProblemListFromString2024(data): #从来自.tex文件的字符串生
|
|||
data = re.findall(r"\\begin\{document\}([\s\S]*?)\\end\{document\}",data)[0]
|
||||
except:
|
||||
pass
|
||||
data = data + "\n\\end{enumerate}"
|
||||
data = re.sub(r"\n{2,}","\n",data)
|
||||
data = re.sub(r"\\definecolor[^\n]*\n","\n",data)
|
||||
data = re.sub(r"\\begin\{tcolorbox\}[\s\S]*?\\end\{tcolorbox\}","\n",data)
|
||||
|
|
@ -545,6 +546,7 @@ def AddProblemstoDict2024nocommit(startingid,raworigin,problems,editor,indexed,c
|
|||
currentsuffix = problems[0][1]
|
||||
problemindex = 0
|
||||
for p_and_suffix_and_meta in problems:
|
||||
try:
|
||||
p, suffix, meta = p_and_suffix_and_meta
|
||||
pid = str(id).zfill(6)
|
||||
if suffix == currentsuffix:
|
||||
|
|
@ -602,6 +604,11 @@ def AddProblemstoDict2024nocommit(startingid,raworigin,problems,editor,indexed,c
|
|||
else:
|
||||
idlist.append(meta["rep"])
|
||||
print(f"该题 {idlist[-1]} {p} 已在题库中, 不必收录.")
|
||||
except Exception as e:
|
||||
print(f"错误类型: {type(e).__name__}")
|
||||
print(f"错误的题目: {p_and_suffix_and_meta}")
|
||||
idlist = []
|
||||
break
|
||||
return idlist
|
||||
|
||||
def CreateIDLinks(old_id_list,new_id_list): #建立已有id和新id之间的联系, thedict为可选, 选中的话即为当前字典, 会从new_id_list中排除当前字典中有的项
|
||||
|
|
|
|||
|
|
@ -15,10 +15,12 @@ class MyWindow_bdsl(QWidget,Ui_Form):
|
|||
|
||||
def bind(self):
|
||||
self.suffix_checked = True
|
||||
self.pushButton_commit.setDisabled(True)
|
||||
self.checkBox_suffix.toggled.connect(self.togglesuffix)
|
||||
self.pushButton_step1.clicked.connect(self.execstep1)
|
||||
self.pushButton_step2.clicked.connect(self.execstep2)
|
||||
self.pushButton_commit.clicked.connect(self.commitchange)
|
||||
self.plainTextEdit_compared.textChanged.connect(self.commitdisable)
|
||||
def togglesuffix(self):
|
||||
self.suffix_checked = self.checkBox_suffix.isChecked()
|
||||
if self.suffix_checked:
|
||||
|
|
@ -81,6 +83,7 @@ class MyWindow_bdsl(QWidget,Ui_Form):
|
|||
self.plainTextEdit_compared.setPlainText(texdata)
|
||||
|
||||
def execstep2(self):
|
||||
idlist = []
|
||||
starting_id = self.lineEdit_startingid.text().strip().zfill(6)
|
||||
raworigin = self.lineEdit_origin.text().strip()
|
||||
data = self.plainTextEdit_compared.toPlainText()
|
||||
|
|
@ -95,9 +98,18 @@ class MyWindow_bdsl(QWidget,Ui_Form):
|
|||
nextspareid = NextSpareID(starting_id,self.database_name)
|
||||
self.db = connect(hostname = db_host, port= db_port, username= db_user, pwd = db_pwd, db= self.database_name)
|
||||
self.cursor = self.db.cursor()
|
||||
rolled_back = False
|
||||
idlist = AddProblemstoDict2024nocommit(nextspareid,raworigin,problems,editor,Indexed,self.cursor)
|
||||
if idlist == []:
|
||||
print("有错误, 改变已回滚.")
|
||||
self.db.rollback()
|
||||
rolled_back = True
|
||||
if not rolled_back:
|
||||
AppendTextFile(f"{GetDate()}-{GetTime()}\n{generate_exp(idlist)}",idlistpath)
|
||||
os.system(f"code {idlistpath}")
|
||||
self.pushButton_commit.setEnabled(True)
|
||||
def commitdisable(self):
|
||||
self.pushButton_commit.setDisabled(True)
|
||||
|
||||
def commitchange(self):
|
||||
self.db.commit()
|
||||
|
|
|
|||
Reference in New Issue